Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select comment nodes with querySelector #221

Closed
milahu opened this issue Sep 23, 2022 · 0 comments
Closed

select comment nodes with querySelector #221

milahu opened this issue Sep 23, 2022 · 0 comments

Comments

@milahu
Copy link

milahu commented Sep 23, 2022

this should work

var { parse: parseHtml } = require('node-html-parser')
var html = `a <!-- b --> c`;
var root = parseHtml(html, { comment: true });

// TODO implement
var comment = root.querySelector('!--');

console.log(comment);
console.log(comment.innerHTML == ' b ');
// dont use magic alias tagname. this would break xml
var comment = root.querySelector('comment');

workaround: regex

var { parse: parseHtml } = require('node-html-parser')
var html = `a <!-- b --> c`;
var root = parseHtml(html, { comment: true });

var htmlTemp = root.toString();
var comment = htmlTemp.match(/<!--(.*?)-->/s);

related #13 #220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants