diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-03-07 10:58:56 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-03-07 10:58:56 -0800 |
commit | 0b42eb5f581e04ba4ea4baca4d5256e81bc6310e (patch) | |
tree | 622e1b3f3662871aa8f6c9f679954fb6eff99ca5 | |
parent | 48eaadc57ff45bb44efe9c8da85a1c792c03dc77 (diff) | |
download | pandoc-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.hs | 10 |
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)) |