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

    1.0.0 • Public • Published

    mdast-util-gfm-strikethrough

    Build Coverage Downloads Size Sponsors Backers Chat

    Extension for mdast-util-from-markdown and/or mdast-util-to-markdown to support GitHub flavored markdown strikethrough (like this) in mdast. When parsing (from-markdown), must be combined with micromark-extension-gfm-strikethrough.

    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-strikethrough

    Use

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

    import {fromMarkdown} from 'mdast-util-from-markdown'
    import {toMarkdown} from 'mdast-util-to-markdown'
    import {gfmStrikethrough} from 'micromark-extension-gfm-strikethrough'
    import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'mdast-util-gfm-strikethrough'
    
    const doc = '*Emphasis*, **importance**, and ~~strikethrough~~.'
    
    const tree = fromMarkdown(doc, {
      extensions: [gfmStrikethrough()],
      mdastExtensions: [gfmStrikethroughFromMarkdown]
    })
    
    console.log(tree)
    
    const out = toMarkdown(tree, {extensions: [gfmStrikethroughToMarkdown]})
    
    console.log(out)

    Now, running node example yields:

    {
      type: 'root',
      children: [
        {
          type: 'paragraph',
          children: [
            {type: 'emphasis', children: [{type: 'text', value: 'Emphasis'}]},
            {type: 'text', value: ', '},
            {type: 'strong', children: [{type: 'text', value: 'importance'}]},
            {type: 'text', value: ', and '},
            {type: 'delete', children: [{type: 'text', value: 'strikethrough'}]},
            {type: 'text', value: '.'}
          ]
        }
      ]
    }
    *Emphasis*, **importance**, and ~~strikethrough~~.

    API

    This package exports the following identifier: gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown. There is no default export.

    gfmStrikethroughFromMarkdown

    gfmStrikethroughToMarkdown

    Support strikethrough. 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-strikethrough

    DownloadsWeekly Downloads

    386,437

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    10.8 kB

    Total Files

    5

    Last publish

    Collaborators

    • wooorm
    • kmck