Gathering detailed insights and metrics for remark-directive
Gathering detailed insights and metrics for remark-directive
Gathering detailed insights and metrics for remark-directive
Gathering detailed insights and metrics for remark-directive
remark-directive-rehype
Remark plugin to enable Markdown directives to be parsed as HTML.
remark-github-admonitions-to-directives
A Remark plugin to convert Github style alerts to admonitions directives.
@hanseartic/remark-qrcode-directive
QR-code directive plugin for remark
remark-directive-sugar
Remark plugin built on remark-directive, providing predefined directives for image captions, video embedding, styled GitHub links, badges, and more.
npm install remark-directive
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
329 Stars
60 Commits
17 Forks
9 Watchers
1 Branches
14 Contributors
Updated on Jul 07, 2025
Latest Version
4.0.0
Package Id
remark-directive@4.0.0
Unpacked Size
19.58 kB
Size
6.70 kB
File Count
8
NPM Version
11.1.0
Node Version
23.1.0
Published on
Feb 27, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
remark plugin to support the
generic directives proposal
(:cite[smith04]
,
::youtube[Video of a cat in a box]{v=01ab2cd3efg}
,
and such).
This package is a unified (remark) plugin to add support for directives: one syntax for arbitrary extensions in markdown.
Directives are one of the four ways to extend markdown: an arbitrary extension syntax (see Extending markdown in micromark’s docs for the alternatives and more info). This mechanism works well when you control the content: who authors it, what tools handle it, and where it’s displayed. When authors can read a guide on how to embed a tweet but are not expected to know the ins and outs of HTML or JavaScript. Directives don’t work well if you don’t know who authors content, what tools handle it, and where it ends up. Example use cases are a docs website for a project or product, or blogging tools and static site generators.
If you just want to turn markdown into HTML (with maybe a few extensions such
as this one),
we recommend micromark
with
micromark-extension-directive
instead.
If you don’t use plugins and want to access the syntax tree,
you can use
mdast-util-from-markdown
with
mdast-util-directive
.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install remark-directive
In Deno with esm.sh
:
1import remarkDirective from 'https://esm.sh/remark-directive@3'
In browsers with esm.sh
:
1<script type="module"> 2 import remarkDirective from 'https://esm.sh/remark-directive@3?bundle' 3</script>
Say our document example.md
contains:
1:::main{#readme} 2 3Lorem:br 4ipsum. 5 6::hr{.red} 7 8A :i[lovely] language know as :abbr[HTML]{title="HyperText Markup Language"}. 9 10:::
…and our module example.js
contains:
1/** 2 * @import {} from 'mdast-util-directive' 3 * @import {} from 'mdast-util-to-hast' 4 * @import {Root} from 'mdast' 5 */ 6 7import {h} from 'hastscript' 8import rehypeFormat from 'rehype-format' 9import rehypeStringify from 'rehype-stringify' 10import remarkDirective from 'remark-directive' 11import remarkParse from 'remark-parse' 12import remarkRehype from 'remark-rehype' 13import {read} from 'to-vfile' 14import {unified} from 'unified' 15import {visit} from 'unist-util-visit' 16 17const file = await unified() 18 .use(remarkParse) 19 .use(remarkDirective) 20 .use(myRemarkPlugin) 21 .use(remarkRehype) 22 .use(rehypeFormat) 23 .use(rehypeStringify) 24 .process(await read('example.md')) 25 26console.log(String(file)) 27 28// This plugin is an example to let users write HTML with directives. 29// It’s informative but rather useless. 30// See below for others examples. 31function myRemarkPlugin() { 32 /** 33 * @param {Root} tree 34 * Tree. 35 * @returns {undefined} 36 * Nothing. 37 */ 38 return function (tree) { 39 visit(tree, function (node) { 40 if ( 41 node.type === 'containerDirective' || 42 node.type === 'leafDirective' || 43 node.type === 'textDirective' 44 ) { 45 const data = node.data || (node.data = {}) 46 const hast = h(node.name, node.attributes || {}) 47 48 data.hName = hast.tagName 49 data.hProperties = hast.properties 50 } 51 }) 52 } 53}
…then running node example.js
yields:
1<main id="readme"> 2 <p>Lorem<br>ipsum.</p> 3 <hr class="red"> 4 <p>A <i>lovely</i> language know as <abbr title="HyperText Markup Language">HTML</abbr>.</p> 5</main>
This package exports no identifiers.
The default export is remarkDirective
.
unified().use(remarkDirective[, options])
Add support for generic directives.
options
(Options
, optional)
— configurationNothing (undefined
).
Doesn’t handle the directives: create your own plugin to do that.
Options
Configuration (TypeScript type).
collapseEmptyAttributes
(boolean
, default: true
)
— collapse empty attributes: get title
instead of title=""
preferShortcut
(boolean
, default: true
)
— prefer #
and .
shortcuts for id
and class
preferUnquoted
(boolean
, default: false
)
— leave attributes unquoted if that results in less bytesquoteSmart
(boolean
, default: false
)
— use the other quote if that results in less bytesquote
('"'
or "'"
,
default:
the quote
used by remark-stringify
for
titles)
— preferred quote to use around attribute valuesThis example shows how directives can be used for YouTube embeds.
It’s based on the example in Use above.
If myRemarkPlugin
was replaced with this function:
1/** 2 * @import {} from 'mdast-util-directive' 3 * @import {} from 'mdast-util-to-hast' 4 * @import {Root} from 'mdast' 5 * @import {VFile} from 'vfile' 6 */ 7 8import {visit} from 'unist-util-visit' 9 10// This plugin is an example to turn `::youtube` into iframes. 11function myRemarkPlugin() { 12 /** 13 * @param {Root} tree 14 * Tree. 15 * @param {VFile} file 16 * File. 17 * @returns {undefined} 18 * Nothing. 19 */ 20 return (tree, file) => { 21 visit(tree, function (node) { 22 if ( 23 node.type === 'containerDirective' || 24 node.type === 'leafDirective' || 25 node.type === 'textDirective' 26 ) { 27 if (node.name !== 'youtube') return 28 29 const data = node.data || (node.data = {}) 30 const attributes = node.attributes || {} 31 const id = attributes.id 32 33 if (node.type === 'textDirective') { 34 file.fail( 35 'Unexpected `:youtube` text directive, use two colons for a leaf directive', 36 node 37 ) 38 } 39 40 if (!id) { 41 file.fail('Unexpected missing `id` on `youtube` directive', node) 42 } 43 44 data.hName = 'iframe' 45 data.hProperties = { 46 src: 'https://www.youtube.com/embed/' + id, 47 width: 200, 48 height: 200, 49 frameBorder: 0, 50 allow: 'picture-in-picture', 51 allowFullScreen: true 52 } 53 } 54 }) 55 } 56}
…and example.md
contains:
1# Cat videos 2 3::youtube[Video of a cat in a box]{#01ab2cd3efg}
…then running node example.js
yields:
1<h1>Cat videos</h1> 2<iframe src="https://www.youtube.com/embed/01ab2cd3efg" width="200" height="200" frameborder="0" allow="picture-in-picture" allowfullscreen>Video of a cat in a box</iframe>
👉 Note: this is sometimes called admonitions, callouts, etc.
This example shows how directives can be used to style blocks.
It’s based on the example in Use above.
If myRemarkPlugin
was replaced with this function:
1/** 2 * @import {} from 'mdast-util-directive' 3 * @import {} from 'mdast-util-to-hast' 4 * @import {Root} from 'mdast' 5 */ 6 7import {h} from 'hastscript' 8import {visit} from 'unist-util-visit' 9 10// This plugin is an example to turn `::note` into divs, 11// passing arbitrary attributes. 12function myRemarkPlugin() { 13 /** 14 * @param {Root} tree 15 * Tree. 16 * @returns {undefined} 17 * Nothing. 18 */ 19 return (tree) => { 20 visit(tree, (node) => { 21 if ( 22 node.type === 'containerDirective' || 23 node.type === 'leafDirective' || 24 node.type === 'textDirective' 25 ) { 26 if (node.name !== 'note') return 27 28 const data = node.data || (node.data = {}) 29 const tagName = node.type === 'textDirective' ? 'span' : 'div' 30 31 data.hName = tagName 32 data.hProperties = h(tagName, node.attributes || {}).properties 33 } 34 }) 35 } 36}
…and example.md
contains:
1# How to use xxx 2 3You can use xxx. 4 5:::note{.warning} 6if you chose xxx, you should also use yyy somewhere… 7:::
…then running node example
yields:
1<h1>How to use xxx</h1> 2<p>You can use xxx.</p> 3<div class="warning"> 4 <p>if you chose xxx, you should also use yyy somewhere…</p> 5</div>
When authoring markdown with directives, keep in mind that they don’t work in most places. On your own site it can be great!
You can define how directives are turned into HTML. If directives are not handled, they do not emit anything.
How to display directives is left as an exercise for the reader.
See Syntax in
micromark-extension-directive
.
See Syntax tree in
mdast-util-directive
.
This package is fully typed with TypeScript. It exports no additional options.
If you’re working with the syntax tree,
you can register the new node types with @types/mdast
by adding a reference:
1/** 2 * @import {} from 'mdast-util-directive' 3 * @import {Root} from 'mdast' 4 */ 5 6import {visit} from 'unist-util-visit' 7 8function myRemarkPlugin() { 9 /** 10 * @param {Root} tree 11 * Tree. 12 * @returns {undefined} 13 * Nothing. 14 */ 15 return (tree) => { 16 visit(tree, function (node) { 17 console.log(node) // `node` can now be one of the nodes for directives. 18 }) 19 } 20}
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release,
we drop support for unmaintained versions of Node.
This means we try to keep the current release line,
remark-directive@3
,
compatible with Node.js 16.
Use of remark-directive
does not involve rehype
(hast)
or user content so there are no openings for
cross-site scripting (XSS) attacks.
remark-gfm
— support GFM
(autolink literals, footnotes, strikethrough, tables, tasklists)remark-frontmatter
— support frontmatter
(YAML, TOML, and more)remark-math
— support mathremark-mdx
— support MDX
(ESM, JSX, expressions)See contributing.md
in
remarkjs/.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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More