{"name":"mdast-zone","version":"0.2.3","description":"HTML comments as ranges or markers in mdast","license":"MIT","keywords":["html","comment","comments","zone","range","marker","mdast"],"dependencies":{"mdast-util-visit":"^0.1.1"},"repository":{"type":"git","url":"git+https://github.com/wooorm/mdast-zone.git"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com"},"files":["index.js"],"devDependencies":{"browserify":"^10.0.0","eslint":"^0.24.0","esmangle":"^1.0.0","istanbul":"^0.3.0","jscs":"^1.0.0","jscs-jsdoc":"^1.0.0","mdast":"^0.26.0","mdast-github":"^0.3.0","mdast-lint":"^0.4.0","mdast-toc":"^0.5.1","mdast-usage":"^0.3.0","mdast-yaml-config":"^0.2.0","mocha":"^2.0.0"},"scripts":{"test-api":"mocha --check-leaks test/index.js","test-coveralls":"istanbul cover _mocha --report lcovonly -- --check-leaks test/index.js","test-coverage":"istanbul cover _mocha -- test/index.js","test-travis":"npm run test-coveralls","test":"npm run test-api","lint-api":"eslint .","lint-style":"jscs --reporter inline .","lint":"npm run lint-api && npm run lint-style","make":"npm run lint && npm run test-coverage","bundle":"browserify --no-builtins -u esprima index.js -s mdastZone > mdast-zone.js","postbundle":"esmangle mdast-zone.js > mdast-zone.min.js","build-md":"mdast . --output --quiet","build":"npm run build-md && npm run bundle"},"gitHead":"e31d94bf35bf9c008d6f2313e4404bbeb07acd93","bugs":{"url":"https://github.com/wooorm/mdast-zone/issues"},"homepage":"https://github.com/wooorm/mdast-zone#readme","_id":"mdast-zone@0.2.3","_shasum":"3b40c9ec6eb51620dd7cdc9e912f2d79610fd955","_from":".","_npmVersion":"2.11.3","_nodeVersion":"2.3.3","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"dist":{"shasum":"3b40c9ec6eb51620dd7cdc9e912f2d79610fd955","tarball":"http://registry-npm.ywwl.com/mdast-zone/download/mdast-zone-0.2.3.tgz","integrity":"sha512-5xnxu2lL77yH2wjllc0VPLqT865fXe12mcD4On9Ec7lp+BLOwmCOkQSAKBdEEwlwMgOdC1SgNy7MgtoiV/+wlw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAbNs7h7KZGGv7UfxdaISWRzwWYw1geniILXIYgTrpJEAiBljLLfJaWPTi+NxLGI9oDSgfNbhgOU8X3KTckneMHZLg=="}],"size":5648,"noattachment":false,"key":"/mdast-zone/-/mdast-zone-0.2.3.tgz"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"directories":{},"readme":"# mdast-zone\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[mdast][] utility to find two comments and replace the content in them.\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  * [`zone(tree, name, handler)`](#zonetree-name-handler)\n  * [`Handler`](#handler)\n  * [`Info`](#info)\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 utility that lets you find certain comments, then takes the\ncontent between them, and calls a given handler with the result, so that you can\nchange or replace things.\n\n## When should I use this?\n\nThis utility is typically useful when you have certain sections that can be\ngenerated.\nComments are a hidden part of markdown, so they can be used as processing\ninstructions.\nYou can use those comments to define what content to change or replace.\n\nA similar package, [`mdast-util-heading-range`][mdast-util-heading-range], does\nthe same but uses a heading to mark the start and end of sections.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-zone\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {zone} from 'https://esm.sh/mdast-zone@6'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {zone} from 'https://esm.sh/mdast-zone@6?bundle'\n</script>\n```\n\n## Use\n\nSay we have the following file, `example.md`:\n\n```markdown\n<!--foo start-->\n\nFoo\n\n<!--foo end-->\n```\n\n…and a module `example.js`:\n\n```js\nimport {zone} from 'mdast-zone'\nimport {remark} from 'remark'\nimport {read} from 'to-vfile'\n\nconst file = await remark()\n  .use(myPluginThatReplacesFoo)\n  .process(await read('example.md'))\n\nconsole.log(String(file))\n\n/** @type {import('unified').Plugin<[], import('mdast').Root>} */\nfunction myPluginThatReplacesFoo() {\n  return function (tree) {\n    zone(tree, 'foo', function (start, nodes, end) {\n      return [\n        start,\n        {type: 'paragraph', children: [{type: 'text', value: 'Bar.'}]},\n        end\n      ]\n    })\n  }\n}\n```\n\n…now running `node example.js` yields:\n\n```markdown\n<!--foo start-->\n\nBar.\n\n<!--foo end-->\n```\n\n## API\n\nThis package exports the identifier [`zone`][api-zone].\nThere is no default export.\n\n### `zone(tree, name, handler)`\n\nSearch `tree` for a start and end comments matching `name` and change their\n“section” with `handler`.\n\n###### Parameters\n\n* `tree` ([`Node`][node])\n  — tree to change\n* `name` (`string`)\n  — comment name to look for\n* `handler` ([`Handler`][api-handler])\n  — handle a section\n\n###### Returns\n\nNothing (`undefined`).\n\n### `Handler`\n\nCallback called when a section is found (TypeScript type).\n\n###### Parameters\n\n* `start` ([`Node`][node])\n  — start of section\n* `nodes` ([`Array<Node>`][node])\n  — nodes between `start` and `end`\n* `end` ([`Node`][node])\n  — end of section\n* `info` ([`Info`][api-info])\n  — extra info\n\n###### Returns\n\nResults (`Array<Node | null | undefined>`, optional).\n\nIf nothing is returned, nothing will be changed.\nIf an array of nodes (can include `null` and `undefined`) is returned, the\noriginal section will be replaced by those nodes.\n\n### `Info`\n\nExtra info (TypeScript type).\n\n###### Fields\n\n* `parent` ([`Node`][node])\n  — parent of the section\n* `start` (`number`)\n  — index of `start` in `parent`\n* `end` (`number`)\n  — index of `end` in `parent`\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`Handler`][api-handler] and\n[`Info`][api-info].\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, `mdast-zone@^6`,\ncompatible with Node.js 16.\n\n## Security\n\nImproper use of `handler` can open you up to a [cross-site scripting (XSS)][xss]\nattack as the value it returns is injected into the syntax tree.\nThis can become a problem if the tree is later transformed to **[hast][]**.\nThe following example shows how a script is injected that could run when loaded\nin a browser.\n\n```js\nfunction handler(start, nodes, end) {\n  return [start, {type: 'html', value: '<script>alert(1)</script>'}, end]\n}\n```\n\nYields:\n\n```markdown\n<!--foo start-->\n\n<script>alert(1)</script>\n\n<!--foo end-->\n```\n\nEither do not use user input or use [`hast-util-santize`][hast-util-sanitize].\n\n## Related\n\n* [`mdast-util-heading-range`](https://github.com/syntax-tree/mdast-util-heading-range)\n  — similar but uses headings to mark sections\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to 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/syntax-tree/mdast-zone/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-zone/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-zone.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-zone\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-zone.svg\n\n[downloads]: https://www.npmjs.com/package/mdast-zone\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-zone\n\n[size]: https://bundlejs.com/?q=mdast-zone\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/syntax-tree/unist/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[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[node]: https://github.com/syntax-tree/mdast#nodes\n\n[mdast-util-heading-range]: https://github.com/syntax-tree/mdast-util-heading-range\n\n[hast]: https://github.com/syntax-tree/hast\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[api-zone]: #zonetree-name-handler\n\n[api-handler]: #handler\n\n[api-info]: #info\n","publish_time":1436738168330,"_cnpm_publish_time":1436738168330,"dist-tags":{"latest":"6.1.0","next":"2.0.0-alpha.1"}}