unified

Project: micromark/micromark-extension-gfm-strikethrough

Package: micromark-extension-gfm-strikethrough@1.0.4

  1. Dependents: 0
  2. micromark extension to support GFM strikethrough
  1. unified 169
  2. markdown 136
  3. micromark 20
  4. gfm 19
  5. micromark-extension 17
  6. strikethrough 6
  7. delete 3
  8. strike 2
  9. through 2
  10. del 2
  11. deletion 2

micromark-extension-gfm-strikethrough

Build Coverage Downloads Size Sponsors Backers Chat

micromark extension to support GFM strikethrough.

Contents

What is this?

This package contains extensions that add support for strikethrough as enabled by GFM to micromark. Strikethrough on github.com, which this extension matches, can use one (~one~) or two (~~two~~) tildes. The GFM spec strictly prohibits one tilde to be used. That behavior can be used by passing singleTilde: false.

When to use this

These tools are all low-level. In many cases, you want to use remark-gfm with remark instead.

Even when you want to use micromark, you likely want to use micromark-extension-gfm to support all GFM features. That extension includes this extension.

When working with mdast-util-from-markdown, you must combine this package with mdast-util-gfm-strikethrough.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:

npm install micromark-extension-gfm-strikethrough

In Deno with esm.sh:

import {gfmStrikethrough, gfmStrikethroughHtml} from 'https://esm.sh/micromark-extension-gfm-strikethrough@1'

In browsers with esm.sh:

<script type="module">
  import {gfmStrikethrough, gfmStrikethroughHtml} from 'https://esm.sh/micromark-extension-gfm-strikethrough@1?bundle'
</script>

Use

import {micromark} from 'micromark'
import {
  gfmStrikethrough,
  gfmStrikethroughHtml
} from 'micromark-extension-gfm-strikethrough'

const output = micromark('Some ~strikethrough~.', {
  extensions: [gfmStrikethrough()],
  htmlExtensions: [gfmStrikethroughHtml]
})

console.log(output)

Yields:

<p>Some <del>strikethrough</del></p>.

API

This package exports the identifiers gfmStrikethrough and gfmStrikethroughHtml. There is no default export.

The export map supports the endorsed development condition. Run node --conditions development module.js to get instrumented dev code. Without this condition, production code is loaded.

gfmStrikethrough(options?)

Function that can be called to get a syntax extension for micromark (passed in extensions).

options

Configuration (optional).

options.singleTilde

Whether to support strikethrough with a single tilde (boolean, default: true). Single tildes work on github.com but are technically prohibited by GFM.

gfmStrikethroughHtml

HTML extension for micromark (passed in htmlExtensions).

Authoring

When authoring markdown with strikethrough, it’s recommended to stick to two tildes for each run. That makes sure it works in most places.

HTML

GFM task list items relate to the <del> element in HTML. See § 4.7.2 The del element in the HTML spec for more info.

CSS

GitHub itself does not apply interesting CSS to del elements. It currently (July 2022) does change code in del.

del code {
  text-decoration: inherit;
}

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

Syntax

Strikethrough parses like other attention (emphasis, strong), which means that it gets really complex and a BNF grammar cannot do it justice.

Types

This package is fully typed with TypeScript. It exports the additional type Options.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. It also works in Deno and modern browsers.

Security

This package is safe.

Contribute

See contributing.md in micromark/.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