Skip to content

Commit

Permalink
Add a formatted citation postprocessing hook
Browse files Browse the repository at this point in the history
  • Loading branch information
andras-simonyi committed Jun 23, 2022
1 parent f7bcebf commit e65b44d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A CSL 1.0.2 Citation Processor for Emacs.
- [Rendering citations and bibliographies](#rendering-citations-and-bibliographies)
- [Rendering isolated references](#rendering-isolated-references)
- [Supported output formats](#supported-output-formats)
- [Hooks](#hooks)
- [License](#license)

## Introduction
Expand Down Expand Up @@ -273,6 +274,15 @@ export), `csl-test` (for the CSL test suite) and `raw` (internal rich-text
format, for debugging) are supported as output formats. New ones can easily be
added — see `citeproc-formatters.el` for examples.

### Hooks

citeproc-el provides the following hook variables:

#### citeproc-citation-postprocess-functions
A list of functions to postprocess rendered citations. Each function takes a
single argument, a rich-text, and returns a post-processed rich-text value. The
functions are applied in the order they appear in the list.

-------------------------------------------------------------------------------

## License
Expand Down
20 changes: 15 additions & 5 deletions citeproc-cite.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ GROUPED is used internally to indicate whether the cites were
"Alist mapping citation modes to corresponding cite-level
key-value pair representations.")

(defvar citeproc-citation-postprocess-functions nil
"A list of functions to postprocess rendered citations.
Each function takes a single argument, a rich-text, and returns a
post-processed rich-text value. The functions are applied in the
order they appear in the list.")

(defun citeproc-cite--varlist (cite)
"Return the varlist belonging to CITE."
(let* ((itd (alist-get 'itd cite))
Expand Down Expand Up @@ -193,8 +199,9 @@ For the optional INTERNAL-LINKS argument see
;; Prepend author to textual citations
(when (eq (citeproc-citation-mode c) 'textual)
(let* ((first-elt (car cites)) ;; First elt is either a cite or a cite group.
;; If the latter then we need to locate the first cite as the
;; 2nd element of the first cite group.
;; If the latter then we need to locate the
;; first cite as the 2nd element of the first
;; cite group.
(first-cite (if (eq 'group (car first-elt))
(cadr first-elt)
first-elt))
Expand All @@ -206,9 +213,12 @@ For the optional INTERNAL-LINKS argument see
(alist-get 'stopped-rendering (car rendered-author)))
(setq result `(nil ,rendered-author " " ,result)))))
;; Capitalize first
(if (citeproc-citation-capitalize-first c)
(citeproc-rt-change-case result #'citeproc-s-capitalize-first)
result)))))
(when (citeproc-citation-capitalize-first c)
(setq result (citeproc-rt-change-case result #'citeproc-s-capitalize-first)))
;; Run the citation postprocessing hook
(dolist (fn citeproc-citation-postprocess-functions)
(setq result (funcall fn result)))
result))))

(defun citeproc-cites--collapse-indexed (cites index-getter no-span-pred)
"Collapse continuously indexed cites in CITES.
Expand Down

0 comments on commit e65b44d

Please sign in to comment.