From cd5c1a47a8672c01d21b796672160fe558601fc2 Mon Sep 17 00:00:00 2001 From: gillchristian Date: Thu, 14 Nov 2019 20:36:57 +0100 Subject: [PATCH 1/2] feat(extensions): Add support for task list extension The Task List extension allows to render checkboxes in lists items https://github.github.com/gfm/#task-list-items-extension- --- CMarkGFM.hsc | 4 ++++ test/test-cmark.hs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/CMarkGFM.hsc b/CMarkGFM.hsc index 5478c84..70cc648 100644 --- a/CMarkGFM.hsc +++ b/CMarkGFM.hsc @@ -21,6 +21,7 @@ module CMarkGFM ( , extTable , extAutolink , extTagfilter + , extTaskList , Node(..) , NodeType(..) , PosInfo(..) @@ -302,6 +303,9 @@ extAutolink = CMarkExtension "autolink" extTagfilter :: CMarkExtension extTagfilter = CMarkExtension "tagfilter" +extTaskList :: CMarkExtension +extTaskList = CMarkExtension "tasklist" + ptrToNodeType :: NodePtr -> IO NodeType ptrToNodeType ptr = do nodeType <- c_cmark_node_get_type ptr diff --git a/test/test-cmark.hs b/test/test-cmark.hs index 53190ad..000b73a 100644 --- a/test/test-cmark.hs +++ b/test/test-cmark.hs @@ -32,4 +32,6 @@ tests = TestList [ , Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 3, endColumn = 17})) DOCUMENT [Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 3, endColumn = 17})) (TABLE [LeftAligned,CenterAligned,NoAlignment,RightAligned]) [Node (Just (PosInfo {startLine = 1, startColumn = 1, endLine = 1, endColumn = 17})) TABLE_ROW [Node (Just (PosInfo {startLine = 1, startColumn = 2, endLine = 1, endColumn = 4})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 3, endLine = 1, endColumn = 3})) (TEXT "a") []],Node (Just (PosInfo {startLine = 1, startColumn = 6, endLine = 1, endColumn = 8})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 7, endLine = 1, endColumn = 7})) (TEXT "b") []],Node (Just (PosInfo {startLine = 1, startColumn = 10, endLine = 1, endColumn = 12})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 11, endLine = 1, endColumn = 11})) (TEXT "c") []],Node (Just (PosInfo {startLine = 1, startColumn = 14, endLine = 1, endColumn = 16})) TABLE_CELL [Node (Just (PosInfo {startLine = 1, startColumn = 15, endLine = 1, endColumn = 15})) (TEXT "d") []]],Node (Just (PosInfo {startLine = 3, startColumn = 1, endLine = 3, endColumn = 17})) TABLE_ROW [Node (Just (PosInfo {startLine = 3, startColumn = 2, endLine = 3, endColumn = 4})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 3, endLine = 3, endColumn = 3})) (TEXT "y") []],Node (Just (PosInfo {startLine = 3, startColumn = 6, endLine = 3, endColumn = 8})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 7, endLine = 3, endColumn = 7})) (TEXT "o") []],Node (Just (PosInfo {startLine = 3, startColumn = 10, endLine = 3, endColumn = 12})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 11, endLine = 3, endColumn = 11})) (TEXT "s") []],Node (Just (PosInfo {startLine = 3, startColumn = 14, endLine = 3, endColumn = 16})) TABLE_CELL [Node (Just (PosInfo {startLine = 3, startColumn = 15, endLine = 3, endColumn = 15})) (TEXT "h") []]]]] ~=? commonmarkToNode [] [extTable] "| a | b | c | d |\n| :-- | :-: | --- | --: |\n| y | o | s | h |" , "\n" ~=? commonmarkToHtml [optUnsafe] [] "<xmp>" , "&lt;xmp>\n" ~=? commonmarkToHtml [optUnsafe] [extTagfilter] "<xmp>" + , "<ul>\n<li><input type=\"checkbox\" disabled=\"\" /> foo</li>\n<li><input type=\"checkbox\" checked=\"\" disabled=\"\" /> bar</li>\n</ul>\n" ~=? commonmarkToHtml [] [extTaskList] "- [ ] foo\n- [x] bar" ] + From 0a11435b59047cfd3bfa005640812842367ccafa Mon Sep 17 00:00:00 2001 From: gillchristian <gillchristiang@gmail.com> Date: Thu, 14 Nov 2019 20:51:25 +0100 Subject: [PATCH 2/2] chore(bech): Add task list cases to bech/full-sample.md --- bench/full-sample.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bench/full-sample.md b/bench/full-sample.md index a138d1a..3c5a14b 100644 --- a/bench/full-sample.md +++ b/bench/full-sample.md @@ -499,6 +499,21 @@ of a list item - - - - - - - - - deeply-nested one-element item +- [ ] a task list +- [x] a check item in the task list + +- [ ] loose task list item + +- [x] loose checked task list item + +- [ ] nested items in the task list + - [ ] nested item 1 + - [x] checked nested item 2 + - [ ] must go deeper + - [x] checked deeper nested item 2 + - [ ] must go even deeper + - [x] checked even deeper nested item 2 + [1] [2] [3] [1] [2] [3] [looooooooooooooooooooooooooooooooooooooooooooooooooong label]