summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-01-19 22:04:02 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2022-01-19 22:06:06 -0800
commitd9ec95e7abc71a642dd8e53b92f2bd3ae1609f10 (patch)
tree285125067b6541b12e51424db6c4c6d4926f7c80
parent89c8f2866e10a87c1b5eaeefc33b76a49953c5c8 (diff)
Modify stringify so it ignores `[Citation]` inside `Cite`.
Otherwise we'll sometimes get two copies of things, one from the `citationPrefix` or `citationSuffix` and another from the embedded fallback text. When there is no fallback text, we'll get no content. However, it really isn't an alternative to just rely on the result of running `query` on the embedded `Citation`s; this will result in a jumble of text rather than anything structured. Closes #7855.
-rw-r--r--src/Text/Pandoc/Shared.hs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 6d00b1468..5b833dd34 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -390,18 +390,11 @@ deLink :: Inline -> Inline
deLink (Link _ ils _) = Span nullAttr ils
deLink x = x
-deQuote :: Inline -> Inline
-deQuote (Quoted SingleQuote xs) =
- Span ("",[],[]) (Str "\8216" : xs ++ [Str "\8217"])
-deQuote (Quoted DoubleQuote xs) =
- Span ("",[],[]) (Str "\8220" : xs ++ [Str "\8221"])
-deQuote x = x
-
-- | Convert pandoc structure to a string with formatting removed.
-- Footnotes are skipped (since we don't want their contents in link
-- labels).
stringify :: Walkable Inline a => a -> T.Text
-stringify = query go . walk (deNote . deQuote)
+stringify = query go . walk fixInlines
where go :: Inline -> T.Text
go Space = " "
go SoftBreak = " "
@@ -413,6 +406,19 @@ stringify = query go . walk (deNote . deQuote)
go LineBreak = " "
go _ = ""
+ fixInlines :: Inline -> Inline
+ fixInlines (Cite _ ils) = Cite [] ils
+ fixInlines (Note _) = Note []
+ fixInlines (q@Quoted{}) = deQuote q
+ fixInlines x = x
+
+deQuote :: Inline -> Inline
+deQuote (Quoted SingleQuote xs) =
+ Span ("",[],[]) (Str "\8216" : xs ++ [Str "\8217"])
+deQuote (Quoted DoubleQuote xs) =
+ Span ("",[],[]) (Str "\8220" : xs ++ [Str "\8221"])
+deQuote x = x
+
-- | Bring all regular text in a pandoc structure to uppercase.
--
-- This function correctly handles cases where a lowercase character doesn't