aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-09-24 09:55:32 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2020-09-24 09:57:55 -0700
commit810ea6fdf831a004da5f4731153ea3ac61af634c (patch)
treeb0b8ca939eef366731a735243969e1e8f87a6e0d
parent4f13c0e25e7c97c0590944718a65147cf2c5d07a (diff)
downloadpandoc-810ea6fdf831a004da5f4731153ea3ac61af634c.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Citeproc.hs18
-rw-r--r--test/command/pandoc-citeproc-327.md2
-rw-r--r--test/command/pandoc-citeproc-386.md2
-rw-r--r--test/command/pandoc-citeproc-ieee.md6
4 files changed, 21 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
index 9fb0e2f0b..71331a4a2 100644
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -135,8 +135,8 @@ processCitations (Pandoc meta bs) = do
Just ls | ls > 1 -> (("line-spacing",T.pack $ show ls):)
_ -> id) $ []
let bibs = mconcat $ map (\(ident, out) ->
- B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para $
- walk (convertQuotes locale) out)
+ B.divWith ("ref-" <> ident,["csl-entry"],[]) . B.para .
+ walk (convertQuotes locale) . insertSpace $ out)
(resultBibliography result)
let moveNotes = maybe True truish $
lookupMeta "notes-after-punctuation" meta
@@ -155,6 +155,20 @@ processCitations (Pandoc meta bs) = do
$ cits
return $ Pandoc meta'' $ insertRefs refkvs classes meta'' (B.toList bibs) bs'
+-- If we have a span.csl-left-margin followed by span.csl-right-inline,
+-- we insert a space. This ensures that they will be separated by a space,
+-- even in formats that don't have special handling for the display spans.
+insertSpace :: Inlines -> Inlines
+insertSpace ils =
+ case Seq.viewl (unMany ils) of
+ (Span ("",["csl-left-margin"],[]) xs) Seq.:< rest ->
+ case Seq.lookup 0 rest of
+ Just (Span ("",["csl-right-inline"],[]) _) ->
+ Many $
+ Span ("",["csl-left-margin"],[]) (xs ++ [Space]) Seq.<| rest
+ _ -> ils
+ _ -> ils
+
getRefsFromBib :: PandocMonad m
=> Locale -> (Text -> Bool) -> Text -> m [Reference Inlines]
getRefsFromBib locale idpred t = do
diff --git a/test/command/pandoc-citeproc-327.md b/test/command/pandoc-citeproc-327.md
index 54265dcc1..92b29bdf8 100644
--- a/test/command/pandoc-citeproc-327.md
+++ b/test/command/pandoc-citeproc-327.md
@@ -43,7 +43,7 @@ I referenced something here^\[1\]^
::: {#refs .references .csl-bib-body}
::: {#ref-LiLiaoDongWanHaiYuDiQiDongWuCiJiShengChanLiYanJiuJiShengJingGuaYiXingPingJie2017 .csl-entry}
-[\[1\]]{.csl-left-margin}[李轶平, 于旭光, 孙明, 等.
+[\[1\] ]{.csl-left-margin}[李轶平, 于旭光, 孙明, 等.
辽东湾海域底栖动物次级生产力研究及生境适宜性评价\[J\]. 水产科学,
2017(06): 728--734.]{.csl-right-inline}
:::
diff --git a/test/command/pandoc-citeproc-386.md b/test/command/pandoc-citeproc-386.md
index 6fab96c07..6f346e7db 100644
--- a/test/command/pandoc-citeproc-386.md
+++ b/test/command/pandoc-citeproc-386.md
@@ -28,7 +28,7 @@ references:
::: {#refs .references .csl-bib-body line-spacing="2"}
::: {#ref-ding_metallic_2012 .csl-entry}
-[\[1\]]{.csl-left-margin}[K. Ding, C. Z. Ning, *Light Sci. Appl.*
+[\[1\] ]{.csl-left-margin}[K. Ding, C. Z. Ning, *Light Sci. Appl.*
**2012**, *1*, e20.]{.csl-right-inline}
:::
:::
diff --git a/test/command/pandoc-citeproc-ieee.md b/test/command/pandoc-citeproc-ieee.md
index 653e1e0b5..17ade2aae 100644
--- a/test/command/pandoc-citeproc-ieee.md
+++ b/test/command/pandoc-citeproc-ieee.md
@@ -88,17 +88,17 @@ References {#references .unnumbered}
::: {#refs .references .csl-bib-body}
::: {#ref-item1 .csl-entry}
-[\[1\]]{.csl-left-margin}[J. Doe, *First book*. Cambridge: Cambridge
+[\[1\] ]{.csl-left-margin}[J. Doe, *First book*. Cambridge: Cambridge
University Press, 2005.]{.csl-right-inline}
:::
::: {#ref-item2 .csl-entry}
-[\[2\]]{.csl-left-margin}[J. Doe, "Article," *Journal of Generic
+[\[2\] ]{.csl-left-margin}[J. Doe, "Article," *Journal of Generic
Studies*, vol. 6, pp. 33--34, 2006.]{.csl-right-inline}
:::
::: {#ref-пункт3 .csl-entry}
-[\[3\]]{.csl-left-margin}[J. Doe and J. Roe, "Why water is wet," in
+[\[3\] ]{.csl-left-margin}[J. Doe and J. Roe, "Why water is wet," in
*Third book*, S. Smith, Ed. Oxford: Oxford University Press,
2007.]{.csl-right-inline}
:::