Welcome to little lamb

Code » qmdoc » commit 0d1937e

Add support for task-lists extension

author Olivier Brunel
2023-01-12 19:53:27 UTC
committer Olivier Brunel
2023-01-12 19:53:27 UTC
parent 0bfd057854b7d906fd0dc47c887531edf85b98d2

Add support for task-lists extension

That is:

* [ ] to do
* [x] done

css/struct.css +6 -0
src/main.c +12 -3

diff --git a/css/struct.css b/css/struct.css
index be41e1b..2323206 100644
--- a/css/struct.css
+++ b/css/struct.css
@@ -186,6 +186,12 @@ main u {
 main s {
     text-decoration: line-through;
 }
+main li.taskOff::marker {
+    content: "☐ ";
+}
+main li.taskOn::marker {
+    content: "☒ ";
+}
 main pre, main code, main kbd {
     font-family: Monaco,Consolas,Liberation Mono,Courier,monospace;
     white-space: pre;
diff --git a/src/main.c b/src/main.c
index cff4944..bee289f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -510,8 +510,17 @@ enter_block(MD_BLOCKTYPE type, void *details, void *ctx_)
             break;
 
         case MD_BLOCK_LI:
-            if (!raw_str(ctx, "<li>"))
-                return ERR_PARSER_ENTER_BLOCK;
+            {
+                MD_BLOCK_LI_DETAIL *d = details;
+                if (!raw_str(ctx, "<li")
+                        || (d->is_task &&
+                            (!raw_str(ctx, " class=\"task")
+                             || !raw_str(ctx, (d->task_mark == ' ') ? "Off" : "On")
+                             || !raw_str(ctx, "\"")
+                            ))
+                        || !raw_str(ctx, ">"))
+                    return ERR_PARSER_ENTER_BLOCK;
+            }
             break;
 
         case MD_BLOCK_HR:
@@ -1200,7 +1209,7 @@ convert_page(struct ctx *ctx, int fddest)
     const MD_PARSER parser = {
         .flags = MD_FLAG_COLLAPSEWHITESPACE | MD_FLAG_PERMISSIVEAUTOLINKS
             | MD_FLAG_NOHTMLBLOCKS | MD_FLAG_STRIKETHROUGH | MD_FLAG_UNDERLINE
-            | MD_FLAG_WIKILINKS
+            | MD_FLAG_WIKILINKS | MD_FLAG_TASKLISTS
             | MD_FLAG_ITALIC | MD_FLAG_BOLD | MD_FLAG_BOX | MD_FLAG_HIGHLIGHT
             | MD_FLAG_INDENT,
         .enter_block = enter_block,