unified

Project: syntax-tree/mdast-util-gfm-strikethrough

Package: mdast-util-gfm-strikethrough@0.2.0

  1. Dependencies: 1·Dependents: 0
  2. mdast extension to parse and serialize GFM strikethrough
  1. markdown 133
  2. util 118
  3. utility 114
  4. unist 110
  5. mdast 81
  6. mdast-util 24
  7. gfm 17
  8. markup 12
  9. strikethrough 4
  10. delete 3
  11. strike 2
  12. through 2
  13. del 2
  14. deletion 2

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.

You probably shouldn’t use this package directly, but instead use remark-gfm with remark.

Install

npm:

npm install mdast-util-gfm-strikethrough

Use

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

var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-gfm-strikethrough')
var strikethrough = require('mdast-util-gfm-strikethrough')

var doc = '*Emphasis*, **importance**, and ~~strikethrough~~.'

var tree = fromMarkdown(doc, {
  extensions: [syntax()],
  mdastExtensions: [strikethrough.fromMarkdown]
})

console.log(tree)

var out = toMarkdown(tree, {extensions: [strikethrough.toMarkdown]})

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

strikethrough.fromMarkdown

strikethrough.toMarkdown

Note: the separate extensions are also available at mdast-util-gfm-strikethrough/from-markdown and mdast-util-gfm-strikethrough/to-markdown.

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

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