徐总多门店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
745 B

const { getRoot } = require('../utils');
/**
* @return {Function} PostHTML plugin
*/
function extractNamespacesToRoot() {
return (tree) => {
const namespaces = {};
tree.match({ tag: /.*/ }, (node) => {
const attrs = node.attrs || {};
Object.keys(attrs).forEach((attr) => {
if (attr.startsWith('xmlns')) {
if (attr in namespaces === false) {
namespaces[attr] = attrs[attr];
}
delete node.attrs[attr];
}
});
return node;
});
const root = getRoot(tree);
root.attrs = root.attrs || {};
Object.keys(namespaces).forEach(name => root.attrs[name] = namespaces[name]);
return tree;
};
}
module.exports = extractNamespacesToRoot;