git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Generalized table parser.

This commit doesn't change the present behavior at all, but it will make it easier to support non-simple tables in the future.

commit0bd5830ad4cbf056d18595208532082fe674c6d2 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 16 Jul 2013, 15:37 (13 years ago) parent595149a
1 file changed+9−4
src/Text/Pandoc/Readers/HTML.hs+9−4
src/Text/Pandoc/Readers/HTML.hs+9−4
@@ -88,7 +88,7 @@ block = choice
8888 , pCodeBlock
8989 , pList
9090 , pHrule
91− , pSimpleTable
91+ , pTable
9292 , pHead
9393 , pBody
9494 , pPlain
@@ -212,8 +212,8 @@ pHrule = do
212212 pSelfClosing (=="hr") (const True)
213213 return [HorizontalRule]
214214
215−pSimpleTable :: TagParser [Block]
216−pSimpleTable = try $ do
215+pTable :: TagParser [Block]
216+pTable = try $ do
217217 TagOpen _ _ <- pSatisfy (~== TagOpen "table" [])
218218 skipMany pBlank
219219 caption <- option [] $ pInTags "caption" inline >>~ skipMany pBlank
@@ -225,6 +225,11 @@ pSimpleTable = try $ do
225225 $ many1 $ try $ skipMany pBlank >> pInTags "tr" (pCell "td")
226226 skipMany pBlank
227227 TagClose _ <- pSatisfy (~== TagClose "table")
228+ let isSinglePlain [] = True
229+ isSinglePlain [Plain _] = True
230+ isSinglePlain _ = False
231+ let isSimple = all isSinglePlain $ concat (head':rows)
232+ guard isSimple
228233 let cols = maximum $ map length rows
229234 let aligns = replicate cols AlignLeft
230235 let widths = replicate cols 0
@@ -233,7 +238,7 @@ pSimpleTable = try $ do
233238pCell :: String -> TagParser [TableCell]
234239pCell celltype = try $ do
235240 skipMany pBlank
236− res <- pInTags celltype pPlain
241+ res <- pInTags celltype block
237242 skipMany pBlank
238243 return [res]
239244