git.iko.soy/typeable/pandoc
on master help sign in
Citeproc: Insert space after csl-left-margin span contents...

if they come before csl-right-inline. This ensures that the citation number or label will be separated from the rest by a space, even in formats (like plain) that don't yet have special handling for the display spans.

commit810ea6fdf831a004da5f4731153ea3ac61af634c authorJohn MacFarlane <jgm@berkeley.edu> dateThu 24 Sep 2020, 09:55 (6 years ago) parent4f13c0e
4 files changed+21−7
src/Text/Pandoc/Citeproc.hs+16−2 test/command/pandoc-citeproc-327.md+1−1 test/command/pandoc-citeproc-386.md+1−1 test/command/pandoc-citeproc-ieee.md+3−3
src/Text/Pandoc/Citeproc.hs+16−2
@@ -135,8 +135,8 @@ processCitations (Pandoc meta bs) = do
135135 Just ls | ls > 1 -> (("line-spacing",T.pack $ show ls):)
136136 _ -> id) $ []
137137 let bibs = mconcat $ map (\(ident, out) ->
138− B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para $
139− walk (convertQuotes locale) out)
138+ B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para .
139+ walk (convertQuotes locale) . insertSpace $ out)
140140 (resultBibliography result)
141141 let moveNotes = maybe True truish $
142142 lookupMeta "notes-after-punctuation" meta
@@ -155,6 +155,20 @@ processCitations (Pandoc meta bs) = do
155155 $ cits
156156 return $ Pandoc meta'' $ insertRefs refkvs classes meta'' (B.toList bibs) bs'
157157
158+-- If we have a span.csl-left-margin followed by span.csl-right-inline,
159+-- we insert a space. This ensures that they will be separated by a space,
160+-- even in formats that don't have special handling for the display spans.
161+insertSpace :: Inlines -> Inlines
162+insertSpace ils =
163+ case Seq.viewl (unMany ils) of
164+ (Span ("",["csl-left-margin"],[]) xs) Seq.:< rest ->
165+ case Seq.lookup 0 rest of
166+ Just (Span ("",["csl-right-inline"],[]) _) ->
167+ Many $
168+ Span ("",["csl-left-margin"],[]) (xs ++ [Space]) Seq.<| rest
169+ _ -> ils
170+ _ -> ils
171+
158172getRefsFromBib :: PandocMonad m
159173 => Locale -> (Text -> Bool) -> Text -> m [Reference Inlines]
160174getRefsFromBib locale idpred t = do
test/command/pandoc-citeproc-327.md+1−1
@@ -43,7 +43,7 @@ I referenced something here^\[1\]^
4343
4444::: {#refs .references .csl-bib-body}
4545::: {#ref-LiLiaoDongWanHaiYuDiQiDongWuCiJiShengChanLiYanJiuJiShengJingGuaYiXingPingJie2017 .csl-entry}
46−[\[1\]]{.csl-left-margin}[李轶平, 于旭光, 孙明, 等.
46+[\[1\] ]{.csl-left-margin}[李轶平, 于旭光, 孙明, 等.
4747辽东湾海域底栖动物次级生产力研究及生境适宜性评价\[J\]. 水产科学,
48482017(06): 728--734.]{.csl-right-inline}
4949:::
test/command/pandoc-citeproc-386.md+1−1
@@ -28,7 +28,7 @@ references:
2828
2929::: {#refs .references .csl-bib-body line-spacing="2"}
3030::: {#ref-ding_metallic_2012 .csl-entry}
31−[\[1\]]{.csl-left-margin}[K. Ding, C. Z. Ning, *Light Sci. Appl.*
31+[\[1\] ]{.csl-left-margin}[K. Ding, C. Z. Ning, *Light Sci. Appl.*
3232**2012**, *1*, e20.]{.csl-right-inline}
3333:::
3434:::
test/command/pandoc-citeproc-ieee.md+3−3
@@ -88,17 +88,17 @@ References {#references .unnumbered}
8888
8989::: {#refs .references .csl-bib-body}
9090::: {#ref-item1 .csl-entry}
91−[\[1\]]{.csl-left-margin}[J. Doe, *First book*. Cambridge: Cambridge
91+[\[1\] ]{.csl-left-margin}[J. Doe, *First book*. Cambridge: Cambridge
9292University Press, 2005.]{.csl-right-inline}
9393:::
9494
9595::: {#ref-item2 .csl-entry}
96−[\[2\]]{.csl-left-margin}[J. Doe, "Article," *Journal of Generic
96+[\[2\] ]{.csl-left-margin}[J. Doe, "Article," *Journal of Generic
9797Studies*, vol. 6, pp. 33--34, 2006.]{.csl-right-inline}
9898:::
9999
100100::: {#ref-пункт3 .csl-entry}
101−[\[3\]]{.csl-left-margin}[J. Doe and J. Roe, "Why water is wet," in
101+[\[3\] ]{.csl-left-margin}[J. Doe and J. Roe, "Why water is wet," in
102102*Third book*, S. Smith, Ed. Oxford: Oxford University Press,
1031032007.]{.csl-right-inline}
104104:::