Controlling GitHub Flavored Markdown Task Lists in Static‑Site Generators
Learn how to enable GitHub Flavored Markdown task lists only where you need them, preventing unwanted checkboxes in code examples and keeping your Markdown source clean.
29 Mar 2026, 00:46 UTC

Problem: Bracketed text turns into unwanted checkboxes
When you enable GitHub Flavored Markdown (GFM) task‑list support in a Markdown parser, every list item that begins with [ ] or [x] is rendered as a disabled checkbox. In documentation that contains code examples, citation markers, or placeholder text like [ ], this behavior creates visual noise and can break layout.
Thesis: Scope task‑list rendering to specific content
Instead of turning the feature on globally, you can configure the parser to add the contains-task-list class and disabled checkbox only when a front‑matter flag signals that the page should treat list items as task lists. This keeps ordinary lists intact while still giving you the full GFM behavior where you need it.
How the GFM task‑list extension works
GFM defines a task list as a list item whose first inline element matches the pattern [ ] or [x] (with a single space after the bracket). When the extension is active, the parser emits:
<ul class='contains-task-list'>
<li>
<input type='checkbox' disabled>
task description
</li>
</ul>
The disabled attribute prevents form submission, and the wrapper ul receives the class contains-task-list for styling.
Worked example: Eleventy with a custom flag
Assume you use Eleventy (11ty) with the markdown-it engine. Install the task‑list plugin:
# Run in your project root (requires npm access)
npm install markdown-it-task-lists --save-dev
Then create a configuration file .eleventy.js that conditionally loads the extension only when front matter contains taskList: true:
const markdownIt = require('markdown-it');
const taskLists = require('markdown-it-task-lists');
module.exports = function(eleventyConfig) {
eleventyConfig.setLibrary('md', markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true
})
// The plugin is added later in a template‑level filter
);
// Add a Nunjucks filter that renders with or without the extension
eleventyConfig.addNunjucksFilter('mdRender', function(content, frontMatter) {
let md = markdownIt({
html: true,
breaks: true,
linkify: true,
typographer: true
});
if (frontMatter && frontMatter.taskList === true) {
md.use(taskLists);
}
return md.render(content);
});
};
In a Markdown file you can now control the behavior:
---
title: 'Release checklist'
taskList: true
---
- [ ] Update version number
- [x] Publish changelog
- [ ] Notify stakeholders
Any other Markdown file that omits taskList: true will render normal bullet lists, even if it contains strings like [ ] inside code blocks or sentences.
Trade‑off and limitation
The approach adds a small rendering step: the filter must inspect front matter and optionally re‑instantiate the parser with the extension. This means:
- Build time increases slightly because the Markdown engine is created twice for pages that need task lists.
- If you rely on other
markdown-itplugins (e.g., for footnotes or emoji), you must re‑apply them in the filter or share a base configuration to avoid missing functionality.
You can verify the result by checking the generated HTML:
# After running eleventy, inspect the output file
grep -A 2 '' _site/release-checklist/index.html
Expected snippet (not tested):
<ul class='contains-task-list'>
<li><input type='checkbox' disabled> Update version number</li>
<li><input type='checkbox' checked disabled> Publish changelog</li>
<li><input type='checkbox' disabled> Notify stakeholders</li>
</ul>
If you see plain <li> elements without the wrapper class or checkboxes, the flag was not respected—double‑check that front matter is being passed to the filter and that the YAML is valid.
Actionable closing
To adopt this pattern:
- Add the
markdown-it-task-listspackage to your dev dependencies. - Wrap your Markdown rendering in a function that receives the page’s front matter.
- Conditionally call
.use(taskLists)only when a flag such astaskList: trueis present. - Audit a few pages with and without the flag to ensure ordinary lists stay unchanged.
- Keep the parser version pinned (e.g.,
markdown-it@14.1.0) to avoid unexpected GFM spec changes.
By scoping the task‑list extension to the content that truly needs it, you preserve the readability of your Markdown source while still getting the accessible, styled checkboxes where they are useful.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.