Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { children = [] } = node;
const { length: childrenLength } = children;
let namespace = optionsNamespace;
let rootIsDocument = childrenLength === 0;
for (let i = 0; i < childrenLength; i += 1) {
const { tagName, properties = {} } = children[i];
if (tagName === 'html') {
// If we have a root HTML node, we don’t need to render as a fragment.
rootIsDocument = true;
// Take namespace of the first child.
if (typeof optionsNamespace === 'undefined') {
namespace = properties.xmlns || ns.html;
}
}
}
// The root node will be a Document, DocumentFragment, or HTMLElement.
let el;
if (rootIsDocument) {
el = doc.implementation.createDocument(namespace, '', null);
} else if (fragment) {
el = doc.createDocumentFragment();
} else {
el = doc.createElement('html');
}
return appendAll(
import xtend from 'xtend';
import toDOM from 'hast-util-to-dom';
import ns from 'web-namespaces';
const htmlXmlnsExpression = new RegExp(` xmlns="${ns.html}"`, 'g');
export default function stringify(config) {
const settings = xtend(config, this.data('settings'));
if (settings.fragment == null) {
settings.fragment = true;
}
this.Compiler = compiler;
function compiler(tree) {
const node = toDOM(tree, settings);
const serialized = new XMLSerializer().serializeToString(node);
// XMLSerializer puts xmlns on root elements (typically the document
// element, but in case of a fragment all of the fragments children).
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);
const { length } = props;
for (let i = 0; i < length; i += 1) {
const { children = [] } = node;
const { length: childrenLength } = children;
let namespace = optionsNamespace;
let rootIsDocument = childrenLength === 0;
for (let i = 0; i < childrenLength; i += 1) {
const { tagName, properties = {} } = children[i];
if (tagName === 'html') {
// If we have a root HTML node, we don’t need to render as a fragment.
rootIsDocument = true;
// Take namespace of the first child.
if (typeof optionsNamespace === 'undefined') {
namespace = properties.xmlns || ns.html;
}
}
}
// The root node will be a Document, DocumentFragment, or HTMLElement.
let el;
if (rootIsDocument) {
el = document.implementation.createDocument(namespace, '', null);
} else if (fragment) {
el = document.createDocumentFragment();
} else {
el = document.createElement('html');
}
return appendAll(el, children, { fragment, namespace, ...options });
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`,