Skip to content

Commit

Permalink
Pandoc: use Span with class csl-quoted for quotes, not Quoted.
Browse files Browse the repository at this point in the history
This way we can leave pandoc's Quoted alone, and we won't
get strange effects like the one described in #87 (where
`"` behaves differently when in a citation suffix).
  • Loading branch information
jgm committed Aug 14, 2021
1 parent 8b190ec commit c3eb08a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Citeproc/Pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ instance CiteprocOutput Inlines where
DisplayLeftMargin -> B.spanWith ("",["csl-left-margin"],[])
DisplayRightInline -> B.spanWith ("",["csl-right-inline"],[])
DisplayIndent -> B.spanWith ("",["csl-indent"],[])
addQuotes = B.doubleQuoted
addQuotes = B.spanWith ("",["csl-quoted"],[])
inNote = B.spanWith ("",["csl-note"],[])
movePunctuationInsideQuotes
= punctuationInsideQuotes
Expand All @@ -94,12 +94,14 @@ convertQuotes locale = B.fromList . map (go DoubleQuote) . B.toList
flipflop DoubleQuote = SingleQuote

go :: QuoteType -> Inline -> Inline
go qt (Quoted _ ils) =
Span ("",[],[]) (Str (oq qt) : map (go (flipflop qt)) ils ++ [Str (cq qt)])
go q (Span ("",["csl-quoted"],[]) ils) =
Span ("",["csl-quoted"],[])
(Str (oq q) : map (go (flipflop q)) ils ++ [Str (cq q)])
go q (Span attr zs) = Span attr (map (go q) zs)
go q (Quoted qt' zs) = Quoted qt' (map (go q) zs)
go q (SmallCaps zs) = SmallCaps (map (go q) zs)
go q (Superscript zs) = Superscript (map (go q) zs)
go q (Subscript zs) = Subscript (map (go q) zs)
go q (Span attr zs) = Span attr (map (go q) zs)
go q (Emph zs) = Emph (map (go q) zs)
go q (Underline zs) = Underline (map (go q) zs)
go q (Strong zs) = Strong (map (go q) zs)
Expand All @@ -117,9 +119,10 @@ punctuationInsideQuotes = B.fromList . go . walk go . B.toList
Just (c,_) -> c == '.' || c == ','
Nothing -> False
go [] = []
go (Quoted qt xs : Str t : rest)
go (Span ("",["csl-quoted"],[]) xs : Str t : rest)
| startsWithMovable t
= Quoted qt (xs ++ [Str (T.take 1 t) | not (endWithPunct True xs)]) :
= Span ("",["csl-quoted"],[])
(xs ++ [Str (T.take 1 t) | not (endWithPunct True xs)]) :
if T.length t == 1
then go rest
else Str (T.drop 1 t) : go rest
Expand Down

0 comments on commit c3eb08a

Please sign in to comment.