aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs11
-rw-r--r--test/command/tasklist.md8
2 files changed, 14 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index dd8b7d6f7..4d8a6b961 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -370,6 +370,13 @@ defList :: PandocMonad m
=> WriterOptions -> [Html] -> StateT WriterState m Html
defList opts items = toList H.dl opts (items ++ [nl opts])
+isTaskListItem :: [Block] -> Bool
+isTaskListItem (Plain (Str "☐":Space:_):_) = True
+isTaskListItem (Plain (Str "☒":Space:_):_) = True
+isTaskListItem (Para (Str "☐":Space:_):_) = True
+isTaskListItem (Para (Str "☒":Space:_):_) = True
+isTaskListItem _ = False
+
listItemToHtml :: PandocMonad m
=> WriterOptions -> [Block] -> StateT WriterState m Html
listItemToHtml opts bls
@@ -819,7 +826,9 @@ blockToHtml opts (Header level attr@(_,classes,_) lst) = do
_ -> H.p ! A.class_ "heading" $ contents'
blockToHtml opts (BulletList lst) = do
contents <- mapM (listItemToHtml opts) lst
- unordList opts contents
+ let isTaskList = not (null lst) && all isTaskListItem lst
+ (if isTaskList then (! A.class_ "task-list") else id) <$>
+ unordList opts contents
blockToHtml opts (OrderedList (startnum, numstyle, _) lst) = do
contents <- mapM (listItemToHtml opts) lst
html5 <- gets stHtml5
diff --git a/test/command/tasklist.md b/test/command/tasklist.md
index 5ff628e1c..2f648d187 100644
--- a/test/command/tasklist.md
+++ b/test/command/tasklist.md
@@ -5,7 +5,7 @@ tests adapted from <https://github.github.com/gfm/#task-list-items-extension->
- [ ] foo
- [x] bar
^D
-<ul>
+<ul class="task-list">
<li><input type="checkbox" disabled="" />
foo</li>
<li><input type="checkbox" disabled="" checked="" />
@@ -21,9 +21,9 @@ bar</li>
- [x] baz
- [ ] bim
^D
-<ul>
+<ul class="task-list">
<li><input type="checkbox" disabled="" checked="" />
-foo<ul>
+foo<ul class="task-list">
<li><input type="checkbox" disabled="" />
bar</li>
<li><input type="checkbox" disabled="" checked="" />
@@ -73,7 +73,7 @@ ordered unchecked</li>
ordered checked</li>
</ol>
<p>paragraph</p>
-<ul>
+<ul class="task-list">
<li><p><input type="checkbox" disabled="" />
list item with a</p><p>second paragraph</p></li>
<li><p><input type="checkbox" disabled="" checked="" />