git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki reader: Improvements to list parsing and HTML tag handling.
commit4e294333b0ddca9d2ee6de408239de4ccf8eb637 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 12 Sep 2012, 17:15 (14 years ago) parentbf26663
1 file changed+16−2
src/Text/Pandoc/Readers/MediaWiki.hs+16−2
src/Text/Pandoc/Readers/MediaWiki.hs+16−2
@@ -34,7 +34,6 @@ _ tests for lists
3434_ support HTML lists
3535_ support list style attributes and start values in ol lists, also
3636 value attribute on li
37−_ support <p> tags in lists (and out?)
3837_ support :, ::, etc. for indent (treat as list continuation paras?)
3938_ support preformatted text (lines starting with space)
4039_ support preformatted text blocks
@@ -69,10 +68,12 @@ import Text.Pandoc.XML ( fromEntities )
6968import Text.Pandoc.Parsing
7069import Text.Pandoc.Shared ( stripTrailingNewlines )
7170import Data.Monoid (mconcat, mempty)
71+import qualified Data.Foldable as F
7272import Control.Applicative ((<$>), (<*), (*>), (<$))
7373import Control.Monad
7474import Data.List (intersperse)
7575import Text.HTML.TagSoup
76+import Data.Sequence (viewl, ViewL(..), (<|))
7677
7778-- | Read mediawiki from an input string and return a Pandoc document.
7879readMediaWiki :: ReaderOptions -- ^ Reader options
@@ -140,11 +141,20 @@ block = header
140141 <|> haskell
141142 <|> mempty <$ skipMany1 blankline
142143 <|> mempty <$ try (spaces *> htmlComment)
144+ <|> pTag
145+ <|> blockHtml
143146 <|> para
144147
145148para :: MWParser Blocks
146149para = B.para . trimInlines . mconcat <$> many1 inline
147150
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+
148158hrule :: MWParser Blocks
149159hrule = B.horizontalRule <$ try (string "----" *> many (char '-') *> newline)
150160
@@ -223,7 +233,11 @@ listItem' c = try $ do
223233 first <- manyTill anyChar newline
224234 rest <- many (try $ char c *> lookAhead listStartChar *>
225235 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
227241
228242--
229243-- inline parsers