@@ -38,16 +38,13 @@ import Data.Text (Text, unpack)
38import Text.Pandoc.Class (PandocMonad)
38import Text.Pandoc.Class (PandocMonad)
39import Text.Pandoc.Definition
39import Text.Pandoc.Definition
40import Text.Pandoc.Options
40import Text.Pandoc.Options
42-- | Parse a CommonMark formatted string into a 'Pandoc' structure.
42-- | Parse a CommonMark formatted string into a 'Pandoc' structure.
43readGFM :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
43readGFM :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
44readGFM opts s = return $
44readGFM opts s = return $
45− nodeToPandoc $ commonmarkToNode opts' exts s
45+ nodeToPandoc $ traceShowId $ commonmarkToNode opts' exts s
46 where opts' = [optSmart | enabled Ext_smart]
46 where opts' = [optSmart | enabled Ext_smart]
47− exts = [extStrikethrough | enabled Ext_strikeout] ++
47+ exts = [extStrikethrough, extTable, extAutolink]
48− [extTable | enabled Ext_pipe_tables] ++
49− [extAutolink | enabled Ext_autolink_bare_uris]
50− -- extTagfilter: no pandoc extension for this
51 enabled x = extensionEnabled x (readerExtensions opts)
48 enabled x = extensionEnabled x (readerExtensions opts)
53nodeToPandoc :: Node -> Pandoc
50nodeToPandoc :: Node -> Pandoc
@@ -91,7 +88,31 @@ addBlock (Node _ (LIST listAttrs) nodes) =
91 delim = case listDelim listAttrs of
88 delim = case listDelim listAttrs of
92 PERIOD_DELIM -> Period
89 PERIOD_DELIM -> Period
93 PAREN_DELIM -> OneParen
90 PAREN_DELIM -> OneParen
94−addBlock (Node _ ITEM _) = id -- handled in LIST
91+addBlock (Node _ (TABLE alignments) nodes) = do
92+ (Table [] aligns widths headers rows :)
93+ where aligns = map fromTableCellAlignment alignments
94+ fromTableCellAlignment None = AlignDefault
95+ fromTableCellAlignment CMarkGFM.Left = AlignLeft
96+ fromTableCellAlignment CMarkGFM.Right = AlignRight
97+ fromTableCellAlignment Center = AlignCenter
98+ widths = replicate numcols 0.0
99+ numcols = if null rows'
101+ else maximum $ map length rows'
102+ rows' = map toRow $ filter isRow nodes
103+ (headers, rows) = case rows' of
106+ isRow (Node _ TABLE_ROW _) = True
108+ isCell (Node _ TABLE_CELL _) = True
110+ toRow (Node _ TABLE_ROW ns) = map toCell $ filter isCell ns
111+ toRow (Node _ t _) = error $ "toRow encountered non-row " ++ show t
112+ toCell (Node _ TABLE_CELL ns) = addBlocks ns
113+ toCell (Node _ t _) = error $ "toCell encountered non-cell " ++ show t
114+addBlock (Node _ TABLE_ROW _) = id -- handled in TABLE
115+addBlock (Node _ TABLE_CELL _) = id -- handled in TABLE
95addBlock _ = id
116addBlock _ = id
97children :: Node -> [Node]
118children :: Node -> [Node]
@@ -124,6 +145,8 @@ addInline (Node _ EMPH nodes) =
124 (Emph (addInlines nodes) :)
145 (Emph (addInlines nodes) :)
125addInline (Node _ STRONG nodes) =
146addInline (Node _ STRONG nodes) =
126 (Strong (addInlines nodes) :)
147 (Strong (addInlines nodes) :)
148+addInline (Node _ STRIKETHROUGH nodes) =
149+ (Strikeout (addInlines nodes) :)
127addInline (Node _ (LINK url title) nodes) =
150addInline (Node _ (LINK url title) nodes) =
128 (Link nullAttr (addInlines nodes) (unpack url, unpack title) :)
151 (Link nullAttr (addInlines nodes) (unpack url, unpack title) :)
129addInline (Node _ (IMAGE url title) nodes) =
152addInline (Node _ (IMAGE url title) nodes) =