MCPcopy Create free account
hub / github.com/THU-MAIC/OpenMAIC / stringify

Function stringify

packages/mathml2omml/src/parse-stringify/stringify.js:16–33  ·  view source on GitHub ↗
(buff, doc)

Source from the content-addressed store, hash-verified

14}
15
16function 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
35export function stringifyDoc(doc) {
36 return doc.reduce((token, rootEl) => token + stringify('', rootEl), '')

Callers 1

stringifyDocFunction · 0.70

Calls 2

escapeXmlTextFunction · 0.85
attrStringFunction · 0.85

Tested by

no test coverage detected