Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
mdast-util-gfm-task-list-item
Advanced tools
mdast extension to parse and serialize GFM task list items
The `mdast-util-gfm-task-list-item` package is a utility for working with GitHub Flavored Markdown (GFM) task list items within the MDAST (Markdown Abstract Syntax Tree) ecosystem. It provides functionality to parse and transform task list items in Markdown documents.
Parse GFM Task List Items
This feature allows you to parse GFM task list items from a Markdown string into an MDAST tree. The code sample demonstrates how to convert a Markdown string containing task list items into an MDAST tree.
const { fromMarkdown } = require('mdast-util-from-markdown');
const { gfmTaskListItemFromMarkdown } = require('mdast-util-gfm-task-list-item');
const markdown = '- [ ] Task 1\n- [x] Task 2';
const tree = fromMarkdown(markdown, { extensions: [gfmTaskListItemFromMarkdown()] });
console.log(JSON.stringify(tree, null, 2));
Serialize GFM Task List Items
This feature allows you to serialize an MDAST tree containing GFM task list items back into a Markdown string. The code sample demonstrates how to convert an MDAST tree with task list items into a Markdown string.
const { toMarkdown } = require('mdast-util-to-markdown');
const { gfmTaskListItemToMarkdown } = require('mdast-util-gfm-task-list-item');
const tree = {
type: 'root',
children: [
{ type: 'listItem', checked: null, children: [{ type: 'text', value: 'Task 1' }] },
{ type: 'listItem', checked: true, children: [{ type: 'text', value: 'Task 2' }] }
]
};
const markdown = toMarkdown(tree, { extensions: [gfmTaskListItemToMarkdown()] });
console.log(markdown);
The `remark-gfm` package is a plugin for the `remark` Markdown processor that adds support for GitHub Flavored Markdown (GFM) features, including task lists, tables, and strikethrough. It provides a more comprehensive set of GFM features compared to `mdast-util-gfm-task-list-item`, which focuses specifically on task list items.
The `remark-task-list` package is a plugin for `remark` that specifically handles task lists in Markdown. It provides similar functionality to `mdast-util-gfm-task-list-item` but is designed to be used directly with the `remark` processor, making it a more integrated solution for users of the `remark` ecosystem.
Extension for mdast-util-from-markdown
and/or
mdast-util-to-markdown
to support GitHub flavored markdown
task list items in mdast.
When parsing (from-markdown
), must be combined with
micromark-extension-gfm-task-list-item
.
You probably shouldn’t use this package directly, but instead use remark-gfm
with remark.
npm:
npm install mdast-util-gfm-task-list-item
Say we have the following file, example.md
:
* [ ] To do
* [x] Done
1. Mixed…
2. [x] …messages
And our script, example.js
, looks as follows:
var fs = require('fs')
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-gfm-task-list-item')
var taskListItem = require('mdast-util-gfm-task-list-item')
var doc = fs.readFileSync('example.md')
var tree = fromMarkdown(doc, {
extensions: [syntax],
mdastExtensions: [taskListItem.fromMarkdown]
})
console.log(tree)
var out = toMarkdown(tree, {extensions: [taskListItem.toMarkdown]})
console.log(out)
Now, running node example
yields (positional info removed for the sake of
brevity):
{
type: 'root',
children: [
{
type: 'list',
ordered: false,
start: null,
spread: false,
children: [
{
type: 'listItem',
spread: false,
checked: false,
children: [
{type: 'paragraph', children: [{type: 'text', value: 'To do'}]}
]
},
{
type: 'listItem',
spread: false,
checked: true,
children: [
{type: 'paragraph', children: [{type: 'text', value: 'Done'}]}
]
}
]
},
{
type: 'list',
ordered: true,
start: 1,
spread: false,
children: [
{
type: 'listItem',
spread: false,
checked: null,
children: [
{type: 'paragraph', children: [{type: 'text', value: 'Mixed…'}]}
]
},
{
type: 'listItem',
spread: false,
checked: true,
children: [
{type: 'paragraph', children: [{type: 'text', value: '…messages'}]}
]
}
]
}
]
}
* [ ] To do
* [x] Done
1. Mixed…
2. [x] …messages
taskListItem.fromMarkdown
taskListItem.toMarkdown
Note: the separate extensions are also available at
mdast-util-gfm-task-list-item/from-markdown
andmdast-util-gfm-task-list-item/to-markdown
.
Support task list items.
The exports are extensions, respectively
for mdast-util-from-markdown
and
mdast-util-to-markdown
.
remarkjs/remark
— markdown processor powered by pluginsremarkjs/remark-gfm
— remark plugin to support GFMmicromark/micromark
— the smallest commonmark-compliant markdown parser that existsmicromark/micromark-extension-gfm-task-list-item
— micromark extension to parse GFM task list itemssyntax-tree/mdast-util-from-markdown
— mdast parser using micromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdastSee contributing.md
in syntax-tree/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
mdast extension to parse and serialize GFM task list items
The npm package mdast-util-gfm-task-list-item receives a total of 2,215,187 weekly downloads. As such, mdast-util-gfm-task-list-item popularity was classified as popular.
We found that mdast-util-gfm-task-list-item demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.