Gathering detailed insights and metrics for posthtml-parser
Gathering detailed insights and metrics for posthtml-parser
Gathering detailed insights and metrics for posthtml-parser
Gathering detailed insights and metrics for posthtml-parser
npm install posthtml-parser
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (98.49%)
Shell (1.51%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
112 Stars
271 Commits
22 Forks
8 Watchers
5 Branches
20 Contributors
Updated on Jun 16, 2025
Latest Version
0.12.1
Package Id
posthtml-parser@0.12.1
Unpacked Size
12.01 kB
Size
4.93 kB
File Count
7
NPM Version
10.5.2
Node Version
20.13.1
Published on
Sep 19, 2024
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
1npm install posthtml-parser
Input HTML:
1<a class="animals" href="#"> 2 <span class="animals__cat" style="background: url(cat.png)">Cat</span> 3</a>
Parse with posthtml-parser
:
1import fs from 'fs' 2import { parser } from 'posthtml-parser' 3 4const html = fs.readFileSync('path/to/input.html', 'utf-8') 5 6console.log(parser(html))
Resulting PostHTML AST:
1[ 2 { 3 tag: 'a', 4 attrs: { 5 class: 'animals', 6 href: '#' 7 }, 8 content: [ 9 '\n ', 10 { 11 tag: 'span', 12 attrs: { 13 class: 'animals__cat', 14 style: 'background: url(cat.png)' 15 }, 16 content: ['Cat'] 17 }, 18 '\n' 19 ] 20 } 21]
Any parser used with PostHTML should return a standard PostHTML Abstract Syntax Tree (AST).
Fortunately, this is a very easy format to produce and understand. The AST is an array that can contain strings and objects. Strings represent plain text content, while objects represent HTML tags.
Tag objects generally look like this:
1{ 2 tag: 'div', 3 attrs: { 4 class: 'foo' 5 }, 6 content: ['hello world!'] 7}
Tag objects can contain three keys:
tag
key takes the name of the tag as the value. This can include custom tags.attrs
key takes an object with key/value pairs representing the attributes of the html tag. A boolean attribute has an empty string as its value.content
key takes an array as its value, which is a PostHTML AST. In this manner, the AST is a tree that should be walked recursively.directives
Type: Array
Default: [{name: '!doctype', start: '<', end: '>'}]
Adds processing of custom directives.
The property name
in custom directives can be of String
or RegExp
type.
xmlMode
Type: Boolean
Default: false
Indicates whether special tags (<script>
and <style>
) should get special treatment and if "empty" tags (eg. <br>
) can have children. If false, the content of special tags will be text only.
For feeds and other XML content (documents that don't consist of HTML), set this to true
.
decodeEntities
Type: Boolean
Default: false
If set to true
, entities within the document will be decoded.
lowerCaseTags
Type: Boolean
Default: false
If set to true
, all tags will be lowercased. If xmlMode
is disabled.
lowerCaseAttributeNames
Type: Boolean
Default: false
If set to true
, all attribute names will be lowercased.
This has noticeable impact on speed.
recognizeCDATA
Type: Boolean
Default: false
If set to true
, CDATA sections will be recognized as text even if the xmlMode
option is not enabled.
If xmlMode
is set to true
, then CDATA sections will always be recognized as text.
recognizeSelfClosing
Type: Boolean
Default: false
If set to true
, self-closing tags will trigger the onclosetag
event even if xmlMode
is not set to true
.
If xmlMode
is set to true
, then self-closing tags will always be recognized.
sourceLocations
Type: Boolean
Default: false
If set to true
, AST nodes will have a location
property containing the start
and end
line and column position of the node.
recognizeNoValueAttribute
Type: Boolean
Default: false
If set to true
, AST nodes will recognize attribute with no value and mark as true
which will be correctly rendered by posthtml-render
package.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
Found 2/6 approved changesets -- score normalized to 3
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
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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