html-dom-parser icon indicating copy to clipboard operation
html-dom-parser copied to clipboard

Support `template` tags

Open loganvolkers opened this issue 3 years ago • 3 comments

The current implementation won't parse <template> tags correctly.

This is because <template> tags use node.content.childNodes instead of node.childNodes for tracking their children.

Related line: https://github.com/remarkablemark/html-dom-parser/blob/master/lib/client/utilities.js#L86

loganvolkers avatar Feb 23 '22 01:02 loganvolkers

Thanks for opening this issue @loganvolkers. Would you like to open a PR?

remarkablemark avatar Mar 14 '22 00:03 remarkablemark

I'm working on a rewrite in Typescript for the browser at the moment. Once that project's done might have time to port the logic back.

loganvolkers avatar Mar 16 '22 03:03 loganvolkers

Sounds good @loganvolkers!

remarkablemark avatar Mar 16 '22 23:03 remarkablemark

I did a quick check in JSFiddle and it looks like node.childNodes is returning the proper nodes:

const template = document.createElement('template');
template.innerHTML = '<br>';

console.log('template.childNodes', template.childNodes); // invalid
console.log('template.content.childNodes', template.content.childNodes); // valid

remarkablemark avatar Apr 17 '24 18:04 remarkablemark