posthtml-parser
Advanced tools
Comparing version 0.2.1 to 0.3.0
29
index.js
@@ -11,2 +11,4 @@ 'use strict'; | ||
var defaultDirectives = [{name: '!doctype', start: '<', end: '>'}]; | ||
/** | ||
@@ -26,8 +28,24 @@ * Parse html to PostHTMLTree | ||
function parserDirective(name, data) { | ||
var directives = options.directives || defaultDirectives; | ||
var last = bufArray.last(); | ||
for (var i = 0; i < directives.length; i++) { | ||
var directive = directives[i]; | ||
var directiveText = directive.start + data + directive.end; | ||
if (name.toLowerCase() === directive.name) { | ||
if (!last) { | ||
results.push(directiveText); | ||
return; | ||
} | ||
last.content || (last.content = []); | ||
last.content.push(directiveText); | ||
} | ||
} | ||
} | ||
var parser = new htmlparser.Parser({ | ||
onprocessinginstruction: function(name, data) { | ||
if (name.toLowerCase() === '!doctype') { | ||
results.push('<' + data + '>'); | ||
} | ||
}, | ||
onprocessinginstruction: parserDirective, | ||
oncomment: function(data) { | ||
@@ -106,1 +124,2 @@ var comment = '<!--' + data + '-->', | ||
module.exports.defaultOptions = defaultOptions; | ||
module.exports.defaultDirectives = defaultDirectives; |
{ | ||
"name": "posthtml-parser", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Parse HTML/XML to PostHTMLTree", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -80,4 +80,11 @@ # posthtml-parser | ||
## Options | ||
### `directives` | ||
Type: `Array` | ||
Default: `[{name: '!doctype', start: '<', end: '>'}]` | ||
Description: *Adds processing of custom directives* | ||
## License | ||
[MIT](LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
134217
27
933
90
2