Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
hast-util-to-nlcst
Advanced tools
hast utility to transform to nlcst.
Note: You probably want to use
rehype-retext
.
This package is ESM only:
Node 12+ is needed to use it and it must be import
ed instead of require
d.
npm:
npm install hast-util-to-nlcst
Say we have the following example.html
:
<article>
Implicit.
<h1>Explicit: <strong>foo</strong>s-ball</h1>
<pre><code class="language-foo">bar()</code></pre>
</article>
…and next to it, index.js
:
import {readSync} from 'to-vfile'
import {inspect} from 'unist-util-inspect'
import {toNlcst} from 'hast-util-to-nlcst'
import {ParseEnglish} from 'parse-english'
import rehype from 'rehype'
const file = readSync('example.html')
const tree = rehype().parse(file)
console.log(inspect(toNlcst(tree, file, ParseEnglish)))
Which, when running, yields:
RootNode[2] (1:1-6:1, 0-134)
├─ ParagraphNode[3] (1:10-3:3, 9-24)
│ ├─ WhiteSpaceNode: "\n " (1:10-2:3, 9-12)
│ ├─ SentenceNode[2] (2:3-2:12, 12-21)
│ │ ├─ WordNode[1] (2:3-2:11, 12-20)
│ │ │ └─ TextNode: "Implicit" (2:3-2:11, 12-20)
│ │ └─ PunctuationNode: "." (2:11-2:12, 20-21)
│ └─ WhiteSpaceNode: "\n " (2:12-3:3, 21-24)
└─ ParagraphNode[1] (3:7-3:43, 28-64)
└─ SentenceNode[4] (3:7-3:43, 28-64)
├─ WordNode[1] (3:7-3:15, 28-36)
│ └─ TextNode: "Explicit" (3:7-3:15, 28-36)
├─ PunctuationNode: ":" (3:15-3:16, 36-37)
├─ WhiteSpaceNode: " " (3:16-3:17, 37-38)
└─ WordNode[4] (3:25-3:43, 46-64)
├─ TextNode: "foo" (3:25-3:28, 46-49)
├─ TextNode: "s" (3:37-3:38, 58-59)
├─ PunctuationNode: "-" (3:38-3:39, 59-60)
└─ TextNode: "ball" (3:39-3:43, 60-64)
This package exports the following identifiers: toNlcst
.
There is no default export.
toNlcst(tree, file, Parser)
Transform the given hast tree to nlcst.
tree
(HastNode
)
— Tree with positional info
(HastNode
)file
(VFile
)
— Virtual fileparser
(Function
)
— nlcst parser, such as parse-english
,
parse-dutch
, or parse-latin
The algorithm supports implicit and explicit paragraphs, such as:
<article>
An implicit paragraph.
<h1>An explicit paragraph.</h1>
</article>
Overlapping paragraphs are also supported (see the tests or the HTML spec for more info).
Some elements are ignored and their content will not be present in
nlcst: <script>
, <style>
, <svg>
, <math>
, <del>
.
To ignore other elements, add a data-nlcst
attribute with a value of ignore
:
<p>This is <span data-nlcst="ignore">hidden</span>.</p>
<p data-nlcst="ignore">Completely hidden.</p>
<code>
elements are mapped to Source
nodes in nlcst.
To mark other elements as source, add a data-nlcst
attribute with a value
of source
:
<p>This is <span data-nlcst="source">marked as source</span>.</p>
<p data-nlcst="source">Completely marked.</p>
hast-util-to-nlcst
does not change the original syntax tree so there are no
openings for cross-site scripting (XSS) attacks.
mdast-util-to-nlcst
— transform mdast to nlcstmdast-util-to-hast
— transform mdast to hasthast-util-to-mdast
— transform hast to mdasthast-util-to-xast
— transform hast to xasthast-util-sanitize
— sanitize hast nodesSee contributing.md
in syntax-tree/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
hast utility to transform to nlcst
The npm package hast-util-to-nlcst receives a total of 0 weekly downloads. As such, hast-util-to-nlcst popularity was classified as not popular.
We found that hast-util-to-nlcst demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.