rehype-remove-unused-css
Advanced tools
Comparing version 0.1.2 to 0.1.3
27
index.js
@@ -26,3 +26,6 @@ /** | ||
const toHtml = require("hast-util-to-html") | ||
const { selectAll } = require("unist-util-select") | ||
const { selectAll } = require("hast-util-select") | ||
const toString = require("hast-util-to-string") | ||
const fromString = require("hast-util-from-string") | ||
const { promisify } = require("util") | ||
@@ -32,19 +35,9 @@ module.exports = function purify(options) { | ||
const html = toHtml(tree) | ||
const nodes = selectAll("[tagName=style]", tree) | ||
await Promise.all(nodes.map((node)=>new Promise((resolve, reject)=>{ | ||
const raw = node.children.map(c=>c.value).join() | ||
uncss(html, {...options, raw}, (err, value)=>{ | ||
if(err) reject(err) | ||
node.children = [{ | ||
value, | ||
type: "text", | ||
position: node.children.every(c=>c.position) ? { | ||
start: node.children[0].position.start, | ||
end: node.children[node.children.length - 1].position.end | ||
} : undefined | ||
}] | ||
resolve() | ||
}) | ||
}))) | ||
const nodes = selectAll("style", tree) | ||
await Promise.all(nodes.map(async (node)=>{ | ||
const raw = toString(node) | ||
const css = await promisify(uncss)(html, {...options, raw}) | ||
fromString(node, css) | ||
})) | ||
} | ||
} |
{ | ||
"name": "rehype-remove-unused-css", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Rehype plugin to remove unused stylesheet with uncss", | ||
@@ -23,5 +23,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"hast-util-from-string": "^1.0.3", | ||
"hast-util-select": "^4.0.0", | ||
"hast-util-to-html": "^7.1.1", | ||
"uncss": "^0.17.3", | ||
"unist-util-select": "^3.0.1" | ||
"hast-util-to-string": "^1.0.3", | ||
"uncss": "^0.17.3" | ||
}, | ||
@@ -28,0 +30,0 @@ "devDependencies": { |
4071
5
38
+ Addedhast-util-from-string@^1.0.3
+ Addedhast-util-select@^4.0.0
+ Addedhast-util-to-string@^1.0.3
+ Added@types/unist@2.0.11(transitive)
+ Addedbcp-47-match@1.0.3(transitive)
+ Addeddirection@1.0.4(transitive)
+ Addedhast-util-from-string@1.0.4(transitive)
+ Addedhast-util-has-property@1.0.4(transitive)
+ Addedhast-util-select@4.0.2(transitive)
+ Addedhast-util-to-string@1.0.4(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
- Removedunist-util-select@^3.0.1
- Removedunist-util-select@3.0.4(transitive)