(node, depth)
| 203 | * @param {number} depth depth |
| 204 | */ |
| 205 | const walk = (node, depth) => { |
| 206 | const indent = `| ${" ".repeat(depth)}`; |
| 207 | if (node.type === NodeType.Doctype) { |
| 208 | let s = `<!DOCTYPE ${node.name || ""}`; |
| 209 | if (node.publicId !== null || node.systemId !== null) { |
| 210 | s += ` "${node.publicId || ""}" "${node.systemId || ""}"`; |
| 211 | } |
| 212 | lines.push(`${indent}${s}>`); |
| 213 | return; |
| 214 | } |
| 215 | if (node.type === NodeType.Comment) { |
| 216 | lines.push(`${indent}<!-- ${node.data} -->`); |
| 217 | return; |
| 218 | } |
| 219 | if (node.type === NodeType.Text) { |
| 220 | lines.push(`${indent}"${node.data}"`); |
| 221 | return; |
| 222 | } |
| 223 | const prefix = NS_PREFIX[node.namespace] || ""; |
| 224 | lines.push(`${indent}<${prefix}${node.tagName}>`); |
| 225 | const attrs = [...node.attributes].sort((a, b) => { |
| 226 | const an = a.serializedName || a.name; |
| 227 | const bn = b.serializedName || b.name; |
| 228 | return an < bn ? -1 : an > bn ? 1 : 0; |
| 229 | }); |
| 230 | for (const a of attrs) { |
| 231 | lines.push( |
| 232 | `| ${" ".repeat(depth + 1)}${ |
| 233 | a.serializedName || a.name |
| 234 | }="${decodeHtmlEntities(a.value, true)}"` |
| 235 | ); |
| 236 | } |
| 237 | if (node.templateContent) { |
| 238 | lines.push(`| ${" ".repeat(depth + 1)}content`); |
| 239 | for (const c of node.templateContent.children) walk(c, depth + 2); |
| 240 | return; |
| 241 | } |
| 242 | for (const c of node.children) walk(c, depth + 1); |
| 243 | }; |
| 244 | for (const c of doc.children) walk(c, 0); |
| 245 | return lines.join("\n"); |
| 246 | }; |
no test coverage detected