summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Hathaway <jesse@mbuki-mvuki.org>2022-01-06 10:10:10 -0600
committerJohn MacFarlane <jgm@berkeley.edu>2022-01-06 15:05:39 -0800
commit4dcb2b6fb6d634c226adc173cb4c77f45360f836 (patch)
tree228b3364e1df7037ca5f0872fe1312bf7fb8d86c
parent6fffa1ac7884896406b9b5626aab35660a8826f3 (diff)
MediaWiki writer: Remove redundant display text for wiki links
Prior to this commit the MediaWiki writer always added the display text for a wiki link: * [[Help|Help]] * [[Bubbles|Everyone loves bubbles]] However the display text in the first example is redundant since MediaWiki uses the target as the default display text. The result being: * [[Help]] * [[Bubbles|Everyone loves bubbles]]
-rw-r--r--src/Text/Pandoc/Writers/MediaWiki.hs11
-rw-r--r--test/command/7808.md8
2 files changed, 15 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs
index a04975ae3..f4bdf239c 100644
--- a/src/Text/Pandoc/Writers/MediaWiki.hs
+++ b/src/Text/Pandoc/Writers/MediaWiki.hs
@@ -449,10 +449,13 @@ inlineToMediaWiki (Link _ txt (src, _)) = do
case txt of
[Str s] | isURI src && escapeURI s == src -> return src
_ -> return $ if isURI src
- then "[" <> src <> " " <> label <> "]"
- else "[[" <> src' <> "|" <> label <> "]]"
- -- with leading / it's a link to a help page
- where src' = fromMaybe src $ T.stripPrefix "/" src
+ then "[" <> src <> " " <> label <> "]"
+ else
+ if src == label
+ then "[[" <> src' <> "]]"
+ else "[[" <> src' <> "|" <> label <> "]]"
+ -- with leading / it's a link to a help page
+ where src' = fromMaybe src $ T.stripPrefix "/" src
inlineToMediaWiki (Image attr alt (source, tit)) = do
img <- imageToMediaWiki attr
diff --git a/test/command/7808.md b/test/command/7808.md
new file mode 100644
index 000000000..9c7d3032f
--- /dev/null
+++ b/test/command/7808.md
@@ -0,0 +1,8 @@
+Wiki links should have no display text, if their display text matches
+their target.
+```
+% pandoc -f mediawiki -t mediawiki
+[[Help]] [[Butter|Butter]] [[Bubbles|Everyone loves bubbles]]
+^D
+[[Help]] [[Butter]] [[Bubbles|Everyone loves bubbles]]
+```