Repository: executablebooks/MyST-Parser
Pull request #686 (2023-01-15 11:25:50)

👌 Add `myst_enable_checkboxes` config
@asmeurer is this what you are after?

codecov[bot]: # [Codecov](https://codecov.io/gh/executablebooks/MyST-Parser/pull/686?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) Report
Base: **90.17**% // Head: **90.18**% // Increases project coverage by **`+0.00%`** :tada:
> Coverage data is based on head [(`c66fb7d`)](https://codecov.io/gh/executablebooks/MyST-Parser/pull/686?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) compared to base [(`9d1869d`)](https://codecov.io/gh/executablebooks/MyST-Parser/commit/9d1869d56eedebd4b73975af412944a2bdcd8544?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #686   +/-   ##
=======================================
  Coverage   90.17%   90.18%           
=======================================
  Files          23       23           
  Lines        2586     2587    +1     
=======================================
+ Hits         2332     2333    +1     
  Misses        254      254           
```

| Flag | Coverage Δ | |
|---|---|---|
| pytests | `90.18% <100.00%> (+<0.01%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/executablebooks/MyST-Parser/pull/686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) | Coverage Δ | |
|---|---|---|
| [myst\_parser/parsers/mdit.py](https://codecov.io/gh/executablebooks/MyST-Parser/pull/686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#diff-bXlzdF9wYXJzZXIvcGFyc2Vycy9tZGl0LnB5) | `95.45% <ø> (ø)` | |
| [myst\_parser/config/main.py](https://codecov.io/gh/executablebooks/MyST-Parser/pull/686?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#diff-bXlzdF9wYXJzZXIvY29uZmlnL21haW4ucHk=) | `88.52% <100.00%> (+0.09%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/executablebooks/MyST-Parser/pull/686?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).

chrisjsewell: hmm not working yet
asmeurer: Yes, this works. This is much better than the manual `<li><input type="checkbox">` I was doing previously.

I would still like the other point in the issue (about removing the bullets from the checkboxes), but I can workaround that with some custom CSS for now. 

Patch:
diff --git a/docs/conf.py b/docs/conf.py
index 30c22e2..0bcab59 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -106,6 +106,7 @@ myst_number_code_blocks = ["typescript"]
 myst_heading_anchors = 2
 myst_footnote_transition = True
 myst_dmath_double_inline = True
+myst_enable_checkboxes = True
 
 # -- HTML output -------------------------------------------------
 
diff --git a/myst_parser/config/main.py b/myst_parser/config/main.py
index 7acc3c5..98ed71c 100644
--- a/myst_parser/config/main.py
+++ b/myst_parser/config/main.py
@@ -300,6 +300,15 @@ class MdParserConfig:
         },
     )
 
+    enable_checkboxes: bool = dc.field(
+        default=False,
+        metadata={
+            "validator": instance_of(bool),
+            "help": "Enable checkboxes",
+            "extension": "tasklist",
+        },
+    )
+
     # docutils only (replicating aspects of sphinx config)
 
     suppress_warnings: Sequence[str] = dc.field(
diff --git a/myst_parser/parsers/mdit.py b/myst_parser/parsers/mdit.py
index dbb533d..73cd0b4 100644
--- a/myst_parser/parsers/mdit.py
+++ b/myst_parser/parsers/mdit.py
@@ -48,7 +48,7 @@ def create_md_parser(
             # note, strikethrough currently only supported tentatively for HTML
             .enable("strikethrough")
             .enable("table")
-            .use(tasklists_plugin)
+            .use(tasklists_plugin, enabled=config.enable_checkboxes)
             .enable("linkify")
             .use(wordcount_plugin, per_minute=config.words_per_minute)
         )
@@ -98,7 +98,7 @@ def create_md_parser(
     if "fieldlist" in config.enable_extensions:
         md.use(fieldlist_plugin)
     if "tasklist" in config.enable_extensions:
-        md.use(tasklists_plugin)
+        md.use(tasklists_plugin, enabled=config.enable_checkboxes)
     if "substitution" in config.enable_extensions:
         md.use(substitution_plugin, *config.sub_delimiters)
     if "attrs_inline" in config.enable_extensions:


Test patch:
diff --git a/tests/test_renderers/fixtures/myst-config.txt b/tests/test_renderers/fixtures/myst-config.txt
index 7f997e9..94aabb1 100644
--- a/tests/test_renderers/fixtures/myst-config.txt
+++ b/tests/test_renderers/fixtures/myst-config.txt
@@ -156,6 +156,25 @@ www.commonmark.org/he<lp
         <lp
 .
 
+[tasklist] --myst-enable-extensions=tasklist --myst-enable-checkboxes="true"
+.
+- [ ] a
+- [x] b
+.
+<document source="<string>">
+    <bullet_list bullet="-" classes="contains-task-list">
+        <list_item classes="task-list-item enabled">
+            <paragraph>
+                <raw format="html" xml:space="preserve">
+                    <input class="task-list-item-checkbox"  type="checkbox">
+                 a
+        <list_item classes="task-list-item enabled">
+            <paragraph>
+                <raw format="html" xml:space="preserve">
+                    <input class="task-list-item-checkbox" checked="checked"  type="checkbox">
+                 b
+.
+
 [heading_anchors] --myst-heading-anchors=1
 .
 # My title