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 16, 2025
1 parent 806dcb0 commit 96d4f5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/Text/Pandoc/Citeproc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ 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 (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 (Superscript _) = True
isNote _ = False

isSpacy :: Inline -> Bool
isSpacy Space = True
Expand All @@ -405,9 +405,9 @@ mvPunct :: Bool -> Locale -> [Inline] -> [Inline]
mvPunct moveNotes locale (x : xs)
| isSpacy x = x : mvPunct moveNotes locale xs
-- 'x [^1],' -> 'x,[^1]'
mvPunct moveNotes locale (q : s : x : ys)
mvPunct moveNotes locale (q : s : x@(Cite _ [il]) : ys)
| isSpacy s
, isNote x
, isNote il
= let spunct = T.takeWhile isPunctuation $ stringify ys
in if moveNotes
then if T.null spunct
Expand All @@ -418,9 +418,8 @@ mvPunct moveNotes locale (q : s : x : ys)
(dropTextWhile isPunctuation (B.fromList ys)))
else q : x : mvPunct moveNotes locale ys
-- 'x[^1],' -> 'x,[^1]'
mvPunct moveNotes locale (Cite cs ils : ys)
| not (null ils)
, isNote (last ils)
mvPunct moveNotes locale (Cite cs ils@(_:_) : ys)
| isNote (last ils)
, startWithPunct ys
, moveNotes
= let s = stringify ys
Expand All @@ -431,8 +430,10 @@ 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@(Cite _ [il]) : ys)
| isSpacy s
, isNote il
= 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 96d4f5b

Please sign in to comment.