{"name":"mdast-zone","version":"5.0.0","description":"mdast utility to treat HTML comments as ranges or markers","license":"MIT","keywords":["unist","mdast","mdast-util","util","utility","html","comment","comments","zone","range","marker"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/mdast-zone.git"},"bugs":{"url":"https://github.com/syntax-tree/mdast-zone/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.3","@types/unist":"^2.0.3","mdast-comment-marker":"^2.0.0","unist-util-visit":"^3.0.0"},"devDependencies":{"@types/tape":"^4.0.0","c8":"^7.0.0","is-hidden":"^2.0.0","prettier":"^2.0.0","remark":"^13.0.0","remark-cli":"^9.0.0","remark-preset-wooorm":"^8.0.0","rimraf":"^3.0.0","tape":"^5.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","xo":"^0.39.0"},"scripts":{"prepack":"npm run build && npm run format","build":"rimraf \"{test/**,}*.d.ts\" && tsc && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node test/index.js","test-coverage":"c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js","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,"rules":{"capitalized-comments":"off","no-var":"off","prefer-arrow-callback":"off"}},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true},"gitHead":"395e497bc39b6ef7041e4a1a39b20e7a90c13471","homepage":"https://github.com/syntax-tree/mdast-zone#readme","_id":"mdast-zone@5.0.0","_nodeVersion":"15.11.0","_npmVersion":"7.10.0","dist":{"integrity":"sha512-xIKqBpSbvVJIsGquLOdtPl0iCmA0moAGrAU/rT4fMPSSNJXNlr5bhp7fhqN8HmcNhqnvbNCkojQAnzkGzvUMyA==","shasum":"b143ed560a20670eb66fb818d162a2b4fc39e798","tarball":"http://registry-npm.ywwl.com/mdast-zone/download/mdast-zone-5.0.0.tgz","fileCount":5,"unpackedSize":10749,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJggxYYCRA9TVsSAnZWagAAwvsP/0E+uQsxDyqCj98LqYdz\nC+3x9XVYU9hrisZIg4AZFHwnfDOKRcCHu2Ro5QI8DcM5rocKofAF7ymHLAuT\nyyoC+cl5puypodN3i6leaJTrGE4cPJ1dVvRiso2/oDtw+9BC9OukYZMKWy5f\nix/3qcksPQQXrP466G+mhr9/D6ChGZ7U1JvCZznYAc9yVO2FmZdHF1imvLDo\n/d3KMiRfYzPxpIbhUW9fSd4fC0Z0/gw6gcULIWVOjjkag5+ybaHky2zrtu+y\nRhv1F7DD4xjOjB6pgV37Pq6dR4eB2E6N0p/0jLDcILKz7sMZMmjg5qYVWJG0\nMP/vOVnZPdUPf79CYUxjQO/ASwhUIhK1svu0HEKiiEdELnwtH7iy1jcTdw6F\nEfZJxxrYaL/o3ZEISMF72xHrioat0hEnjIg/LGxpMbO6EZ/UJoRHMj7WogI2\n2kvEDvAW1KIsw7UcAmgOIGvfe06wmN/2e2HmCvK+L3W+DRElG70f0RTsi2mV\nHN81VESgW0XFJ8HLtcONrT0MidxccQIk1EP+MvqUGZGRefiZ36VZ1RM/DH0S\nyJbcbaaFwuoe+kdYpXvDNPa8DX98MEByeXhyg2r90xv15ZXSui0+olY61gqs\n0e9lVpmwNLYquMU/wi4msNezMd5TgUQoc+LlmPjZNgRyAV7rR1z48lOjY10V\nKoLI\r\n=BnDK\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQClx+nKP8umhERuXP/HQVH67e6BaPLwDHSmq3/EMqjvwwIhAIpZtirNwt9ULbXZelw74kPviw72GffmzutN2L9I7W/1"}],"size":4356,"noattachment":false,"key":"/mdast-zone/-/mdast-zone-5.0.0.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mdast-zone_5.0.0_1619203608156_0.75386650596529"},"_hasShrinkwrap":false,"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":1619203608355,"_cnpm_publish_time":1619203608355,"dist-tags":{"latest":"6.1.0","next":"2.0.0-alpha.1"}}