diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-08-06 23:41:03 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-08-06 23:41:03 +0200 |
commit | 124679fd63564d434e2f90616be1c6daebaa22f9 (patch) | |
tree | 919325223ba67dc3cb2475ee9dda00c946174218 /src/Text/Pandoc/Readers | |
parent | 3a494392028daff84fecb6dddc2fd9535faf91b2 (diff) | |
download | pandoc-124679fd63564d434e2f90616be1c6daebaa22f9.tar.gz |
Improved mediawiki reader's treatment of verbatim constructions.
Previously these yielded strings of alternating Code and Space
elements; we now incorporate the spaces into the Code. Emphasis
etc. is still possible inside these.
Closes #3055.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 4e4bc3fb0..dcf0c5f4a 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -376,11 +376,17 @@ preformatted = try $ do spacesStr _ = False if F.all spacesStr contents then return mempty - else return $ B.para $ walk strToCode contents - -strToCode :: Inline -> Inline -strToCode (Str s) = Code ("",[],[]) s -strToCode x = x + else return $ B.para $ encode contents + +encode :: Inlines -> Inlines +encode = B.fromList . normalizeCode . B.toList . walk strToCode + where strToCode (Str s) = Code ("",[],[]) s + strToCode Space = Code ("",[],[]) " " + strToCode x = x + normalizeCode [] = [] + normalizeCode (Code a1 x : Code a2 y : zs) | a1 == a2 = + normalizeCode $ (Code a1 (x ++ y)) : zs + normalizeCode (x:xs) = x : normalizeCode xs header :: MWParser Blocks header = try $ do @@ -545,8 +551,8 @@ inlineTag = do TagOpen "del" _ -> B.strikeout <$> inlinesInTags "del" TagOpen "sub" _ -> B.subscript <$> inlinesInTags "sub" TagOpen "sup" _ -> B.superscript <$> inlinesInTags "sup" - TagOpen "code" _ -> walk strToCode <$> inlinesInTags "code" - TagOpen "tt" _ -> walk strToCode <$> inlinesInTags "tt" + TagOpen "code" _ -> encode <$> inlinesInTags "code" + TagOpen "tt" _ -> encode <$> inlinesInTags "tt" TagOpen "hask" _ -> B.codeWith ("",["haskell"],[]) <$> charsInTags "hask" _ -> B.rawInline "html" . snd <$> htmlTag (~== tag) |