git.iko.soy/typeable/pandoc
on master help sign in
5 files changed+142−29
since splitsnapshots
unifiedsplit
cabal.project+1−1 src/Text/Pandoc/Citeproc.hs+49−26 src/Text/Pandoc/Writers/HTML.hs+6−1 stack.yaml+1−1 test/command/7394.md+85
cabal.project+1−1
@@ -10,4 +10,4 @@ source-repository-package
1010source-repository-package
1111 type: git
1212 location: https://github.com/jgm/citeproc
13− tag: 85277c4baa6c0350baf29247583ae0f438f7c9c5
13+ tag: 4ce0501cd6f9c86eee087afcf878c256e49b9615
src/Text/Pandoc/Citeproc.hs+49−26
@@ -27,7 +27,7 @@ import Text.Pandoc.Error (PandocError(..))
2727import Text.Pandoc.Extensions (pandocExtensions)
2828import Text.Pandoc.Logging (LogMessage(..))
2929import Text.Pandoc.Options (ReaderOptions(..))
30−import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines, tshow)
30+import Text.Pandoc.Shared (stringify, ordNub, tshow)
3131import qualified Text.Pandoc.UTF8 as UTF8
3232import Text.Pandoc.Walk (query, walk, walkM)
3333import Control.Applicative ((<|>))
@@ -49,6 +49,7 @@ import qualified Data.Text as T
4949import System.FilePath (takeExtension)
5050import Safe (lastMay, initSafe)
5151
52+
5253processCitations :: PandocMonad m => Pandoc -> m Pandoc
5354processCitations (Pandoc meta bs) = do
5455 style <- getStyle (Pandoc meta bs)
@@ -98,8 +99,10 @@ processCitations (Pandoc meta bs) = do
9899 let metanocites = lookupMeta "nocite" meta
99100 let Pandoc meta'' bs' =
100101 maybe id (setMeta "nocite") metanocites .
101− walk (map capitalizeNoteCitation . mvPunct moveNotes locale) .
102− walk deNote .
102+ walk (mvPunct moveNotes locale) .
103+ (if styleIsNoteStyle sopts
104+ then walk addNote . walk deNote
105+ else id) .
103106 evalState (walkM insertResolvedCitations $ Pandoc meta' bs)
104107 $ cits
105108 return $ Pandoc meta''
@@ -561,42 +564,62 @@ extractText (FancyVal x) = toText x
561564extractText (NumVal n) = T.pack (show n)
562565extractText _ = mempty
563566
564−capitalizeNoteCitation :: Inline -> Inline
565−capitalizeNoteCitation (Cite cs [Note [Para ils]]) =
566− Cite cs
567− [Note [Para $ B.toList $ addTextCase Nothing CapitalizeFirst
568− $ B.fromList ils]]
569−capitalizeNoteCitation x = x
570−
571−deNote :: [Inline] -> [Inline]
572−deNote [] = []
573−deNote (Note bs:rest) =
574− Note (walk go bs) : deNote rest
567+-- Here we take the Spans with class csl-note that are left
568+-- after deNote has removed nested ones, and convert them
569+-- into real notes.
570+addNote :: Inline -> Inline
571+addNote (Span ("",["csl-note"],[]) ils) =
572+ Note [Para $
573+ B.toList . addTextCase Nothing CapitalizeFirst . B.fromList $ ils]
574+addNote x = x
575+
576+-- Here we handle citation notes that occur inside footnotes
577+-- or other citation notes, in a note style. We don't want
578+-- notes inside notes, so we convert these to parenthesized
579+-- or comma-separated citations.
580+deNote :: Inline -> Inline
581+deNote (Note bs) =
582+ case bs of
583+ [Para (cit@(Cite (c:_) _) : ils)]
584+ | citationMode c /= AuthorInText ->
585+ -- if citation is first in note, no need to parenthesize.
586+ Note [Para (walk removeNotes $ cit : walk addParens ils)]
587+ _ -> Note (walk removeNotes . walk addParens $ bs)
588+
575589 where
576− go [] = []
577− go (Cite (c:cs) ils : zs)
590+ addParens [] = []
591+ addParens (Cite (c:cs) ils : zs)
578592 | citationMode c == AuthorInText
579− = Cite (c:cs) (concatMap (noteAfterComma (needsPeriod zs)) ils) : go zs
593+ = Cite (c:cs) (concatMap (noteAfterComma (needsPeriod zs)) ils) :
594+ addParens zs
580595 | otherwise
581− = Cite (c:cs) (concatMap noteInParens ils) : go zs
582− go (x:xs) = x : go xs
596+ = Cite (c:cs) (concatMap noteInParens ils) : addParens zs
597+ addParens (x:xs) = x : addParens xs
598+
599+ removeNotes (Span ("",["csl-note"],[]) ils) = Span ("",[],[]) ils
600+ removeNotes x = x
601+
583602 needsPeriod [] = True
584603 needsPeriod (Str t:_) = case T.uncons t of
585604 Nothing -> False
586605 Just (c,_) -> isUpper c
587606 needsPeriod (Space:zs) = needsPeriod zs
588607 needsPeriod _ = False
589− noteInParens (Note bs')
608+
609+ noteInParens (Span ("",["csl-note"],[]) ils)
590610 = Space : Str "(" :
591− removeFinalPeriod (blocksToInlines bs') ++ [Str ")"]
611+ removeFinalPeriod ils ++ [Str ")"]
592612 noteInParens x = [x]
593− noteAfterComma needsPer (Note bs')
613+
614+ noteAfterComma needsPer (Span ("",["csl-note"],[]) ils)
615+ | not (null ils)
594616 = Str "," : Space :
595− (if needsPer
596− then id
597− else removeFinalPeriod) (blocksToInlines bs')
617+ if needsPer
618+ then ils
619+ else removeFinalPeriod ils
598620 noteAfterComma _ x = [x]
599−deNote (x:xs) = x : deNote xs
621+
622+deNote x = x
600623
601624-- Note: we can't use dropTextWhileEnd indiscriminately,
602625-- because this would remove the final period on abbreviations like Ibid.
src/Text/Pandoc/Writers/HTML.hs+6−1
@@ -26,8 +26,13 @@ module Text.Pandoc.Writers.HTML (
2626 writeSlideous,
2727 writeDZSlides,
2828 writeRevealJs,
29− tagWithAttributes
29+ tagWithAttributes,
30+ inlineToHtml,
31+ blockToHtml,
32+ WriterState(..),
33+ defaultWriterState
3034 ) where
35+
3136import Control.Monad.State.Strict
3237import Data.Char (ord)
3338import Data.List (intercalate, intersperse, partition, delete, (\\), foldl')
stack.yaml+1−1
@@ -14,7 +14,7 @@ extra-deps:
1414- git: https://github.com/jgm/doctemplates
1515 commit: 428c26d5303cf7a2b1051fe1ffd9aafe9ba71c81
1616- git: https://github.com/jgm/citeproc
17− commit: 85277c4baa6c0350baf29247583ae0f438f7c9c5
17+ commit: 4ce0501cd6f9c86eee087afcf878c256e49b9615
1818ghc-options:
1919 "$locals": -fhide-source-paths -Wno-missing-home-modules
2020resolver: lts-18.0
test/command/7394.mdnew file+85
@@ -0,0 +1,85 @@
1+```
2+% pandoc -f markdown -t plain --citeproc
3+---
4+csl: command/chicago-fullnote-bibliography.csl
5+references:
6+- author:
7+ - family: Wandt
8+ given: Manfred
9+ edition: 6
10+ id: wandt2014ges-sv
11+ issued: 2014
12+ publisher: Franz Vahlen
13+ publisher-place: München
14+ title: Gesetzliche schuldverhältnisse
15+ title-short: Gesetzl SV
16+ type: book
17+- author:
18+ - family: Smith
19+ given: Zenda
20+ edition: 6
21+ id: smith2015
22+ issued: 2015
23+ publisher: Macmillan
24+ publisher-place: New York
25+ title: A verb and a noun
26+ type: book
27+---
28+
29+Hi^[@wandt2014ges-sv.].
30+
31+Hi^[[@wandt2014ges-sv].].
32+
33+Hi^[[See also @wandt2014ges-sv].].
34+
35+Hi^[See also @wandt2014ges-sv.].
36+
37+Hi^[@wandt2014ges-sv [@smith2015].].
38+
39+Hi^[[@wandt2014ges-sv; @smith2015].].
40+
41+Hi [@wandt2014ges-sv].
42+
43+Hi [see also @wandt2014ges-sv].
44+
45+^D
46+Hi[1].
47+
48+Hi[2].
49+
50+Hi[3].
51+
52+Hi[4].
53+
54+Hi[5].
55+
56+Hi[6].
57+
58+Hi.[7]
59+
60+Hi.[8]
61+
62+Smith, Zenda. A Verb and a Noun. 6th ed. New York: Macmillan, 2015.
63+
64+Wandt, Manfred. Gesetzliche Schuldverhältnisse. 6th ed. München: Franz
65+Vahlen, 2014.
66+
67+[1] Manfred Wandt, Gesetzliche Schuldverhältnisse, 6th ed. (München:
68+Franz Vahlen, 2014).
69+
70+[2] Wandt.
71+
72+[3] See also Wandt.
73+
74+[4] See also Wandt.
75+
76+[5] Wandt, Zenda Smith, A Verb and a Noun, 6th ed. (New York: Macmillan,
77+2015).
78+
79+[6] Wandt, Gesetzl SV; Smith, A Verb and a Noun.
80+
81+[7] Wandt, Gesetzl SV.
82+
83+[8] See also Wandt.
84+```
85+