micromark-extension-gfm-task-list-item

micromark extension to support GFM task list items

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
micromark-extension-gfm-task-list-item
502.0.19 months ago4 years agoMinified + gzip package size for micromark-extension-gfm-task-list-item in KB

Readme

micromark-extension-gfm-task-list-item
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
micromark extensions to support GFM task list items.

Contents

*   [`gfmTaskListItem()`](#gfmtasklistitem)
*   [`gfmTaskListItemHtml()`](#gfmtasklistitemhtml)

What is this?

This package contains extensions that add support for task lists as enabled by GFM to micromarkmicromark. It matches how task list items work on github.com.

When to use this

This project is useful when you want to support task lists in markdown.
You can use these extensions when you are working with micromarkmicromark. To support all GFM features, use micromark-extension-gfmmicromark-extension-gfm.
When you need a syntax tree, you can combine this package with mdast-util-gfm-task-list-itemmdast-util-gfm-task-list-item.
All these packages are used remark-gfmremark-gfm, which focusses on making it easier to transform content by abstracting these internals away.

Install

This package is ESM onlyesm. In Node.js (version 16+), install with npm:
npm install micromark-extension-gfm-task-list-item

In Deno with esm.shesmsh:
import {gfmTaskListItem, gfmTaskListItemHtml} from 'https://esm.sh/micromark-extension-gfm-task-list-item@2'

In browsers with esm.shesmsh:
<script type="module">
  import {gfmTaskListItem, gfmTaskListItemHtml} from 'https://esm.sh/micromark-extension-gfm-task-list-item@2?bundle'
</script>

Use

import {micromark} from 'micromark'
import {
  gfmTaskListItem,
  gfmTaskListItemHtml
} from 'micromark-extension-gfm-task-list-item'

const output = micromark('* [x] a\n* [ ] b', {
  extensions: [gfmTaskListItem()],
  htmlExtensions: [gfmTaskListItemHtml()]
})

console.log(output)

Yields:
<ul>
<li><input type="checkbox" disabled="" checked="" /> a</li>
<li><input type="checkbox" disabled="" /> b</li>
</ul>

API

This package exports the identifiers gfmTaskListItemapi-gfm-task-list-item and gfmTaskListItemHtmlapi-gfm-task-list-item-html. There is no default export.
The export map supports the development conditiondevelopment. Run node --conditions development module.js to get instrumented dev code. Without this condition, production code is loaded.

gfmTaskListItem()

Create an HTML extension for micromark to support GFM task list items syntax.
Returns
Extension for micromark that can be passed in extensions, to enable GFM task list items syntax (Extensionmicromark-extension).

gfmTaskListItemHtml()

Create an HTML extension for micromark to support GFM task list items when serializing to HTML.
Returns
Extension for micromark that can be passed in htmlExtensions to support GFM task list items when serializing to HTML (HtmlExtensionmicromark-html-extension).

Authoring

It is recommended to use lowercase x (instead of uppercase X), because in markdown, it is more common to use lowercase in places where casing does not matter. It is also recommended to use a space (instead of a tab), as there is no benefit of using tabs in this case.

HTML

Checks relate to the <input> element, in the checkbox state (type=checkbox), in HTML. See § 4.10.5.1.15 Checkbox state (type=checkbox)html-input-checkbox in the HTML spec for more info.
<!--…-->
<li><input type="checkbox" disabled="" /> foo</li>
<li><input type="checkbox" disabled="" checked="" /> bar</li>
<!--…-->

CSS

GitHub itself uses slightly different markup for task list items than they define in their spec. When following the spec, as this extension does, only inputs are added. They can be styled with the following CSS:
input[type="checkbox"] {
  margin: 0 .2em .25em -1.6em;
  vertical-align: middle;
}

input[type="checkbox"]:dir(rtl) {
  margin: 0 -1.6em .25em .2em;
}

For the complete actual CSS see sindresorhus/github-markdown-cssgithub-markdown-css.

Syntax

Checks form with the following BNF:
gfm_task_list_item_check ::= '[' (0x09 | ' ' | 'X' | 'x') ']'

The check is only allowed at the start of the first paragraph, optionally following zero or more definitions or a blank line, in a list item. The check must be followed by whitespace ([\t\n\r ]*), which is in turn followed by non-whitespace.

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, micromark-extension-gfm-task-list-item@^2, compatible with Node.js 16.
This package works with micromark version 3 and later.

Security

This package is safe.

Related

— support all of GFM
— support all of GFM in mdast
— support all of GFM in mdast
— support all of GFM in remark

Contribute

See contributing.md in micromark/.githubcontributing for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor