Skip to content

Commit

Permalink
Citeproc: fix moving punctuation before citation notes.
Browse files Browse the repository at this point in the history
This previously worked with regular citations, but not author-in-text
citations. Now it works with both.
  • Loading branch information
jgm committed Jan 15, 2025
1 parent 806dcb0 commit 92cb00a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Text/Pandoc/Citeproc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,21 @@ getBibliographyFormat fp mbmime = do
_ -> Nothing

isNote :: Inline -> Bool
isNote (Cite _ [Note _]) = True
-- the following allows citation styles that are "in-text" but use superscript
-- references to be treated as if they are "notes" for the purposes of moving
-- the citations after trailing punctuation (see <https://github.com/jgm/pandoc-citeproc/issues/382>):
isNote (Cite _ [Superscript _]) = True
isNote _ = False
isNote (Cite cs xs) = length xs == 1 && endsWithNote (Cite cs xs)
isNote _ = False

endsWithNote :: Inline -> Bool
endsWithNote (Cite _ xs) =
-- this formulation captures both Cite [Note _] and cite [..., Note _];
-- the latter occurs with author-in-text citations.
case lastMay xs of
Just (Note _) -> True
-- the following allows citation styles that are "in-text" but use superscript
-- references to be treated as if they are "notes" for the purposes of moving
-- the citations after trailing punctuation (see <https://github.com/jgm/pandoc-citeproc/issues/382>):
Just (Superscript _) -> True
_ -> False
endsWithNote _ = False

isSpacy :: Inline -> Bool
isSpacy Space = True
Expand Down Expand Up @@ -420,7 +429,7 @@ mvPunct moveNotes locale (q : s : x : ys)
-- 'x[^1],' -> 'x,[^1]'
mvPunct moveNotes locale (Cite cs ils : ys)
| not (null ils)
, isNote (last ils)
, endsWithNote (last ils)
, startWithPunct ys
, moveNotes
= let s = stringify ys
Expand All @@ -431,8 +440,9 @@ mvPunct moveNotes locale (Cite cs ils : ys)
++ [last ils]) :
mvPunct moveNotes locale
(B.toList (dropTextWhile isPunctuation (B.fromList ys)))
mvPunct moveNotes locale (s : x : ys) | isSpacy s, isNote x =
x : mvPunct moveNotes locale ys
mvPunct moveNotes locale (s : x : ys)
| isSpacy s, isNote x
= x : mvPunct moveNotes locale ys
mvPunct moveNotes locale (s : x@(Cite _ (Superscript _ : _)) : ys)
| isSpacy s = x : mvPunct moveNotes locale ys
mvPunct moveNotes locale (Cite cs ils : Str "." : ys)
Expand Down
19 changes: 19 additions & 0 deletions test/command/author-in-text-move-note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```
% pandoc --citeproc --csl command/chicago-fullnote-bibliography.csl -t plain
---
references:
- id: foo
type: book
author: John Doe
title: A Book
...
See @foo [p. 21], as well.
^D
See John Doe[1], as well.
John Doe. A Book, n.d.
[1] A Book, n.d., 21.
```

0 comments on commit 92cb00a

Please sign in to comment.