Gathering detailed insights and metrics for mdast-zone
Gathering detailed insights and metrics for mdast-zone
Gathering detailed insights and metrics for mdast-zone
Gathering detailed insights and metrics for mdast-zone
utility to treat HTML comments as ranges or markers in mdast
npm install mdast-zone
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
16 Stars
167 Commits
2 Forks
9 Watchers
1 Branches
12 Contributors
Updated on Apr 09, 2025
Latest Version
6.1.0
Package Id
mdast-zone@6.1.0
Unpacked Size
15.03 kB
Size
5.57 kB
File Count
7
NPM Version
10.2.3
Node Version
21.2.0
Published on
Dec 04, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
mdast utility to find two comments and replace the content in them.
This package is a utility that lets you find certain comments, then takes the content between them, and calls a given handler with the result, so that you can change or replace things.
This utility is typically useful when you have certain sections that can be generated. Comments are a hidden part of markdown, so they can be used as processing instructions. You can use those comments to define what content to change or replace.
A similar package, mdast-util-heading-range
, does
the same but uses a heading to mark the start and end of sections.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install mdast-zone
In Deno with esm.sh
:
1import {zone} from 'https://esm.sh/mdast-zone@6'
In browsers with esm.sh
:
1<script type="module"> 2 import {zone} from 'https://esm.sh/mdast-zone@6?bundle' 3</script>
Say we have the following file, example.md
:
1<!--foo start--> 2 3Foo 4 5<!--foo end-->
…and a module example.js
:
1import {zone} from 'mdast-zone' 2import {remark} from 'remark' 3import {read} from 'to-vfile' 4 5const file = await remark() 6 .use(myPluginThatReplacesFoo) 7 .process(await read('example.md')) 8 9console.log(String(file)) 10 11/** @type {import('unified').Plugin<[], import('mdast').Root>} */ 12function myPluginThatReplacesFoo() { 13 return function (tree) { 14 zone(tree, 'foo', function (start, nodes, end) { 15 return [ 16 start, 17 {type: 'paragraph', children: [{type: 'text', value: 'Bar.'}]}, 18 end 19 ] 20 }) 21 } 22}
…now running node example.js
yields:
1<!--foo start--> 2 3Bar. 4 5<!--foo end-->
This package exports the identifier zone
.
There is no default export.
zone(tree, name, handler)
Search tree
for a start and end comments matching name
and change their
“section” with handler
.
tree
(Node
)
— tree to changename
(string
)
— comment name to look forhandler
(Handler
)
— handle a sectionNothing (undefined
).
Handler
Callback called when a section is found (TypeScript type).
start
(Node
)
— start of sectionnodes
(Array<Node>
)
— nodes between start
and end
end
(Node
)
— end of sectioninfo
(Info
)
— extra infoResults (Array<Node | null | undefined>
, optional).
If nothing is returned, nothing will be changed.
If an array of nodes (can include null
and undefined
) is returned, the
original section will be replaced by those nodes.
Info
Extra info (TypeScript type).
parent
(Node
)
— parent of the sectionstart
(number
)
— index of start
in parent
end
(number
)
— index of end
in parent
This package is fully typed with TypeScript.
It exports the additional types Handler
and
Info
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, mdast-zone@^6
,
compatible with Node.js 16.
Improper use of handler
can open you up to a cross-site scripting (XSS)
attack as the value it returns is injected into the syntax tree.
This can become a problem if the tree is later transformed to hast.
The following example shows how a script is injected that could run when loaded
in a browser.
1function handler(start, nodes, end) { 2 return [start, {type: 'html', value: '<script>alert(1)</script>'}, end] 3}
Yields:
1<!--foo start--> 2 3<script>alert(1)</script> 4 5<!--foo end-->
Either do not use user input or use hast-util-santize
.
mdast-util-heading-range
— similar but uses headings to mark sectionsSee 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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More