1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/posthtml-svg-mode/lib/renderer.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
const merge = require('merge-options');
const renderer = require('posthtml-render');
const api = require('posthtml/lib/api');
const defaultOptions = {
closingSingleTag: 'slash',
singleTags: [
'circle',
'path',
'ellipse',
'line',
'path',
'polygon',
'polyline',
'rect',
'use',
'animateTransform',
'stop'
]
};
/**
* @param {PostHTMLTree} tree
* @param {Object|null} [options] {@see https://github.com/posthtml/posthtml-render#options}
*/
module.exports = function xmlRenderer(tree, options) {
const opts = merge(defaultOptions, options || {});
/**
* Workaround for https://github.com/fb55/htmlparser2/issues/187
* Also see https://github.com/fb55/htmlparser2/pull/129
*/
opts.singleTags = opts.singleTags.filter((tag) => {
let hasContent = false;
api.match.call(tree, { tag }, (node) => {
if (typeof node.content !== 'undefined' && !hasContent) {
hasContent = true;
}
return node;
});
return !hasContent;
});
return renderer(tree, opts);
};
module.exports.defaultOptions = defaultOptions;