(htmlRoot: IHtmlNode)
| 252 | } |
| 253 | |
| 254 | export function convertNode(htmlRoot: IHtmlNode) { |
| 255 | return walkTree<IHtmlNode, IPureNode>(htmlRoot, (htmlNode, next) => { |
| 256 | const node: IPureNode = { |
| 257 | content: htmlNode.html, |
| 258 | children: next() || [], |
| 259 | }; |
| 260 | if (htmlNode.data) { |
| 261 | node.payload = { |
| 262 | tag: htmlNode.tag, |
| 263 | ...htmlNode.data, |
| 264 | }; |
| 265 | } |
| 266 | if (htmlNode.comments) { |
| 267 | if (htmlNode.comments.includes('foldAll')) { |
| 268 | node.payload = { ...node.payload, fold: 2 }; |
| 269 | } else if (htmlNode.comments.includes('fold')) { |
| 270 | node.payload = { ...node.payload, fold: 1 }; |
| 271 | } |
| 272 | } |
| 273 | return node; |
| 274 | }); |
| 275 | } |
| 276 | |
| 277 | export function buildTree(html: string, opts?: Partial<IHtmlParserOptions>) { |
| 278 | const htmlRoot = parseHtml(html, opts); |
no test coverage detected