Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
? ' ' + Object.keys(node.data).map(key => {
if (typeof node.data[key] !== 'string') {
throw new Error('mdast span: only stings are supported, you may use JSON.stringify')
}
return `data-${encodeEntities(key)}="${encodeEntities(node.data[key])}"`
}).join(' ')
: ''}>`
export function domToHTML(root: HTMLNode, stats: TableStats): string {
let html = ''
if (root.type === 'tag') {
const strChildren = root.children.reduce((prev: string, curr: HTMLNode) => {
if (curr.type === 'tag' && curr.name === 'tr') {
stats.rows += 1
}
if (curr.type === 'tag' && (curr.name === 'td' || curr.name === 'th') && stats.rows === 1) {
stats.columns += 1
}
return `${prev}${domToHTML(curr, stats)}`
}, '')
html = `${renderOpeningTag(root.name, root.attribs)}${strChildren}`
} else if (root.type === 'text') {
const text = strigifyEntities(root.data)
html = text
stats.characters += text.length
}
return html
}
function encoder (value: string): string {
return encode(value, options)
}