Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function serializeNodeToHtmlString(node) {
const serialized = new XMLSerializer().serializeToString(node);
// XMLSerializer puts xmlns on “main” elements that are not in the XML
// namespace.
// We’d like to inspect that, but having the HTML namespace everywhere will
// get unwieldy, so remove those.
return serialized
.replace(new RegExp(` xmlns="${ns.html}"`, 'g'), '')
.replace(new RegExp(`(<(?:svg|g)) xmlns="${ns.svg}"`, 'g'), '$1');
}
function element(node, options) {
const { namespace, doc } = options;
let impliedNamespace = options.impliedNamespace || namespace;
const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;
if (
(impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
&& tagName === 'svg'
) {
impliedNamespace = ns.svg;
}
const schema = impliedNamespace === ns.svg ? svg : html;
const el = impliedNamespace === null || impliedNamespace === undefined
? doc.createElement(tagName)
: doc.createElementNS(impliedNamespace, tagName);
// Add HTML attributes.
const props = Object.keys(properties);
var fn = own.call(map, ast.nodeName) ? map[ast.nodeName] : element
var children
var node
var pos
// remove #document-fragment and update parentNode of childs
if (ast.nodeName === 'template') {
ast.childNodes = ast.content.childNodes
ast.childNodes.forEach(n => {
n.parentNode = ast
})
delete ast.content
}
if (fn === element) {
config.schema = ast.namespaceURI === ns.svg ? svg : html
}
if (ast.childNodes) {
children = nodes(ast.childNodes, config)
}
node = fn(ast, children, config)
if (ast.sourceCodeLocation && config.file) {
pos = location(node, ast.sourceCodeLocation, config)
if (pos) {
config.location = true
node.position = pos
}
}
function element(node, options) {
const { namespace, doc } = options;
let impliedNamespace = options.impliedNamespace || namespace;
const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;
if (
(impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
&& tagName === 'svg'
) {
impliedNamespace = ns.svg;
}
const schema = impliedNamespace === ns.svg ? svg : html;
const el = impliedNamespace === null || impliedNamespace === undefined
? doc.createElement(tagName)
: doc.createElementNS(impliedNamespace, tagName);
// Add HTML attributes.
const props = Object.keys(properties);
const { length } = props;
for (let i = 0; i < length; i += 1) {
const key = props[i];
const {
function element(node, options) {
const { namespace, doc } = options;
let impliedNamespace = options.impliedNamespace || namespace;
const { tagName = impliedNamespace === ns.svg ? 'g' : 'div', properties = {}, children = [] } = node;
if (
(impliedNamespace === null || impliedNamespace === undefined || impliedNamespace === ns.html)
&& tagName === 'svg'
) {
impliedNamespace = ns.svg;
}
const schema = impliedNamespace === ns.svg ? svg : html;
const el = impliedNamespace === null || impliedNamespace === undefined
? doc.createElement(tagName)
: doc.createElementNS(impliedNamespace, tagName);
// Add HTML attributes.
const props = Object.keys(properties);
const { length } = props;
for (let i = 0; i < length; i += 1) {
const key = props[i];
const {
attribute,
property,
// `mustUseAttribute`,