git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Improvements to list parsing and HTML tag handling.
4e29433John MacFarlane
src/Text/Pandoc/Readers/MediaWiki.hs+16−2
@@ -34,7 +34,6 @@ _ tests for lists
34_ support HTML lists
34_ support HTML lists
35_ support list style attributes and start values in ol lists, also
35_ support list style attributes and start values in ol lists, also
36 value attribute on li
36 value attribute on li
37−_ support <p> tags in lists (and out?)
38_ support :, ::, etc. for indent (treat as list continuation paras?)
37_ support :, ::, etc. for indent (treat as list continuation paras?)
39_ support preformatted text (lines starting with space)
38_ support preformatted text (lines starting with space)
40_ support preformatted text blocks
39_ support preformatted text blocks
@@ -69,10 +68,12 @@ import Text.Pandoc.XML ( fromEntities )
69import Text.Pandoc.Parsing
68import Text.Pandoc.Parsing
70import Text.Pandoc.Shared ( stripTrailingNewlines )
69import Text.Pandoc.Shared ( stripTrailingNewlines )
71import Data.Monoid (mconcat, mempty)
70import Data.Monoid (mconcat, mempty)
71+import qualified Data.Foldable as F
72import Control.Applicative ((<$>), (<*), (*>), (<$))
72import Control.Applicative ((<$>), (<*), (*>), (<$))
73import Control.Monad
73import Control.Monad
74import Data.List (intersperse)
74import Data.List (intersperse)
75import Text.HTML.TagSoup
75import Text.HTML.TagSoup
76+import Data.Sequence (viewl, ViewL(..), (<|))
76
77
77-- | Read mediawiki from an input string and return a Pandoc document.
78-- | Read mediawiki from an input string and return a Pandoc document.
78readMediaWiki :: ReaderOptions -- ^ Reader options
79readMediaWiki :: ReaderOptions -- ^ Reader options
@@ -140,11 +141,20 @@ block = header
140 <|> haskell
141 <|> haskell
141 <|> mempty <$ skipMany1 blankline
142 <|> mempty <$ skipMany1 blankline
142 <|> mempty <$ try (spaces *> htmlComment)
143 <|> mempty <$ try (spaces *> htmlComment)
144+ <|> pTag
145+ <|> blockHtml
143 <|> para
146 <|> para
144
147
145para :: MWParser Blocks
148para :: MWParser Blocks
146para = B.para . trimInlines . mconcat <$> many1 inline
149para = B.para . trimInlines . mconcat <$> many1 inline
147
150
151+-- We can just skip pTags, as contents will be treated as paragraphs
152+pTag :: MWParser Blocks
153+pTag = mempty <$ (htmlTag (\t -> t ~== TagOpen "p" [] || t ~== TagClose "p"))
154+
155+blockHtml :: MWParser Blocks
156+blockHtml = (B.rawBlock "html" . snd <$> htmlTag isBlockTag)
157+
148hrule :: MWParser Blocks
158hrule :: MWParser Blocks
149hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
159hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
150
160
@@ -223,7 +233,11 @@ listItem' c = try $ do
223 first <- manyTill anyChar newline
233 first <- manyTill anyChar newline
224 rest <- many (try $ char c *> lookAhead listStartChar *>
234 rest <- many (try $ char c *> lookAhead listStartChar *>
225 manyTill anyChar newline)
235 manyTill anyChar newline)
226− parseFromString (mconcat <$> many1 block) $ unlines $ first : rest
236+ contents <- parseFromString (mconcat <$> many1 block)
237+ $ unlines $ first : rest
238+ case viewl (B.unMany contents) of
239+ (Para xs) :< rest -> return $ B.Many $ (Plain xs) <| rest
240+ _ -> return contents
227
241
228--
242--
229-- inline parsers
243-- inline parsers