htmlnano
Version:
Modular HTML minifier, built on top of the PostHTML
30 lines (28 loc) • 959 B
JavaScript
const rDoctype = /^`.
*
* posthtml-parser emits the doctype as a raw string node at the top level of
* the tree, so we only need to inspect top-level string nodes.
*
* This is a max-only module: rewriting a legacy PUBLIC doctype can subtly
* change rendering (e.g. almost-standards vs. full standards mode), so it is
* not enabled in the safe preset. XML declarations (``) are left
* untouched.
*/ function normalizeDoctype(tree) {
tree.forEach((node, index)=>{
if (typeof node !== 'string') {
return;
}
if (rDoctype.test(node) && node !== shortDoctype) {
tree[index] = shortDoctype;
}
});
return tree;
}
const mod = {
default: normalizeDoctype
};
export { mod as default };