aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-03-07 10:58:56 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-03-07 10:58:56 -0800
commit0b42eb5f581e04ba4ea4baca4d5256e81bc6310e (patch)
tree622e1b3f3662871aa8f6c9f679954fb6eff99ca5
parent48eaadc57ff45bb44efe9c8da85a1c792c03dc77 (diff)
downloadpandoc-0b42eb5f581e04ba4ea4baca4d5256e81bc6310e.tar.gz
MediaWiki writer: spaces to underscores in wikilink URL.
This mimics MediaWiki itself. Closes #1982.
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index e43b8a86c..d1ba35ba0 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -593,11 +593,17 @@ imageOption =
<|> try (many1 (oneOf "x0123456789") <* string "px")
<|> try (oneOfStrings ["link=","alt=","page=","class="] <* many (noneOf "|]"))
+collapseUnderscores :: String -> String
+collapseUnderscores [] = []
+collapseUnderscores ('_':'_':xs) = collapseUnderscores ('_':xs)
+collapseUnderscores (x:xs) = x : collapseUnderscores xs
+
+addUnderscores :: String -> String
+addUnderscores = collapseUnderscores . intercalate "_" . words
+
internalLink :: MWParser Inlines
internalLink = try $ do
sym "[["
- let addUnderscores x = let (pref,suff) = break (=='#') x
- in pref ++ intercalate "_" (words suff)
pagename <- unwords . words <$> many (noneOf "|]")
label <- option (B.text pagename) $ char '|' *>
( (mconcat <$> many1 (notFollowedBy (char ']') *> inline))