Skip to content

Commit

Permalink
Allow formatted bibliography to be placed in metadata fields.
Browse files Browse the repository at this point in the history
This modifies `processCitations` so that pandoc will look not just
in the document body but in metadata for a Div with id `refs` in
which to place the formatted bibliography.

Thus, one can include a metadata field, say `refs`, whose content
is an empty div with id `refs`, and the formatted bibliography
will be put into this metadata field.  It may then be interpolated
into a template using the variable `refs`.

Closes #7969.

Closes #526 by providing a way to interpolate references into
a template.
  • Loading branch information
jgm committed Mar 16, 2022
1 parent 878c4d6 commit 75ddff2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
13 changes: 13 additions & 0 deletions MANUAL.txt
Expand Up @@ -5975,6 +5975,19 @@ The bibliography will be inserted after this heading. Note that
the `unnumbered` class will be added to this heading, so that the
section will not be numbered.

If you want to put the bibliography into a variable in your
template, one way to do that is to put the div with id `refs`
into a metadata field, e.g.

---
refs: |
::: {#refs}
:::
...

You can then put the variable `$refs$` into your template where
you want the bibliography to be placed.

## Including uncited items in the bibliography

If you want to include items in the bibliography without actually
Expand Down
27 changes: 14 additions & 13 deletions src/Text/Pandoc/Citeproc.hs
Expand Up @@ -108,8 +108,8 @@ processCitations (Pandoc meta bs) = do
evalState (walkM insertResolvedCitations $ Pandoc meta' bs)
$ cits
return $ walk removeQuoteSpan
$ Pandoc meta''
$ insertRefs refkvs classes meta'' (B.toList bibs) bs'
$ insertRefs refkvs classes (B.toList bibs)
$ Pandoc meta'' bs'

removeQuoteSpan :: Inline -> Inline
removeQuoteSpan (Span ("",["csl-quoted"],[]) xs) = Span nullAttr xs
Expand Down Expand Up @@ -461,23 +461,24 @@ isYesValue _ = False
-- if document contains a Div with id="refs", insert
-- references as its contents. Otherwise, insert references
-- at the end of the document in a Div with id="refs"
insertRefs :: [(Text,Text)] -> [Text] -> Meta -> [Block] -> [Block] -> [Block]
insertRefs _ _ _ [] bs = bs
insertRefs refkvs refclasses meta refs bs =
insertRefs :: [(Text,Text)] -> [Text] -> [Block] -> Pandoc -> Pandoc
insertRefs _ _ [] d = d
insertRefs refkvs refclasses refs (Pandoc meta bs) =
if isRefRemove meta
then bs
else case runState (walkM go bs) False of
(bs', True) -> bs'
(_, False)
-> case refTitle meta of
then Pandoc meta bs
else case runState (walkM go (Pandoc meta bs)) False of
(d', True) -> d'
(Pandoc meta' bs', False)
-> Pandoc meta' $
case refTitle meta of
Nothing ->
case reverse bs of
case reverse bs' of
Header lev (id',classes,kvs) ys : xs ->
reverse xs ++
[Header lev (id',addUnNumbered classes,kvs) ys,
Div ("refs",refclasses,refkvs) refs]
_ -> bs ++ [refDiv]
Just ils -> bs ++
_ -> bs' ++ [refDiv]
Just ils -> bs' ++
[Header 1 ("bibliography", ["unnumbered"], []) ils,
refDiv]
where
Expand Down

0 comments on commit 75ddff2

Please sign in to comment.