git.iko.soy/typeable/pandoc
on master help sign in
Improve punctuation moving with `--citeproc`.

Previously, using `--citeproc` could cause punctuation to move in quotes even when there aer no citations. This has been changed; now, punctuation moving is limited to citations. In addition, we only move footnotes around punctuation if the style is a note style, even if `notes-after-punctuation` is `true`.

commit851d037b3eee4516fde50b81eb8a0fc9b2f1545b authorJohn MacFarlane <jgm@berkeley.edu> dateMon 28 Jun 2021, 22:41 (5 years ago) parent97b0aa6
3 files changed+18−17
src/Text/Pandoc/Citeproc.hs+15−14 test/command/6890.md+2−2 test/command/pandoc-citeproc-322.md+1−1
src/Text/Pandoc/Citeproc.hs+15−14
@@ -90,21 +90,15 @@ processCitations (Pandoc meta bs) = do
9090 walk (convertQuotes locale) .
9191 insertSpace $ out)
9292 (resultBibliography result)
93− let moveNotes = maybe True truish $
94− lookupMeta "notes-after-punctuation" meta
93+ let moveNotes = styleIsNoteStyle sopts &&
94+ maybe True truish (lookupMeta "notes-after-punctuation" meta)
9595 let cits = map (walk (convertQuotes locale)) $
9696 resultCitations result
9797
98− let fixQuotes = case localePunctuationInQuote locale of
99− Just True ->
100− B.toList . movePunctuationInsideQuotes . B.fromList
101− _ -> id
102−
10398 let metanocites = lookupMeta "nocite" meta
10499 let Pandoc meta'' bs' =
105100 maybe id (setMeta "nocite") metanocites .
106− walk (map capitalizeNoteCitation .
107− fixQuotes . mvPunct moveNotes locale) .
101+ walk (map capitalizeNoteCitation . mvPunct moveNotes locale) .
108102 walk deNote .
109103 evalState (walkM insertResolvedCitations $ Pandoc meta' bs)
110104 $ cits
@@ -375,7 +369,6 @@ formatFromExtension fp = case dropWhile (== '.') $ takeExtension fp of
375369
376370
377371isNote :: Inline -> Bool
378−isNote (Note _) = True
379372isNote (Cite _ [Note _]) = True
380373 -- the following allows citation styles that are "in-text" but use superscript
381374 -- references to be treated as if they are "notes" for the purposes of moving
@@ -388,6 +381,12 @@ isSpacy Space = True
388381isSpacy SoftBreak = True
389382isSpacy _ = False
390383
384+movePunctInsideQuotes :: Locale -> [Inline] -> [Inline]
385+movePunctInsideQuotes locale
386+ | localePunctuationInQuote locale == Just True
387+ = B.toList . movePunctuationInsideQuotes . B.fromList
388+ | otherwise
389+ = id
391390
392391mvPunct :: Bool -> Locale -> [Inline] -> [Inline]
393392mvPunct moveNotes locale (x : xs)
@@ -400,7 +399,8 @@ mvPunct moveNotes locale (q : s : x : ys)
400399 in if moveNotes
401400 then if T.null spunct
402401 then q : x : mvPunct moveNotes locale ys
403− else q : Str spunct : x : mvPunct moveNotes locale
402+ else movePunctInsideQuotes locale
403+ [q , Str spunct , x] ++ mvPunct moveNotes locale
404404 (B.toList
405405 (dropTextWhile isPunctuation (B.fromList ys)))
406406 else q : x : mvPunct moveNotes locale ys
@@ -412,9 +412,10 @@ mvPunct moveNotes locale (Cite cs ils : ys)
412412 , moveNotes
413413 = let s = stringify ys
414414 spunct = T.takeWhile isPunctuation s
415− in Cite cs (init ils
416− ++ [Str spunct | not (endWithPunct False (init ils))]
417− ++ [last ils]) :
415+ in Cite cs (movePunctInsideQuotes locale $
416+ init ils
417+ ++ [Str spunct | not (endWithPunct False (init ils))]
418+ ++ [last ils]) :
418419 mvPunct moveNotes locale
419420 (B.toList (dropTextWhile isPunctuation (B.fromList ys)))
420421mvPunct moveNotes locale (s : x : ys) | isSpacy s, isNote x =
test/command/6890.md+2−2
@@ -23,12 +23,12 @@ references:
2323
2424@fruchtel-sozialer-2013a
2525
26−Some text [^1].
26+Some text.[^1]
2727
2828[^1]: @fruchtel-sozialer-2013a
2929^D
3030[Para [Cite [Citation {citationId = "fruchtel-sozialer-2013a", citationPrefix = [], citationSuffix = [], citationMode = AuthorInText, citationNoteNum = 1, citationHash = 0}] [Str "Fr\252chtel,",Space,Str "Budde,",Space,Str "and",Space,Str "Cyprian",Space,Str "(2013)"]]
31−,Para [Str "Some",Space,Str "text",Str ".",Note [Para [Cite [Citation {citationId = "fruchtel-sozialer-2013a", citationPrefix = [], citationSuffix = [], citationMode = AuthorInText, citationNoteNum = 2, citationHash = 0}] [Str "Fr\252chtel,",Space,Str "Budde,",Space,Str "and",Space,Str "Cyprian",Space,Str "(2013)"]]],Str ""]
31+,Para [Str "Some",Space,Str "text.",Note [Para [Cite [Citation {citationId = "fruchtel-sozialer-2013a", citationPrefix = [], citationSuffix = [], citationMode = AuthorInText, citationNoteNum = 2, citationHash = 0}] [Str "Fr\252chtel,",Space,Str "Budde,",Space,Str "and",Space,Str "Cyprian",Space,Str "(2013)"]]]]
3232,Div ("refs",["references","csl-bib-body","hanging-indent"],[])
3333 [Div ("ref-fruchtel-sozialer-2013a",["csl-entry"],[])
3434 [Para [Str "Fr\252chtel,",Space,Str "Frank,",Space,Str "Wolfgang",Space,Str "Budde,",Space,Str "and",Space,Str "Gudrun",Space,Str "Cyprian.",Space,Str "2013.",Space,Emph [Str "Sozialer",Space,Str "Raum",Space,Str "und",Space,Str "Soziale",Space,Str "Arbeit",Space,Str "Fieldbook:",Space,Str "Methoden",Space,Str "und",Space,Str "Techniken"],Str ".",Space,Str "3rd",Space,Str "ed.",Space,Str "Wiesbaden,",Space,Str "Germany:",Space,Str "Springer",Space,Str "VS."]]]]
test/command/pandoc-citeproc-322.md+1−1
@@ -19,7 +19,7 @@ references:
1919 type: 'article-journal'
2020---
2121
22−Foo[@timmory__justice_1950].
22+Foo [@timmory__justice_1950].
2323^D
2424Foo.[^1]
2525