mdast-util-gfm-task-list-item
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    mdast-util-gfm-task-list-item

    Build Coverage Downloads Size Sponsors Backers Chat

    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.

    When to use this

    Use this if you’re dealing with the AST manually. It’s might be better to use remark-gfm with remark, which includes this but provides a nicer interface and makes it easier to combine with hundreds of plugins.

    Install

    This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

    npm:

    npm install mdast-util-gfm-task-list-item

    Use

    Say we have the following file, example.md:

    * [ ] To do
    * [x] Done
    
    1. Mixed…
    2. [x] …messages

    And our module, example.js, looks as follows:

    import fs from 'node:fs'
    import {fromMarkdown} from 'mdast-util-from-markdown'
    import {toMarkdown} from 'mdast-util-to-markdown'
    import {gfmTaskListItem} from 'micromark-extension-gfm-task-list-item'
    import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'mdast-util-gfm-task-list-item'
    
    const doc = fs.readFileSync('example.md')
    
    const tree = fromMarkdown(doc, {
      extensions: [gfmTaskListItem],
      mdastExtensions: [gfmTaskListItemFromMarkdown]
    })
    
    console.log(tree)
    
    const out = toMarkdown(tree, {extensions: [gfmTaskListItemToMarkdown]})
    
    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

    API

    This package exports the following identifier: gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown. There is no default export.

    gfmTaskListItemFromMarkdown

    gfmTaskListItemToMarkdown

    Support task list items. The exports are extensions, respectively for mdast-util-from-markdown and mdast-util-to-markdown.

    Related

    Contribute

    See 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.

    License

    MIT © Titus Wormer

    Install

    npm i mdast-util-gfm-task-list-item

    DownloadsWeekly Downloads

    384,516

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    13.3 kB

    Total Files

    5

    Last publish

    Collaborators

    • wooorm
    • kmck