aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/CommonMark.hs
diff options
context:
space:
mode:
authordespresc <christian.j.j.despres@gmail.com>2020-03-28 18:22:48 -0400
committerdespresc <christian.j.j.despres@gmail.com>2020-04-15 23:03:22 -0400
commit7254a2ae0ba40b29c04b8924f27739614229432b (patch)
tree114e3143953451e3212511e7bf2e178548d3e1bd /src/Text/Pandoc/Readers/CommonMark.hs
parent83c1ce1d77d3ef058e4e5c645a8eb0379fab780f (diff)
downloadpandoc-7254a2ae0ba40b29c04b8924f27739614229432b.tar.gz
Implement the new Table type
Diffstat (limited to 'src/Text/Pandoc/Readers/CommonMark.hs')
-rw-r--r--src/Text/Pandoc/Readers/CommonMark.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs
index 67853aef7..33afbe59f 100644
--- a/src/Text/Pandoc/Readers/CommonMark.hs
+++ b/src/Text/Pandoc/Readers/CommonMark.hs
@@ -111,31 +111,33 @@ addBlock opts (Node _ (LIST listAttrs) nodes) =
PAREN_DELIM -> OneParen
exts = readerExtensions opts
addBlock opts (Node _ (TABLE alignments) nodes) =
- (Table [] aligns widths headers rows :)
+ (Table nullAttr (Caption Nothing []) (zip aligns widths) 0 headers rows [] :)
where aligns = map fromTableCellAlignment alignments
fromTableCellAlignment NoAlignment = AlignDefault
fromTableCellAlignment LeftAligned = AlignLeft
fromTableCellAlignment RightAligned = AlignRight
fromTableCellAlignment CenterAligned = AlignCenter
- widths = replicate numcols 0.0
+ widths = replicate numcols Nothing
numcols = if null rows'
then 0
- else maximum $ map length rows'
+ else maximum $ map rowLength rows'
rows' = map toRow $ filter isRow nodes
(headers, rows) = case rows' of
- (h:rs) -> (h, rs)
+ (h:rs) -> ([h], rs)
[] -> ([], [])
isRow (Node _ TABLE_ROW _) = True
isRow _ = False
isCell (Node _ TABLE_CELL _) = True
isCell _ = False
- toRow (Node _ TABLE_ROW ns) = map toCell $ filter isCell ns
+ toRow (Node _ TABLE_ROW ns) = Row nullAttr $ map toCell $ filter isCell ns
toRow (Node _ t _) = error $ "toRow encountered non-row " ++ show t
- toCell (Node _ TABLE_CELL []) = []
+ toCell (Node _ TABLE_CELL []) = fromSimpleCell []
toCell (Node _ TABLE_CELL (n:ns))
- | isBlockNode n = addBlocks opts (n:ns)
- | otherwise = [Plain (addInlines opts (n:ns))]
+ | isBlockNode n = fromSimpleCell $ addBlocks opts (n:ns)
+ | otherwise = fromSimpleCell [Plain (addInlines opts (n:ns))]
toCell (Node _ t _) = error $ "toCell encountered non-cell " ++ show t
+ fromSimpleCell = Cell nullAttr Nothing 1 1
+ rowLength (Row _ body) = length body -- all cells are 1×1
addBlock _ (Node _ TABLE_ROW _) = id -- handled in TABLE
addBlock _ (Node _ TABLE_CELL _) = id -- handled in TABLE
addBlock _ _ = id