(buff, doc)
| 14 | } |
| 15 | |
| 16 | function stringify(buff, doc) { |
| 17 | switch (doc.type) { |
| 18 | case 'text': |
| 19 | return buff + escapeXmlText(doc.data) |
| 20 | case 'tag': { |
| 21 | const voidElement = |
| 22 | doc.voidElement || (!doc.children.length && doc.attribs['xml:space'] !== 'preserve') |
| 23 | buff += `<${doc.name}${doc.attribs ? attrString(doc.attribs) : ''}${voidElement ? '/>' : '>'}` |
| 24 | if (voidElement) { |
| 25 | return buff |
| 26 | } |
| 27 | return `${buff + doc.children.reduce(stringify, '')}</${doc.name}>` |
| 28 | } |
| 29 | case 'comment': |
| 30 | buff += `<!--${doc.comment}-->` |
| 31 | return buff |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | export function stringifyDoc(doc) { |
| 36 | return doc.reduce((token, rootEl) => token + stringify('', rootEl), '') |
no test coverage detected