From 124679fd63564d434e2f90616be1c6daebaa22f9 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 6 Aug 2016 23:41:03 +0200 Subject: 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. --- src/Text/Pandoc/Readers/MediaWiki.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/Text/Pandoc/Readers') 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) -- cgit v1.2.3