git.iko.soy/typeable/pandoc
on master help sign in
Make HTML reader more forgiving of bad HTML.

* Skip spaces after <b>, <emph>, etc. * Convert Plain elements into Para when they're in a list item with Para, Pre, BlockQuote, CodeBlock. An example of HTML that pandoc handles better now: ~~~~ <h4> Testing html to markdown </h4> <ul> <li> <b> An item in a list </b> <p> An introductory sentence. <pre> Some preformatted text at this stage comes next. But alas! much havoc is wrought by Pandoc. </pre> </ul> ~~~~ Thanks to Dirk Laurie for reporting the issues.

commit4134dad500f6cb360a9ceb957e0c5ec2ec59b2a8 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 10 Jul 2011, 16:54 (15 years ago) parentb5411c0
1 file changed+16−4
src/Text/Pandoc/Readers/HTML.hs+16−4
src/Text/Pandoc/Readers/HTML.hs+16−4
@@ -107,7 +107,7 @@ pBulletList = try $ do
107107 -- treat it as a list item, though it's not valid xhtml...
108108 skipMany nonItem
109109 items <- manyTill (pInTags "li" block >>~ skipMany nonItem) (pCloses "ul")
110− return [BulletList items]
110+ return [BulletList $ map fixPlains items]
111111
112112pOrderedList :: TagParser [Block]
113113pOrderedList = try $ do
@@ -138,7 +138,7 @@ pOrderedList = try $ do
138138 -- treat it as a list item, though it's not valid xhtml...
139139 skipMany nonItem
140140 items <- manyTill (pInTags "li" block >>~ skipMany nonItem) (pCloses "ol")
141− return [OrderedList (start, style, DefaultDelim) items]
141+ return [OrderedList (start, style, DefaultDelim) $ map fixPlains items]
142142
143143pDefinitionList :: TagParser [Block]
144144pDefinitionList = try $ do
@@ -154,7 +154,19 @@ pDefListItem = try $ do
154154 defs <- many1 (try $ skipMany nonItem >> pInTags "dd" block)
155155 skipMany nonItem
156156 let term = intercalate [LineBreak] terms
157− return (term, defs)
157+ return (term, map fixPlains defs)
158+
159+fixPlains :: [Block] -> [Block]
160+fixPlains bs = if any isParaish bs
161+ then map plainToPara bs
162+ else bs
163+ where isParaish (Para _) = True
164+ isParaish (CodeBlock _ _) = True
165+ isParaish (Header _ _) = True
166+ isParaish (BlockQuote _) = True
167+ isParaish _ = False
168+ plainToPara (Plain xs) = Para xs
169+ plainToPara x = x
158170
159171pRawTag :: TagParser String
160172pRawTag = do
@@ -358,7 +370,7 @@ pInlinesInTags :: String -> ([Inline] -> Inline)
358370 -> TagParser [Inline]
359371pInlinesInTags tagtype f = do
360372 contents <- pInTags tagtype inline
361− return [f contents]
373+ return [f $ normalizeSpaces contents]
362374
363375pInTags :: String -> TagParser [a]
364376 -> TagParser [a]