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

Comment parsing doesn't seem to work

Open ktrieu opened this issue 1 year ago • 0 comments

I'm on Node v21.5.0 and version 6.1.12 of the library. I have a pretty simple test case that I believe should work, judging from the issue about adding comment support to querySelector (https://github.com/taoqf/node-html-parser/issues/221).

index.js

import { parse } from 'node-html-parser'
import * as fs from 'fs';

const html = fs.readFileSync('./test.html').toString();

const parsed = parse(html, { comment: true });

const comments = parsed.querySelectorAll('!--');

console.log(comments);

test.html

<html>
  <body>
    <h1>TEST</h1>
    <!-- Some comment here. -->
  </body>
</html>

However, running this code prints []. I get the same result when the HTML is included inline as a raw string, so I don't think the file handling is at fault.

ktrieu avatar Feb 29 '24 18:02 ktrieu