Skip to content

Commit

Permalink
Add name post-processing hook
Browse files Browse the repository at this point in the history
  • Loading branch information
andras-simonyi committed Jul 2, 2022
1 parent 6c928c6 commit 54843c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ 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.

#### citeproc-name-postprocess-functions
A list of functions to postprocess rendered names.
Each function takes three arguments:

- the rich-text rendering of a name to be post-processed,
- the rendered name as an alist with CSL name-part
keys (`family`, `given` etc.), and
- the rendering context, as a `citeproc-context` structure.

The output of each function should be the post-processed rich-text, and
the functions are applied in the order they appear in the list.
-------------------------------------------------------------------------------

## License
Expand Down
16 changes: 10 additions & 6 deletions citeproc-name.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@

(defvar citeproc-name-postprocess-functions nil
"A list of functions to postprocess rendered names.
Each function takes two arguments: a name rendered in rich-text,
and the original name as an alist with CSL name-part
keys (`family', `given' etc.). The output shoul be a rich-text.
The functions are applied in the order they appear in the list.")
Each function takes three arguments:
- the rich-text rendering of a name to be post-processed,
- the rendered name as an alist with CSL name-part
keys (`family', `given' etc.), and
- the rendering context, as a `citeproc-context' structure.
The output of each function should be the post-processed
rich-text, and the functions are applied in the order they appear
in the list.")

;; OPTIMIZE: Name count could be sped up by only counting the names to be
;; rendered without actually rendering them
Expand Down Expand Up @@ -225,8 +229,8 @@ Nature."
attrs sort-o context)
context)))
(dolist (fn citeproc-name-postprocess-functions)
(setq result (funcall fn result name)))
result))
(setq result (funcall fn result name context)))
result))

(defun citeproc-name--parts-w-sep (c1 c2 sep context)
"Join name-parts in lists C1 C2 with spaces and then with SEP."
Expand Down

0 comments on commit 54843c9

Please sign in to comment.