git.iko.soy/typeable/pandoc
on master help sign in
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.

commit124679fd63564d434e2f90616be1c6daebaa22f9 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 6 Aug 2016, 23:41 (10 years ago) parent3a49439
1 file changed+13−7
src/Text/Pandoc/Readers/MediaWiki.hs+13−7
src/Text/Pandoc/Readers/MediaWiki.hs+13−7
@@ -376,11 +376,17 @@ preformatted = try $ do
376376 spacesStr _ = False
377377 if F.all spacesStr contents
378378 then return mempty
379− else return $ B.para $ walk strToCode contents
380−
381−strToCode :: Inline -> Inline
382−strToCode (Str s) = Code ("",[],[]) s
383−strToCode x = x
379+ else return $ B.para $ encode contents
380+
381+encode :: Inlines -> Inlines
382+encode = B.fromList . normalizeCode . B.toList . walk strToCode
383+ where strToCode (Str s) = Code ("",[],[]) s
384+ strToCode Space = Code ("",[],[]) " "
385+ strToCode x = x
386+ normalizeCode [] = []
387+ normalizeCode (Code a1 x : Code a2 y : zs) | a1 == a2 =
388+ normalizeCode $ (Code a1 (x ++ y)) : zs
389+ normalizeCode (x:xs) = x : normalizeCode xs
384390
385391header :: MWParser Blocks
386392header = try $ do
@@ -545,8 +551,8 @@ inlineTag = do
545551 TagOpen "del" _ -> B.strikeout <$> inlinesInTags "del"
546552 TagOpen "sub" _ -> B.subscript <$> inlinesInTags "sub"
547553 TagOpen "sup" _ -> B.superscript <$> inlinesInTags "sup"
548− TagOpen "code" _ -> walk strToCode <$> inlinesInTags "code"
549− TagOpen "tt" _ -> walk strToCode <$> inlinesInTags "tt"
554+ TagOpen "code" _ -> encode <$> inlinesInTags "code"
555+ TagOpen "tt" _ -> encode <$> inlinesInTags "tt"
550556 TagOpen "hask" _ -> B.codeWith ("",["haskell"],[]) <$> charsInTags "hask"
551557 _ -> B.rawInline "html" . snd <$> htmlTag (~== tag)
552558