aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-07-16 15:37:15 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2013-07-16 15:37:15 -0700
commit0bd5830ad4cbf056d18595208532082fe674c6d2 (patch)
treec28e8e8098b7a3346615e8aeefab22b437e864d1 /src/Text
parent595149a9bcb12aa832065f591058ab963c9f237e (diff)
downloadpandoc-0bd5830ad4cbf056d18595208532082fe674c6d2.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs13
1 files changed, 9 insertions, 4 deletions
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]