diff options
| author | John MacFarlane <[email protected]> | 2025-01-15 15:32:54 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-01-16 08:32:02 -0800 |
| commit | 96d4f5be518900fe7ad53fcd163f3237d737862f (patch) | |
| tree | 4ce7ce1d25c03b43f7bffc83d648696fee1c834d /src/Text | |
| parent | 806dcb08498fd04e23ecec1ec89ecd0d8005fcd0 (diff) | |
Citeproc: fix moving punctuation before citation notes.
This previously worked with regular citations, but not author-in-text
citations. Now it works with both.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/Citeproc.hs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index b590acc3f..a290a8bdf 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -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 @@ -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 @@ -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 @@ -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) |
