From 0bd5830ad4cbf056d18595208532082fe674c6d2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 16 Jul 2013 15:37:15 -0700 Subject: 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. --- src/Text/Pandoc/Readers/HTML.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index f6657a4d1..56d35160c 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -88,7 +88,7 @@ block = choice , pCodeBlock , pList , pHrule - , pSimpleTable + , pTable , pHead , pBody , pPlain @@ -212,8 +212,8 @@ pHrule = do pSelfClosing (=="hr") (const True) return [HorizontalRule] -pSimpleTable :: TagParser [Block] -pSimpleTable = try $ do +pTable :: TagParser [Block] +pTable = try $ do TagOpen _ _ <- pSatisfy (~== TagOpen "table" []) skipMany pBlank caption <- option [] $ pInTags "caption" inline >>~ skipMany pBlank @@ -225,6 +225,11 @@ pSimpleTable = try $ do $ many1 $ try $ skipMany pBlank >> pInTags "tr" (pCell "td") skipMany pBlank TagClose _ <- pSatisfy (~== TagClose "table") + let isSinglePlain [] = True + isSinglePlain [Plain _] = True + isSinglePlain _ = False + let isSimple = all isSinglePlain $ concat (head':rows) + guard isSimple let cols = maximum $ map length rows let aligns = replicate cols AlignLeft let widths = replicate cols 0 @@ -233,7 +238,7 @@ pSimpleTable = try $ do pCell :: String -> TagParser [TableCell] pCell celltype = try $ do skipMany pBlank - res <- pInTags celltype pPlain + res <- pInTags celltype block skipMany pBlank return [res] -- cgit v1.2.3