aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-02-05 10:08:18 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-02-05 10:08:18 -0800
commit0a4f49d3703bfb7016800148059206482278eeb6 (patch)
treebef9970b57f97b26c35bd93f671c173000ed912a
parent9c4dc8b49b3894d51aa37fbcff1c228776ffb98f (diff)
downloadpandoc-0a4f49d3703bfb7016800148059206482278eeb6.tar.gz
MediaWiki writer: prevent triple `[[[`.
This confuses mediawiki's parser. So we insert a `<nowiki/>` no-op between a literal `[` and a link. Closes #6119.
-rw-r--r--src/Text/Pandoc/Writers/MediaWiki.hs12
-rw-r--r--test/command/6119.md10
2 files changed, 21 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs
index ad292200c..d63c9de2e 100644
--- a/src/Text/Pandoc/Writers/MediaWiki.hs
+++ b/src/Text/Pandoc/Writers/MediaWiki.hs
@@ -347,7 +347,17 @@ blockListToMediaWiki blocks =
-- | Convert list of Pandoc inline elements to MediaWiki.
inlineListToMediaWiki :: PandocMonad m => [Inline] -> MediaWikiWriter m Text
inlineListToMediaWiki lst =
- fmap T.concat $ mapM inlineToMediaWiki lst
+ fmap T.concat $ mapM inlineToMediaWiki $ fixup lst
+ where
+ fixup [] = []
+ fixup (Str t : x : xs)
+ | not (T.null t) && T.last t == '['
+ , isLinkOrImage x =
+ Str t : RawInline (Format "mediawiki") "<nowiki/>" : x : fixup xs
+ fixup (x:xs) = x : fixup xs
+ isLinkOrImage (Link{}) = True
+ isLinkOrImage (Image{}) = True
+ isLinkOrImage _ = False
-- | Convert Pandoc inline element to MediaWiki.
inlineToMediaWiki :: PandocMonad m => Inline -> MediaWikiWriter m Text
diff --git a/test/command/6119.md b/test/command/6119.md
new file mode 100644
index 000000000..6a0085e18
--- /dev/null
+++ b/test/command/6119.md
@@ -0,0 +1,10 @@
+```
+% pandoc -t mediawiki
+[[link](url)]
+
+[![image](url)]
+^D
+[<nowiki/>[[url|link]]]
+
+[<nowiki/>[[File:url|image]]]
+```