aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-10-24 21:46:03 -0700
committerJohn MacFarlane <[email protected]>2023-10-24 21:46:03 -0700
commit4457b775d3f815471b0cad72d516d86102d15895 (patch)
treeb54178b7e763a077a3cbbdf04aa913f943e11fda /src
parent6f3ec91a0d64f90e955c51fbcff9f3a7f639f62c (diff)
ICML writer: prevent doubled attributes.
Closes #9158.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/ICML.hs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/ICML.hs b/src/Text/Pandoc/Writers/ICML.hs
index 8ee45f6c6..a19121968 100644
--- a/src/Text/Pandoc/Writers/ICML.hs
+++ b/src/Text/Pandoc/Writers/ICML.hs
@@ -157,9 +157,13 @@ writeICML opts doc = do
Just tpl -> renderTemplate tpl context
-- | Auxiliary functions for parStylesToDoc and charStylesToDoc.
-contains :: Text -> (Text, (Text, Text)) -> [(Text, Text)]
-contains s rule =
- [snd rule | fst rule `Text.isInfixOf` s]
+contains :: Text -> (Text, (Text, Text)) -> [(Text, Text)] -> [(Text, Text)]
+contains s (t, (k,v)) attrs =
+ if t `Text.isInfixOf` s
+ then case lookup k attrs of -- avoid duplicates, #9158
+ Nothing -> (k, v) : attrs
+ Just _ -> attrs
+ else attrs
-- | The monospaced font to use as default.
monospacedFont :: Doc Text
@@ -183,7 +187,7 @@ parStylesToDoc st = vcat $ map makeStyle $ Set.toAscList $ blockStyles st
where
makeStyle s =
let countSubStrs sub str = length $ Text.breakOnAll sub str
- attrs = concatMap (contains s) [
+ attrs = foldr (contains s) [] [
(defListTermName, ("BulletsAndNumberingListType", "BulletList"))
, (defListTermName, ("FontStyle", "Bold"))
, (tableHeaderName, ("FontStyle", "Bold"))
@@ -248,7 +252,7 @@ charStylesToDoc :: WriterState -> Doc Text
charStylesToDoc st = vcat $ map makeStyle $ Set.toAscList $ inlineStyles st
where
makeStyle s =
- let attrs = concatMap (contains s) [
+ let attrs = foldr (contains s) [] [
(strikeoutName, ("StrikeThru", "true"))
, (superscriptName, ("Position", "Superscript"))
, (subscriptName, ("Position", "Subscript"))