{"name":"remark-directive","version":"2.0.0","description":"remark plugin to support directives","license":"MIT","keywords":["unified","remark","remark-plugin","plugin","mdast","markdown","generic","directive","container"],"repository":{"type":"git","url":"git+https://github.com/remarkjs/remark-directive.git"},"bugs":{"url":"https://github.com/remarkjs/remark-directive/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"@types/mdast":"^3.0.0","mdast-util-directive":"^2.0.0","micromark-extension-directive":"^2.0.0","unified":"^10.0.0"},"devDependencies":{"@types/tape":"^4.0.0","c8":"^7.0.0","is-hidden":"^2.0.0","prettier":"^2.0.0","remark":"^14.0.0","remark-cli":"^10.0.0","remark-preset-wooorm":"^8.0.0","rimraf":"^3.0.0","tape":"^5.0.0","to-vfile":"^7.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.43.0"},"scripts":{"build":"rimraf \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage","format":"remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true,"ignoreCatch":true},"gitHead":"2631e46657a401e32c7555342d30b58bc57d6d4f","homepage":"https://github.com/remarkjs/remark-directive#readme","_id":"remark-directive@2.0.0","_nodeVersion":"16.6.1","_npmVersion":"7.20.3","dist":{"integrity":"sha512-1AMpSzp/NsvursAORfucrP+FeXJOm5kgA5Au8nID45zYNKAmI7PtI8ywExXl2U2pJlG4KtPyhA75flPRZz5K4A==","shasum":"db838ab7a2543dea0b07a2041fe982112f611add","tarball":"http://registry-npm.ywwl.com/remark-directive/download/remark-directive-2.0.0.tgz","fileCount":5,"unpackedSize":10577,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhC/CCCRA9TVsSAnZWagAALnkP/RsLvStj0de93TEbWJ4B\nYWoyFWxdpqcRGRHrIlauFNCDD6x9apJ+yMl8kd4lDk9XoZC5VPyGhPEV4DT3\nW0IzC65dAlxYktv/lo3Cv2gNReYEXe7l0SKC8igTrhBWx1dif54DY1DyeMS0\nwAmmMOC+rMUVAp3mDRglHBnudVwGVfbEwjsadpvBCiWjxZFdFbfS2vl76tWX\ndJSbQu9J3nOkBbimyDYNqAn0JZtRcfwLcLx3yazUmkfvJdoFPjEn0406nQZt\nVG5yXkBhgjfN1Bj/SoEibpFLuPK2ejmNxjGHQL6n6rnRyqno8LDLE88RLe+Q\nA0AM2LNYknXKGGR8IbbuH7P232GuZrJSanjAZ8ZGDOkNkFwMZMZSTL8NWJIS\njOydWPLpJh2W2UmwBj4xFk3VAOJcchBE9fKTTHbPdlgkwx0uKFcrOeyx4+7c\nNXVYhdP3pOAq4gS0s4Ydq6DNQEDmMhxb2ug6k+FmBS2W+ve6X1DwsMmUx9MJ\n5eT4nrXEkRPtqv5hwZzQUaAf++a5IOtF8LL4oFZXRZSULLZ9VIGp8Y72eRzQ\nS7wGwX6nDb2o2I4QELs+jskH0c+iKGs0+5pkbgo/t+96+qqR90oqDrCHwoHt\nBfItiJ7r02sCpkeQqJXO0X3J866T3dbCsLtFv5Vi4TFN6b4HF9/3rtgDw5U+\nHYWA\r\n=yGYg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHwIbBugo2C+ywZMAKfadoZhBzf2wX3FOdk4xjjGe2PcAiAQraEmFaLSLq1LGu17N7OoTB59Rpm5f4RCI2NOUDv+Gg=="}],"size":4266,"noattachment":false,"key":"/remark-directive/-/remark-directive-2.0.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"johno","email":"johnotander@gmail.com"},{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/remark-directive_2.0.0_1628172418100_0.9659196334083633"},"_hasShrinkwrap":false,"readme":"# remark-directive\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n**[remark][]** plugin to support the [generic directives\nproposal][commonmark-prop] (`:cite[smith04]`,\n`::youtube[Video of a cat in a box]{v=01ab2cd3efg}`, and such).\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`unified().use(remarkDirective)`](#unifieduseremarkdirective)\n*   [Examples](#examples)\n    *   [Example: YouTube](#example-youtube)\n    *   [Example: Styled blocks](#example-styled-blocks)\n*   [Authoring](#authoring)\n*   [HTML](#html)\n*   [CSS](#css)\n*   [Syntax](#syntax)\n*   [Syntax tree](#syntax-tree)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a [unified][] ([remark][]) plugin to add support for directives:\none syntax for arbitrary extensions in markdown.\n\n## When should I use this?\n\nDirectives are one of the four ways to extend markdown: an arbitrary extension\nsyntax (see [Extending markdown][micromark-extending-markdown] in micromark’s\ndocs for the alternatives and more info).\nThis mechanism works well when you control the content: who authors it, what\ntools handle it, and where it’s displayed.\nWhen authors can read a guide on how to embed a tweet but are not expected to\nknow the ins and outs of HTML or JavaScript.\nDirectives don’t work well if you don’t know who authors content, what tools\nhandle it, and where it ends up.\nExample use cases are a docs website for a project or product, or blogging\ntools and static site generators.\n\nIf you *just* want to turn markdown into HTML (with maybe a few extensions such\nas this one), we recommend [`micromark`][micromark] with\n[`micromark-extension-directive`][micromark-extension-directive] instead.\nIf you don’t use plugins and want to access the syntax tree, you can use\n[`mdast-util-from-markdown`][mdast-util-from-markdown] with\n[`mdast-util-directive`][mdast-util-directive].\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install remark-directive\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport remarkDirective from 'https://esm.sh/remark-directive@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import remarkDirective from 'https://esm.sh/remark-directive@3?bundle'\n</script>\n```\n\n## Use\n\nSay our document `example.md` contains:\n\n```markdown\n:::main{#readme}\n\nLorem:br\nipsum.\n\n::hr{.red}\n\nA :i[lovely] language know as :abbr[HTML]{title=\"HyperText Markup Language\"}.\n\n:::\n```\n\n…and our module `example.js` contains:\n\n```js\n// Register `hName`, `hProperties` types, used when turning markdown to HTML:\n/// <reference types=\"mdast-util-to-hast\" />\n// Register directive nodes in mdast:\n/// <reference types=\"mdast-util-directive\" />\n\nimport {h} from 'hastscript'\nimport rehypeFormat from 'rehype-format'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkDirective from 'remark-directive'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport {read} from 'to-vfile'\nimport {unified} from 'unified'\nimport {visit} from 'unist-util-visit'\n\nconst file = await unified()\n  .use(remarkParse)\n  .use(remarkDirective)\n  .use(myRemarkPlugin)\n  .use(remarkRehype)\n  .use(rehypeFormat)\n  .use(rehypeStringify)\n  .process(await read('example.md'))\n\nconsole.log(String(file))\n\n// This plugin is an example to let users write HTML with directives.\n// It’s informative but rather useless.\n// See below for others examples.\nfunction myRemarkPlugin() {\n  /**\n   * @param {import('mdast').Root} tree\n   *   Tree.\n   * @returns {undefined}\n   *   Nothing.\n   */\n  return function (tree) {\n    visit(tree, function (node) {\n      if (\n        node.type === 'containerDirective' ||\n        node.type === 'leafDirective' ||\n        node.type === 'textDirective'\n      ) {\n        const data = node.data || (node.data = {})\n        const hast = h(node.name, node.attributes || {})\n\n        data.hName = hast.tagName\n        data.hProperties = hast.properties\n      }\n    })\n  }\n}\n```\n\n…then running `node example.js` yields:\n\n```html\n<main id=\"readme\">\n  <p>Lorem<br>ipsum.</p>\n  <hr class=\"red\">\n  <p>A <i>lovely</i> language know as <abbr title=\"HyperText Markup Language\">HTML</abbr>.</p>\n</main>\n```\n\n## API\n\nThis package exports no identifiers.\nThe default export is [`remarkDirective`][api-remark-directive].\n\n### `unified().use(remarkDirective)`\n\nAdd support for generic directives.\n\n###### Parameters\n\nThere are no parameters.\n\n###### Returns\n\nNothing (`undefined`).\n\n###### Notes\n\nDoesn’t handle the directives:\n[create your own plugin][unified-create-plugin] to do that.\n\n## Examples\n\n### Example: YouTube\n\nThis example shows how directives can be used for YouTube embeds.\nIt’s based on the example in Use above.\nIf `myRemarkPlugin` was replaced with this function:\n\n```js\n// Register `hName`, `hProperties` types, used when turning markdown to HTML:\n/// <reference types=\"mdast-util-to-hast\" />\n// Register directive nodes in mdast:\n/// <reference types=\"mdast-util-directive\" />\n\nimport {visit} from 'unist-util-visit'\n\n// This plugin is an example to turn `::youtube` into iframes.\nfunction myRemarkPlugin() {\n  /**\n   * @param {import('mdast').Root} tree\n   *   Tree.\n   * @param {import('vfile').VFile} file\n   *   File.\n   * @returns {undefined}\n   *   Nothing.\n   */\n  return (tree, file) => {\n    visit(tree, function (node) {\n      if (\n        node.type === 'containerDirective' ||\n        node.type === 'leafDirective' ||\n        node.type === 'textDirective'\n      ) {\n        if (node.name !== 'youtube') return\n\n        const data = node.data || (node.data = {})\n        const attributes = node.attributes || {}\n        const id = attributes.id\n\n        if (node.type === 'textDirective') {\n          file.fail(\n            'Unexpected `:youtube` text directive, use two colons for a leaf directive',\n            node\n          )\n        }\n\n        if (!id) {\n          file.fail('Unexpected missing `id` on `youtube` directive', node)\n        }\n\n        data.hName = 'iframe'\n        data.hProperties = {\n          src: 'https://www.youtube.com/embed/' + id,\n          width: 200,\n          height: 200,\n          frameBorder: 0,\n          allow: 'picture-in-picture',\n          allowFullScreen: true\n        }\n      }\n    })\n  }\n}\n```\n\n…and `example.md` contains:\n\n```markdown\n# Cat videos\n\n::youtube[Video of a cat in a box]{#01ab2cd3efg}\n```\n\n…then running `node example.js` yields:\n\n```html\n<h1>Cat videos</h1>\n<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>\n```\n\n### Example: Styled blocks\n\n> 👉 **Note**: This is sometimes called admonitions, callouts, etc.\n\nThis example shows how directives can be used to style blocks.\nIt’s based on the example in Use above.\nIf `myRemarkPlugin` was replaced with this function:\n\n```js\n// Register `hName`, `hProperties` types, used when turning markdown to HTML:\n/// <reference types=\"mdast-util-to-hast\" />\n// Register directive nodes in mdast:\n/// <reference types=\"mdast-util-directive\" />\n\nimport {h} from 'hastscript'\nimport {visit} from 'unist-util-visit'\n\n// This plugin is an example to turn `::youtube` into iframes.\n// This plugin is an example to turn `::note` into divs, passing arbitrary\n// attributes.\nfunction myRemarkPlugin() {\n  /**\n   * @param {import('mdast').Root} tree\n   *   Tree.\n   * @returns {undefined}\n   *   Nothing.\n   */\n  return (tree) => {\n    visit(tree, (node) => {\n      if (\n        node.type === 'containerDirective' ||\n        node.type === 'leafDirective' ||\n        node.type === 'textDirective'\n      ) {\n        if (node.name !== 'note') return\n\n        const data = node.data || (node.data = {})\n        const tagName = node.type === 'textDirective' ? 'span' : 'div'\n\n        data.hName = tagName\n        data.hProperties = h(tagName, node.attributes || {}).properties\n      }\n    })\n  }\n}\n```\n\n…and `example.md` contains:\n\n```markdown\n# How to use xxx\n\nYou can use xxx.\n\n:::note{.warning}\nif you chose xxx, you should also use yyy somewhere…\n:::\n```\n\n…then running `node example` yields:\n\n```html\n<h1>How to use xxx</h1>\n<p>You can use xxx.</p>\n<div class=\"warning\">\n  <p>if you chose xxx, you should also use yyy somewhere…</p>\n</div>\n```\n\n## Authoring\n\nWhen authoring markdown with directives, keep in mind that they don’t work in\nmost places.\nOn your own site it can be great!\n\n## HTML\n\nYou can define how directives are turned into HTML.\nIf directives are not handled, they do not emit anything.\n\n## CSS\n\nHow to display directives is left as an exercise for the reader.\n\n## Syntax\n\nSee [*Syntax* in\n`micromark-extension-directive`](https://github.com/micromark/micromark-extension-directive#syntax).\n\n## Syntax tree\n\nSee [*Syntax tree* in\n`mdast-util-directive`](https://github.com/syntax-tree/mdast-util-directive#syntax-tree).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional options.\n\nIf you’re working with the syntax tree, you can register the new node types\nwith `@types/mdast` by adding a reference:\n\n```js\n// Register directive nodes in mdast:\n/// <reference types=\"mdast-util-directive\" />\n\nimport {visit} from 'unist-util-visit'\n\nfunction myRemarkPlugin() {\n  /**\n   * @param {import('mdast').Root} tree\n   *   Tree.\n   * @returns {undefined}\n   *   Nothing.\n   */\n  return (tree) => {\n    visit(tree, function (node) {\n      console.log(node) // `node` can now be one of the nodes for directives.\n    })\n  }\n}\n```\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `remark-directive@^3`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `remark-directive` does not involve **[rehype][]** ([hast][]) or user\ncontent so there are no openings for [cross-site scripting (XSS)][wiki-xss]\nattacks.\n\n## Related\n\n*   [`remark-gfm`](https://github.com/remarkjs/remark-gfm)\n    — support GFM (autolink literals, footnotes, strikethrough, tables,\n    tasklists)\n*   [`remark-frontmatter`](https://github.com/remarkjs/remark-frontmatter)\n    — support frontmatter (YAML, TOML, and more)\n*   [`remark-math`](https://github.com/remarkjs/remark-math)\n    — support math\n*   [`remark-mdx`](https://github.com/mdx-js/mdx/tree/main/packages/remark-mdx)\n    — support MDX (ESM, JSX, expressions)\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways\nto get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/remarkjs/remark-directive/workflows/main/badge.svg\n\n[build]: https://github.com/remarkjs/remark-directive/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-directive.svg\n\n[coverage]: https://codecov.io/github/remarkjs/remark-directive\n\n[downloads-badge]: https://img.shields.io/npm/dm/remark-directive.svg\n\n[downloads]: https://www.npmjs.com/package/remark-directive\n\n[size-badge]: https://img.shields.io/bundlejs/size/remark-directive\n\n[size]: https://bundlejs.com/?q=remark-directive\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/remarkjs/remark/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[health]: https://github.com/remarkjs/.github\n\n[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md\n\n[support]: https://github.com/remarkjs/.github/blob/main/support.md\n\n[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[commonmark-prop]: https://talk.commonmark.org/t/generic-directives-plugins-syntax/444\n\n[hast]: https://github.com/syntax-tree/hast\n\n[mdast-util-directive]: https://github.com/syntax-tree/mdast-util-directive\n\n[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown\n\n[micromark]: https://github.com/micromark/micromark\n\n[micromark-extension-directive]: https://github.com/micromark/micromark-extension-directive\n\n[micromark-extending-markdown]: https://github.com/micromark/micromark#extending-markdown\n\n[rehype]: https://github.com/rehypejs/rehype\n\n[remark]: https://github.com/remarkjs/remark\n\n[typescript]: https://www.typescriptlang.org\n\n[unified]: https://github.com/unifiedjs/unified\n\n[unified-create-plugin]: https://unifiedjs.com/learn/guide/create-a-plugin/\n\n[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[api-remark-directive]: #unifieduseremarkdirective\n","publish_time":1628172418232,"_cnpm_publish_time":1628172418232,"dist-tags":{"latest":"4.0.0"}}