From 810ea6fdf831a004da5f4731153ea3ac61af634c Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Thu, 24 Sep 2020 09:55:32 -0700 Subject: 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. --- src/Text/Pandoc/Citeproc.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src') 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 -- cgit v1.2.3