![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
hast-util-from-parse5
Advanced tools
Readme
hast utility to transform Parse5’s AST to a hast tree.
npm:
npm install hast-util-from-parse5
Say we have the following file, example.html
:
<!doctype html><title>Hello!</title><h1 id="world">World!<!--after-->
And our script, example.js
, looks as follows:
var vfile = require('to-vfile')
var parse5 = require('parse5')
var inspect = require('unist-util-inspect')
var fromParse5 = require('hast-util-from-parse5')
var doc = vfile.readSync('example.html')
var ast = parse5.parse(String(doc), {sourceCodeLocationInfo: true})
var hast = fromParse5(ast, doc)
console.log(inspect(hast))
Now, running node example
yields:
root[2] (1:1-2:1, 0-70) [data={"quirksMode":false}]
├─ doctype (1:1-1:16, 0-15) [name="html"]
└─ element[2] [tagName="html"]
├─ element[1] [tagName="head"]
│ └─ element[1] (1:16-1:37, 15-36) [tagName="title"]
│ └─ text: "Hello!" (1:23-1:29, 22-28)
└─ element[1] [tagName="body"]
└─ element[3] (1:37-2:1, 36-70) [tagName="h1"][properties={"id":"world"}]
├─ text: "World!" (1:52-1:58, 51-57)
├─ comment: "after" (1:58-1:70, 57-69)
└─ text: "\n" (1:70-2:1, 69-70)
fromParse5(ast[, options])
Transform Parse5’s AST to a hast tree.
options
If options
is a VFile
, it’s treated as {file: options}
.
options.space
Whether the root of the tree is in the 'html'
or 'svg'
space (enum, 'svg'
or 'html'
, default: 'html'
).
If an element in with the SVG namespace is found in ast
, fromParse5
automatically switches to the SVG space when entering the element, and switches
back when leaving.
options.file
VFile
, used to add positional information
to nodes.
If given, the file should have the original HTML source as its
contents.
options.verbose
Whether to add extra positional information about starting tags, closing tags,
and attributes to elements (boolean
, default: false
).
Note: not used without file
.
For the following HTML:
<img src="http://example.com/fav.ico" alt="foo" title="bar">
The verbose info would looks as follows:
{
type: 'element',
tagName: 'img',
properties: {src: 'http://example.com/fav.ico', alt: 'foo', title: 'bar'},
children: [],
data: {
position: {
opening: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 61, offset: 60}
},
closing: null,
properties: {
src: {
start: {line: 1, column: 6, offset: 5},
end: {line: 1, column: 38, offset: 37}
},
alt: {
start: {line: 1, column: 39, offset: 38},
end: {line: 1, column: 48, offset: 47}
},
title: {
start: {line: 1, column: 49, offset: 48},
end: {line: 1, column: 60, offset: 59}
}
}
}
},
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 61, offset: 60}
}
}
Use of hast-util-from-parse5
can open you up to a
cross-site scripting (XSS) attack if Parse5’s AST is unsafe.
hast-util-to-parse5
— transform hast to Parse5’s ASThast-util-to-nlcst
— transform hast to nlcsthast-util-to-mdast
— transform hast to mdasthast-util-to-xast
— transform hast to xastmdast-util-to-hast
— transform mdast to hastmdast-util-to-nlcst
— transform mdast to nlcstSee 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 from Parse5’s AST
The npm package hast-util-from-parse5 receives a total of 2,922,072 weekly downloads. As such, hast-util-from-parse5 popularity was classified as popular.
We found that hast-util-from-parse5 demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.