{"name":"micromark-extension-directive","version":"1.1.0","description":"micromark extension to support generic directives (`:cite[smith04]`)","license":"MIT","keywords":["micromark","micromark-extension","generic","directive","container","extension","markdown","unified"],"repository":{"type":"git","url":"git+https://github.com/micromark/micromark-extension-directive.git"},"bugs":{"url":"https://github.com/micromark/micromark-extension-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"}],"dependencies":{"micromark":"~2.11.0","parse-entities":"^2.0.0"},"devDependencies":{"html-void-elements":"^1.0.0","nyc":"^15.0.0","prettier":"^2.0.0","remark-cli":"^9.0.0","remark-preset-wooorm":"^8.0.0","tape":"^5.0.0","xo":"^0.36.0"},"scripts":{"format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test","test-coverage":"nyc --reporter lcov tape test.js","test":"npm run format && npm run test-coverage"},"nyc":{"check-coverage":true,"lines":100,"functions":100,"branches":100},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"esnext":false,"rules":{"guard-for-in":"off","unicorn/explicit-length-check":"off"}},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"20b2396fe9c739440c93bc52e8d185c8de8a72fa","homepage":"https://github.com/micromark/micromark-extension-directive#readme","_id":"micromark-extension-directive@1.1.0","_nodeVersion":"15.1.0","_npmVersion":"6.14.9","dist":{"integrity":"sha512-ctP99oO5EUzUcrHaj25+gGx/2NjPHOSZaJu64MNpY91mCfdj/UHy7SXinvrPHoUGBuHEoGhRItJLkgmKL6DWkg==","shasum":"6f95adbdafd051454ae3860ce6e152d025c212b9","tarball":"http://registry-npm.ywwl.com/micromark-extension-directive/download/micromark-extension-directive-1.1.0.tgz","fileCount":14,"unpackedSize":37776,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfz7VLCRA9TVsSAnZWagAAKxMP/270K7qtA5xjcHcb5H8l\nEdZ2ODMR3JzdEaQZWA3Jd1qon+XvJFMmSlXCk6s44G3qhVSCUpBIPHQLofHT\nmvCo0E0O/ledjOFW+ybAOyAW5zMRiGdqYrnG8H7BrmoD6iRGBwmar34rSc9D\nTF9ZzrLdr6T3dygEr7+3kkZMZb/jWFT4mwqKc04I6YAYO69vHcKBlxdz/HDT\nvaBQ1T0a6l4CUAfEnmNNhji7/qefZQpEF0CN49hhW7GYyxaQ0cVcaxijfkIj\ns5TiN1SAgviZT+9lrs44u4nCSe+1rzrBwVLMpYMS8y8w57ENedbdpMVOs8XN\nI3caursanSqegeYT9DEmkTHQnUJGOV8MuCAFu+2cJI/R7dwNW28AbxuRZ36r\nMroSru2CX77NzpdV/1mUq9WYf5CMPPYH4AI4IKr8QUpp+Wj5X1YwKWut1hI5\n5bME+8MHX7WQtdBN/8WX/0Kdx9a2XnTHoko+2+wPNTWvYDLU+89It98+1pWw\nKEdjjTfmPOgOyZinJxir/htD3Db8RqBbXYG3QlXyojGVhMI/hSftm0t564cO\nCNOhf/z86a3UyoKlkiybGTjevBT4gv761Mlbvkf9PTVFb2N5LProXO5pm1Ys\noCV2Onv7HSzPj7mSUmP+pwpOEM/nHp7gZe4CAI5jGip9GhBgmhqqFr2UHO6s\nB2wn\r\n=q3Aj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCuEYUbhYDwhdIROcl+Q8JXILnYWc36fUUwu6hU1eVddQIgcz8e0VDWkmLYPuwJchjZTjb3qO8bzoaqvp+mBVLTx2w="}],"size":9101,"noattachment":false,"key":"/micromark-extension-directive/-/micromark-extension-directive-1.1.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/micromark-extension-directive_1.1.0_1607447882411_0.3162071920488505"},"_hasShrinkwrap":false,"readme":"# micromark-extension-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[micromark][] extensions to support [directives][prop] (`:cite[smith04]` and\nsuch).\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When to use this](#when-to-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`directive()`](#directive)\n    *   [`directiveHtml(options?)`](#directivehtmloptions)\n    *   [`Directive`](#directive-1)\n    *   [`Handle`](#handle)\n    *   [`HtmlOptions`](#htmloptions)\n*   [Authoring](#authoring)\n*   [HTML](#html)\n*   [CSS](#css)\n*   [Syntax](#syntax)\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 contains two extensions that add support for directive syntax in\nmarkdown to [`micromark`][micromark].\n\n## When to use this\n\nThis project is useful when you want to solve the need for an infinite number\nof potential extensions to markdown in a single markdown-esque way.\n\nYou can use these extensions when you are working with [`micromark`][micromark]\nalready.\n\nWhen you need a syntax tree, you can combine this package with\n[`mdast-util-directive`][mdast-util-directive].\n\nAll these packages are used [`remark-directive`][remark-directive], which\nfocusses on making it easier to transform content by abstracting these\ninternals away.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n[npm][]:\n\n```sh\nnpm install micromark-extension-directive\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {directive, directiveHtml} from 'https://esm.sh/micromark-extension-directive@3'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {directive, directiveHtml} from 'https://esm.sh/micromark-extension-directive@3?bundle'\n</script>\n```\n\n## Use\n\nSay our document `example.md` contains:\n\n```markdown\nA lovely language know as :abbr[HTML]{title=\"HyperText Markup Language\"}.\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport fs from 'node:fs/promises'\nimport {micromark} from 'micromark'\nimport {directive, directiveHtml} from 'micromark-extension-directive'\n\nconst output = micromark(await fs.readFile('example.md'), {\n  extensions: [directive()],\n  htmlExtensions: [directiveHtml({abbr})]\n})\n\nconsole.log(output)\n\n/**\n * @this {import('micromark-util-types').CompileContext}\n * @type {import('micromark-extension-directive').Handle}\n * @returns {undefined}\n */\nfunction abbr(d) {\n  if (d.type !== 'textDirective') return false\n\n  this.tag('<abbr')\n\n  if (d.attributes && 'title' in d.attributes) {\n    this.tag(' title=\"' + this.encode(d.attributes.title) + '\"')\n  }\n\n  this.tag('>')\n  this.raw(d.label || '')\n  this.tag('</abbr>')\n}\n```\n\n…now running `node example.js` yields:\n\n```html\n<p>A lovely language know as <abbr title=\"HyperText Markup Language\">HTML</abbr>.</p>\n```\n\n## API\n\nThis package exports the identifiers [`directive`][api-directive] and\n[`directiveHtml`][api-directive-html].\nThere is no default export.\n\nThe export map supports the [`development` condition][development].\nRun `node --conditions development module.js` to get instrumented dev code.\nWithout this condition, production code is loaded.\n\n### `directive()`\n\nCreate an extension for `micromark` to enable directive syntax.\n\n###### Returns\n\nExtension for `micromark` that can be passed in `extensions`, to enable\ndirective syntax ([`Extension`][micromark-extension]).\n\n### `directiveHtml(options?)`\n\nCreate an extension for `micromark` to support directives when serializing to\nHTML.\n\n> 👉 **Note**: this uses KaTeX to render math.\n\n###### Parameters\n\n*   `options` ([`HtmlOptions`][api-html-options], default: `{}`)\n    — configuration\n\n###### Returns\n\nExtension for `micromark` that can be passed in `htmlExtensions`, to\nsupport directives when serializing to HTML\n([`HtmlExtension`][micromark-html-extension]).\n\n### `Directive`\n\nStructure representing a directive (TypeScript type).\n\n###### Fields\n\n*   `type` (`'containerDirective'`, `'leafDirective'`, or `'textDirective'`)\n    — kind\n*   `name` (`string`)\n    — name of directive\n*   `label` (`string` or `undefined`)\n    — compiled HTML content that was in `[brackets]`\n*   `attributes` (`Record<string, string>` or `undefined`)\n    — object w/ HTML attributes\n*   `content` (`string` or `undefined`)\n    — compiled HTML content inside container directive\n\n### `Handle`\n\nHandle a directive (TypeScript type).\n\n###### Parameters\n\n*   `this` ([`CompileContext`][micromark-compile-context])\n    — current context\n*   `directive` ([`Directive`][api-directive-type])\n    — directive\n\n###### Returns\n\nSignal whether the directive was handled (`boolean`, default: `true`).\nYield `false` to let the fallback (a special handle for `'*'`) handle it.\n\n### `HtmlOptions`\n\nConfiguration (TypeScript type).\n\n> 👉 **Note**: the special field `'*'` can be used to specify a fallback handle\n> to handle all otherwise unhandled directives.\n\n###### Type\n\n```ts\ntype HtmlOptions = Record<string, Handle>\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\nThe syntax looks like this:\n\n```markdown\nDirectives in text can form with a single colon, such as :cite[smith04].\nTheir syntax is `:name[label]{attributes}`.\n\nLeafs (block without content) can form by using two colons:\n\n::youtube[Video of a cat in a box]{vid=01ab2cd3efg}\n\nTheir syntax is `::name[label]{attributes}` on its own line.\n\nContainers (blocks with content) can form by using three colons:\n\n:::spoiler\nHe dies.\n:::\n\nThe `name` part is required.  The first character must be a letter, other\ncharacters can be alphanumerical, `-`, and `_`.\n`-` or `_` cannot end a name.\n\nThe `[label]` part is optional (`:x` and `:x[]` are equivalent)†.\nWhen used, it can include text constructs such as emphasis and so on: `x[a *b*\nc]`.\n\nThe `{attributes}` part is optional (`:x` and `:x{}` are equivalent)†.\nWhen used, it is handled like HTML attributes, such as that `{a}`, `{a=\"\"}`,\n, `{a=''}` but also `{a=b}`, `{a=\"b\"}`, and `{a='b'}` are equivalent.\nShortcuts are available for `id=` (`{#readme}` for `{id=readme}`) and\n`class` (`{.big}` for `{class=big}`).\nWhen multiple ids are found, the last is used; when multiple classes are found,\nthey are combined: `{.red class=green .blue}` is equivalent to\n`{.red .green .blue}` and `{class=\"red green blue\"}`.\n\n† there is one case where a name must be followed by an empty label or empty\nattributes: a *text* directive that only has a name, cannot be followed by a\ncolon. So, `:red:` doesn’t work. Use either `:red[]` or `:red{}` instead.\nThe reason for this is to allow GitHub emoji (gemoji) and directives to coexist.\n\nContainers can be nested by using more colons outside:\n\n::::spoiler\nHe dies.\n\n:::spoiler\nShe is born.\n:::\n::::\n\nThe closing fence must include the same or more colons as the opening.\nIf no closing is found, the container runs to the end of its parent container\n(block quote, list item, document, or other container).\n\n::::spoiler\nThese three are not enough to close\n:::\nSo this line is also part of the container.\n```\n\nNote that while other implementations are sometimes loose in what they allow,\nthis implementation mimics CommonMark as closely as possible:\n\n*   Whitespace is not allowed between colons and name (~~`: a`~~), name and\n    label (~~`:a []`~~), name and attributes (~~`:a {}`~~), or label and\n    attributes (~~`:a[] {}`~~) — because it’s not allowed in links either\n    (~~`[] ()`~~)\n*   No trailing colons allowed on the opening fence of a container\n    (~~`:::a:::`~~) — because it’s not allowed in fenced code either\n*   The label and attributes in a leaf or container cannot include line endings\n    (~~`::a[b\\nc]`~~) — because it’s not allowed in fenced code either\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Directive`][api-directive-type],\n[`Handle`][api-handle], and [`HtmlOptions`][api-html-options].\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,\n`micromark-extension-directive@^3`, compatible with Node.js 16.\n\nThis package works with `micromark` version `3` and later.\n\n## Security\n\nThis package is safe assuming that you write safe handlers.\nAny vulnerability in your code could open you to a\n[cross-site scripting (XSS)][xss] attack.\n\n## Related\n\n*   [`remark-directive`][remark-directive]\n    — remark plugin to support directives\n*   [`mdast-util-directive`][mdast-util-directive]\n    — mdast utility to support directives\n\n## Contribute\n\nSee [`contributing.md` in `micromark/.github`][contributing] for ways to get\nstarted.\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/micromark/micromark-extension-directive/workflows/main/badge.svg\n\n[build]: https://github.com/micromark/micromark-extension-directive/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-directive.svg\n\n[coverage]: https://codecov.io/github/micromark/micromark-extension-directive\n\n[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-directive.svg\n\n[downloads]: https://www.npmjs.com/package/micromark-extension-directive\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-directive\n\n[size]: https://bundlejs.com/?q=micromark-extension-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/micromark/micromark/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[contributing]: https://github.com/micromark/.github/blob/main/contributing.md\n\n[support]: https://github.com/micromark/.github/blob/main/support.md\n\n[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions\n\n[micromark]: https://github.com/micromark/micromark\n\n[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension\n\n[micromark-extension]: https://github.com/micromark/micromark#syntaxextension\n\n[micromark-compile-context]: https://github.com/micromark/micromark/blob/41e3c4c/packages/micromark-util-types/index.js#L457\n\n[mdast-util-directive]: https://github.com/syntax-tree/mdast-util-directive\n\n[remark-directive]: https://github.com/remarkjs/remark-directive\n\n[prop]: https://talk.commonmark.org/t/generic-directives-plugins-syntax/444\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[api-directive]: #directive\n\n[api-directive-html]: #directivehtmloptions\n\n[api-directive-type]: #directive-1\n\n[api-handle]: #handle\n\n[api-html-options]: #htmloptions\n","publish_time":1607447882597,"_cnpm_publish_time":1607447882597,"dist-tags":{"latest":"4.0.0"}}