Skip to content

Commit

Permalink
Citeproc: fix both the expected test output and code for last commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Jan 15, 2025
1 parent 92cb00a commit 5662525
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
33 changes: 12 additions & 21 deletions src/Text/Pandoc/Citeproc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,13 @@ getBibliographyFormat fp mbmime = do
_ -> Nothing

isNote :: Inline -> Bool
isNote (Cite cs xs) = length xs == 1 && endsWithNote (Cite cs xs)
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

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
isSpacy SoftBreak = True
Expand All @@ -414,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 @@ -427,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)
, endsWithNote (last ils)
mvPunct moveNotes locale (Cite cs ils@(_:_) : ys)
| isNote (last ils)
, startWithPunct ys
, moveNotes
= let s = stringify ys
Expand All @@ -440,8 +430,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
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
Expand Down
2 changes: 1 addition & 1 deletion test/command/author-in-text-move-note.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ references:
See @foo [p. 21], as well.
^D
See John Doe[1], as well.
See John Doe,[1] as well.
John Doe. A Book, n.d.
Expand Down

0 comments on commit 5662525

Please sign in to comment.