From 48b23d491d0b4d98792fc9e5b90ea0059ef43076 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 28 Mar 2013 10:47:27 -0700 Subject: MediaWiki reader: Correctly handle indented preformatted text without preceding or following blank line. --- src/Text/Pandoc/Readers/MediaWiki.hs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 31d14117b..21b7363ff 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -50,7 +50,8 @@ import Control.Monad import Data.List (intersperse, intercalate, isPrefixOf ) import Text.HTML.TagSoup import Data.Sequence (viewl, ViewL(..), (<|)) -import Data.Char (isDigit) +import qualified Data.Foldable as F +import Data.Char (isDigit, isSpace) -- | Read mediawiki from an input string and return a Pandoc document. readMediaWiki :: ReaderOptions -- ^ Reader options @@ -175,7 +176,11 @@ block = mempty <$ skipMany1 blankline <|> para para :: MWParser Blocks -para = B.para . trimInlines . mconcat <$> many1 inline +para = do + contents <- trimInlines . mconcat <$> many1 inline + if F.all (==Space) contents + then return mempty + else return $ B.para contents table :: MWParser Blocks table = do @@ -330,10 +335,16 @@ preformatted = try $ do lines . fromEntities . map spToNbsp <$> try (htmlTag (~== TagOpen "nowiki" []) *> manyTill anyChar (htmlTag (~== TagClose "nowiki"))) - let inline' = whitespace' <|> endline' <|> nowiki' <|> inline + let inline' = whitespace' <|> endline' <|> nowiki' + <|> (notFollowedBy newline *> inline) let strToCode (Str s) = Code ("",[],[]) s strToCode x = x - B.para . bottomUp strToCode . mconcat <$> many1 inline' + contents <- mconcat <$> many1 inline' + let spacesStr (Str xs) = all isSpace xs + spacesStr _ = False + if F.all spacesStr contents + then return mempty + else return $ B.para $ bottomUp strToCode contents header :: MWParser Blocks header = try $ do @@ -504,7 +515,8 @@ whitespace = B.space <$ (skipMany1 spaceChar <|> endline <|> htmlComment) endline :: MWParser () endline = () <$ try (newline <* - notFollowedBy blankline <* + notFollowedBy spaceChar <* + notFollowedBy newline <* notFollowedBy' hrule <* notFollowedBy tableStart <* notFollowedBy' header <* -- cgit v1.2.3