diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-03-28 10:47:27 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-03-28 10:48:00 -0700 |
commit | 48b23d491d0b4d98792fc9e5b90ea0059ef43076 (patch) | |
tree | 0269599235330d1731c27d00f09de4ea4c74e58c /src/Text/Pandoc/Readers | |
parent | 099b4b776985e23bffb06b3dca3a697d3fde2a41 (diff) | |
download | pandoc-48b23d491d0b4d98792fc9e5b90ea0059ef43076.tar.gz |
MediaWiki reader: Correctly handle indented preformatted text
without preceding or following blank line.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 22 |
1 files changed, 17 insertions, 5 deletions
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 <* |