{"name":"hast-util-to-nlcst","version":"1.2.1","description":"Transform HAST to NLCST","license":"MIT","keywords":["hast","rehype","nlcst","retext","html","natural","language"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-to-nlcst.git"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-to-nlcst/issues"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"http://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"http://wooorm.com"}],"files":["index.js"],"dependencies":{"hast-util-embedded":"^1.0.0","hast-util-is-element":"^1.0.0","hast-util-phrasing":"^1.0.0","hast-util-to-string":"^1.0.0","hast-util-whitespace":"^1.0.0","nlcst-to-string":"^2.0.0","unist-util-position":"^3.0.0","vfile-location":"^2.0.0"},"devDependencies":{"browserify":"^14.0.0","esmangle":"^1.0.1","is-hidden":"^1.0.1","negate":"^1.0.0","nyc":"^11.0.0","parse-dutch":"^4.0.0","parse-english":"^4.0.0","parse-latin":"^4.0.0","rehype":"^5.0.0","remark-cli":"^4.0.0","remark-preset-wooorm":"^3.0.0","tape":"^4.0.0","vfile":"^2.0.0","xo":"^0.18.0"},"scripts":{"build-md":"remark . -qfo","build-bundle":"browserify index.js --bare -s hastUtilToNLCST > hast-util-to-nlcst.js","build-mangle":"esmangle hast-util-to-nlcst.js > hast-util-to-nlcst.min.js","build":"npm run build-md && npm run build-bundle && npm run build-mangle","lint":"xo","test-api":"node test","test-coverage":"nyc --reporter lcov tape test/index.js","test":"npm run build && npm run lint && npm run test-coverage"},"nyc":{"check-coverage":true,"lines":100,"functions":100,"branches":100},"xo":{"space":true,"esnext":false,"rules":{"max-params":"off"},"ignores":["hast-util-to-nlcst.js"]},"remarkConfig":{"plugins":["preset-wooorm"]},"gitHead":"f82664a57bcfe9ff2850abe81de517a59f4a6675","homepage":"https://github.com/syntax-tree/hast-util-to-nlcst#readme","_id":"hast-util-to-nlcst@1.2.1","_npmVersion":"5.0.0","_nodeVersion":"8.0.0","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"dist":{"integrity":"sha512-xS7zkMDv1dsU5QaJxMBXXwwIAnOzM46qXLjFHfCcYg4ii8Q8C8PqkiTp8RKfGOTiRnXePQElzth2ollLEXDHSQ==","shasum":"e250ba8353f0f0a5a32b2df8e151565e8d00603b","tarball":"http://registry-npm.ywwl.com/hast-util-to-nlcst/download/hast-util-to-nlcst-1.2.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBmzB3EZ49PFNpXH7Oq8LgUYvBa6kQgGE8LfRmbvreKNAiAxzWJZN+w7LfTLAVXdYxcCsgLeghL8F5AFSmyu+hpVDg=="}],"size":4904,"noattachment":false,"key":"/hast-util-to-nlcst/-/hast-util-to-nlcst-1.2.1.tgz"},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-to-nlcst-1.2.1.tgz_1500920797730_0.5152161621954292"},"directories":{},"readme":"# hast-util-to-nlcst\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[hast][] utility to transform to [nlcst][].\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    *   [`toNlcst(tree, file, Parser)`](#tonlcsttree-file-parser)\n    *   [`ParserConstructor`](#parserconstructor)\n    *   [`ParserInstance`](#parserinstance)\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 takes a [hast][] (HTML) syntax tree as input and\nturns it into [nlcst][] (natural language).\n\n## When should I use this?\n\nThis project is useful when you want to deal with ASTs and inspect the natural\nlanguage inside HTML.\nUnfortunately, there is no way yet to apply changes to the nlcst back into\nhast.\n\nThe mdast utility [`mdast-util-to-nlcst`][mdast-util-to-nlcst] does the same but\nuses a markdown tree as input.\n\nThe rehype plugin [`rehype-retext`][rehype-retext] wraps this utility to do the\nsame at a higher-level (easier) abstraction.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hast-util-to-nlcst\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {toNlcst} from 'https://esm.sh/hast-util-to-nlcst@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {toNlcst} from 'https://esm.sh/hast-util-to-nlcst@4?bundle'\n</script>\n```\n\n## Use\n\nSay our document `example.html` contains:\n\n```html\n<article>\n  Implicit.\n  <h1>Explicit: <strong>foo</strong>s-ball</h1>\n  <pre><code class=\"language-foo\">bar()</code></pre>\n</article>\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport {fromHtml} from 'hast-util-from-html'\nimport {toNlcst} from 'hast-util-to-nlcst'\nimport {ParseEnglish} from 'parse-english'\nimport {read} from 'to-vfile'\nimport {inspect} from 'unist-util-inspect'\n\nconst file = await read('example.html')\nconst tree = fromHtml(file)\n\nconsole.log(inspect(toNlcst(tree, file, ParseEnglish)))\n```\n\n…now running `node example.js` yields (positional info removed for brevity):\n\n```txt\nRootNode[2] (1:1-6:1, 0-134)\n├─0 ParagraphNode[3] (1:10-3:3, 9-24)\n│   ├─0 WhiteSpaceNode \"\\n  \" (1:10-2:3, 9-12)\n│   ├─1 SentenceNode[2] (2:3-2:12, 12-21)\n│   │   ├─0 WordNode[1] (2:3-2:11, 12-20)\n│   │   │   └─0 TextNode \"Implicit\" (2:3-2:11, 12-20)\n│   │   └─1 PunctuationNode \".\" (2:11-2:12, 20-21)\n│   └─2 WhiteSpaceNode \"\\n  \" (2:12-3:3, 21-24)\n└─1 ParagraphNode[1] (3:7-3:43, 28-64)\n    └─0 SentenceNode[4] (3:7-3:43, 28-64)\n        ├─0 WordNode[1] (3:7-3:15, 28-36)\n        │   └─0 TextNode \"Explicit\" (3:7-3:15, 28-36)\n        ├─1 PunctuationNode \":\" (3:15-3:16, 36-37)\n        ├─2 WhiteSpaceNode \" \" (3:16-3:17, 37-38)\n        └─3 WordNode[4] (3:25-3:43, 46-64)\n            ├─0 TextNode \"foo\" (3:25-3:28, 46-49)\n            ├─1 TextNode \"s\" (3:37-3:38, 58-59)\n            ├─2 PunctuationNode \"-\" (3:38-3:39, 59-60)\n            └─3 TextNode \"ball\" (3:39-3:43, 60-64)\n```\n\n## API\n\nThis package exports the identifier [`toNlcst`][api-to-nlcst].\nThere is no default export.\n\n### `toNlcst(tree, file, Parser)`\n\nTurn a hast tree into an nlcst tree.\n\n> 👉 **Note**: `tree` must have positional info and `file` must be a `VFile`\n> corresponding to `tree`.\n\n##### Parameters\n\n*   `tree` ([`HastNode`][hast-node])\n    — hast tree to transform\n*   `file` ([`VFile`][vfile])\n    — virtual file\n*   `Parser` ([`ParserConstructor`][api-parser-constructor] or\n    [`ParserInstance`][api-parser-instance])\n    — parser to use.\n\n##### Returns\n\n[`NlcstNode`][nlcst-node].\n\n##### Notes\n\n###### Implied paragraphs\n\nThe algorithm supports implicit and explicit paragraphs, such as:\n\n```html\n<article>\n  An implicit paragraph.\n  <h1>An explicit paragraph.</h1>\n</article>\n```\n\nOverlapping paragraphs are also supported (see the tests or the HTML spec for\nmore info).\n\n###### Ignored nodes\n\nSome elements are ignored and their content will not be present in\n**[nlcst][]**: `<script>`, `<style>`, `<svg>`, `<math>`, `<del>`.\n\nTo ignore other elements, add a `data-nlcst` attribute with a value of `ignore`:\n\n```html\n<p>This is <span data-nlcst=\"ignore\">hidden</span>.</p>\n<p data-nlcst=\"ignore\">Completely hidden.</p>\n```\n\n###### Source nodes\n\n`<code>` elements are mapped to [`Source`][nlcst-source] nodes in\n**[nlcst][]**.\n\nTo mark other elements as source, add a `data-nlcst` attribute with a value\nof `source`:\n\n```html\n<p>This is <span data-nlcst=\"source\">marked as source</span>.</p>\n<p data-nlcst=\"source\">Completely marked.</p>\n```\n\n### `ParserConstructor`\n\nCreate a new parser (TypeScript type).\n\n###### Type\n\n```ts\ntype ParserConstructor = new () => ParserInstance\n```\n\n### `ParserInstance`\n\nnlcst parser (TypeScript type).\n\nFor example, [`parse-dutch`][parse-dutch], [`parse-english`][parse-english], or\n[`parse-latin`][parse-latin].\n\n###### Type\n\n```ts\ntype ParserInstance = {\n  parse(value?: string | null | undefined): NlcstRoot\n  tokenize(value?: string | null | undefined): Array<NlcstSentenceContent>\n  tokenizeParagraph(value?: string | null | undefined): NlcstParagraph\n  tokenizeParagraphPlugins: Array<(node: NlcstParagraph) => undefined | void>\n  tokenizeSentencePlugins: Array<(node: NlcstSentence) => undefined | void>\n}\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional types [`ParserConstructor`][api-parser-constructor]\nand [`ParserInstance`][api-parser-instance].\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, `hast-util-to-nlcst@^4`,\ncompatible with Node.js 16.\n\n## Security\n\n`hast-util-to-nlcst` does not change the original syntax tree so there are no\nopenings for [cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n*   [`mdast-util-to-nlcst`](https://github.com/syntax-tree/mdast-util-to-nlcst)\n    — transform mdast to nlcst\n*   [`hast-util-to-mdast`](https://github.com/syntax-tree/hast-util-to-mdast)\n    — transform hast to mdast\n*   [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast)\n    — transform hast to xast\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/hast-util-to-nlcst/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-to-nlcst/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-nlcst.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-nlcst\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-nlcst.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-to-nlcst\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-to-nlcst\n\n[size]: https://bundlejs.com/?q=hast-util-to-nlcst\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[rehype-retext]: https://github.com/rehypejs/rehype-retext\n\n[vfile]: https://github.com/vfile/vfile\n\n[hast]: https://github.com/syntax-tree/hast\n\n[hast-node]: https://github.com/syntax-tree/hast#nodes\n\n[nlcst]: https://github.com/syntax-tree/nlcst\n\n[nlcst-node]: https://github.com/syntax-tree/nlcst#nodes\n\n[nlcst-source]: https://github.com/syntax-tree/nlcst#source\n\n[mdast-util-to-nlcst]: https://github.com/syntax-tree/mdast-util-to-nlcst\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[parse-english]: https://github.com/wooorm/parse-english\n\n[parse-latin]: https://github.com/wooorm/parse-latin\n\n[parse-dutch]: https://github.com/wooorm/parse-dutch\n\n[api-to-nlcst]: #tonlcsttree-file-parser\n\n[api-parser-constructor]: #parserconstructor\n\n[api-parser-instance]: #parserinstance\n","publish_time":1500920798642,"_cnpm_publish_time":1500920798642,"dist-tags":{"latest":"4.0.0"}}