mdast-util-inline-spoiler
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

mdast-util-inline-spoiler

Thanks to benrbray/remark-cite for a remark plugin boilerplate.

license

Extension for mdast-util-from-markdown and mdast-util-to-markdown to support Discord-style spoilers. Converts the token stream produced by micromark-extension-inline-spoiler into an abstract syntax tree.

Using remark? You probably shouldn’t use this package directly, but instead use remark-inline-spoiler. See micromark-extension-inline-spoiler for a full description of the supported syntax.

Install

Install mdast-util-inline-spoiler on npm, yarn or bun.

npm install mdast-util-inline-spoiler
yarn add mdast-util-inline-spoiler
bun install mdast-util-inline-spoiler

Usage

Markdown to AST

import fromMarkdown from 'mdast-util-from-markdown'
import { spoilerSyntax } from 'micromark-extension-inline-spoiler'
import { spoilerFromMarkdown } from 'mdast-util-inline-spoiler'

let ast = fromMarkdown('||Don\'t spoil this||', {
  extensions: [spoilerSyntax()],
  mdastExtensions: [spoilerFromMarkdown]
})

The corresponding node in the abstract syntax tree has the form below, where value contains the hidden content:

{
	"type": "spoiler",
	"value": "Don't spoil this"
}

AST to Markdown

Taking the ast from the previous example,

import fromMarkdown from 'mdast-util-from-markdown'
import { spoilerToMarkdown } from 'mdast-util-inline-spoiler'

let markdownString = toMarkdown(ast, {
	extensions: [spoilerToMarkdown({})]
}).trim();

The result will be:

||Don't spoil this||

Package Sidebar

Install

npm i mdast-util-inline-spoiler

Weekly Downloads

7

Version

1.0.0

License

MIT

Unpacked Size

21.2 kB

Total Files

14

Last publish

Collaborators

  • hlysine