@@ -46,7 +46,7 @@ import Data.Maybe (fromMaybe)
4646import GHC.Generics (Generic )
4747import Data.Data (Data )
4848import Data.Typeable (Typeable )
49- import Data.Text (Text , empty , snoc )
49+ import Data.Text (Text , empty , pack , snoc )
5050import qualified Data.Text.Foreign as TF
5151import Data.ByteString.Unsafe (unsafePackMallocCString )
5252import Data.Text.Encoding (decodeUtf8 )
@@ -239,6 +239,7 @@ data NodeType =
239239 | HEADING Level
240240 | LIST ListAttributes
241241 | ITEM
242+ | TASKLIST Bool
242243 | TEXT Text
243244 | SOFTBREAK
244245 | LINEBREAK
@@ -335,7 +336,11 @@ ptrToNodeType ptr = do
335336 # const CMARK_NODE_LIST
336337 -> LIST <$> listAttr
337338 # const CMARK_NODE_ITEM
338- -> return ITEM
339+ -> do
340+ ts <- typeString
341+ if ts == pack " tasklist"
342+ then TASKLIST <$> checked
343+ else return ITEM
339344 # const CMARK_NODE_HEADING
340345 -> HEADING <$> level
341346 # const CMARK_NODE_EMPH
@@ -372,7 +377,8 @@ ptrToNodeType ptr = do
372377 return TABLE_CELL
373378 else
374379 error $ " Unknown node type " ++ (show nodeType)
375- where literal = c_cmark_node_get_literal ptr >>= totext
380+ where typeString = c_cmark_node_get_type_string ptr >>= totext
381+ literal = c_cmark_node_get_literal ptr >>= totext
376382 level = c_cmark_node_get_heading_level ptr
377383 onEnter = c_cmark_node_get_on_enter ptr >>= totext
378384 onExit = c_cmark_node_get_on_exit ptr >>= totext
@@ -400,6 +406,7 @@ ptrToNodeType ptr = do
400406 ncols <- c_cmark_gfm_extensions_get_table_columns ptr
401407 cols <- c_cmark_gfm_extensions_get_table_alignments ptr
402408 mapM (fmap ucharToAlignment . peekElemOff cols) [0 .. (fromIntegral ncols) - 1 ]
409+ checked = c_cmark_gfm_extensions_get_tasklist_item_checked ptr
403410 ucharToAlignment (CUChar 108 ) = LeftAligned
404411 ucharToAlignment (CUChar 99 ) = CenterAligned
405412 ucharToAlignment (CUChar 114 ) = RightAligned
@@ -464,7 +471,13 @@ fromNode (Node _ nodeType children) = do
464471 c_cmark_node_set_list_tight n $ listTight attr
465472 c_cmark_node_set_list_start n $ listStart attr
466473 return n
467- ITEM -> c_cmark_node_new (# const CMARK_NODE_ITEM )
474+ ITEM -> c_cmark_node_new (# const CMARK_NODE_ITEM )
475+ TASKLIST checked -> do
476+ n <- c_cmark_node_new (# const CMARK_NODE_ITEM )
477+ tasklistExt <- withCString (unCMarkExtension extTaskList) c_cmark_find_syntax_extension
478+ c_cmark_node_set_syntax_extension n tasklistExt
479+ c_cmark_gfm_extensions_set_tasklist_item_checked n checked
480+ return n
468481 HEADING lev -> do
469482 n <- c_cmark_node_new (# const CMARK_NODE_HEADING )
470483 c_cmark_node_set_heading_level n lev
@@ -555,6 +568,9 @@ foreign import ccall "cmark-gfm.h cmark_parser_free"
555568foreign import ccall " cmark-gfm.h cmark_node_get_type"
556569 c_cmark_node_get_type :: NodePtr -> IO Int
557570
571+ foreign import ccall " cmark-gfm.h cmark_node_get_type_string"
572+ c_cmark_node_get_type_string :: NodePtr -> IO CString
573+
558574foreign import ccall " cmark-gfm.h cmark_node_first_child"
559575 c_cmark_node_first_child :: NodePtr -> IO NodePtr
560576
@@ -680,3 +696,12 @@ foreign import ccall "cmark-gfm-core-extensions.h cmark_gfm_extensions_get_table
680696
681697foreign import ccall " cmark-gfm-core-extensions.h cmark_gfm_extensions_get_table_alignments"
682698 c_cmark_gfm_extensions_get_table_alignments :: NodePtr -> IO (Ptr CUChar )
699+
700+ foreign import ccall " cmark-gfm-core-extensions.h cmark_node_set_syntax_extension"
701+ c_cmark_node_set_syntax_extension :: NodePtr -> ExtensionPtr -> IO Int
702+
703+ foreign import ccall " cmark-gfm-core-extensions.h cmark_gfm_extensions_set_tasklist_item_checked"
704+ c_cmark_gfm_extensions_set_tasklist_item_checked :: NodePtr -> Bool -> IO Int
705+
706+ foreign import ccall " cmark-gfm-core-extensions.h cmark_gfm_extensions_get_tasklist_item_checked"
707+ c_cmark_gfm_extensions_get_tasklist_item_checked :: NodePtr -> IO Bool
0 commit comments