taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Comment parsing doesn't seem to work #270

Open ktrieu opened 7 months ago

ktrieu commented 7 months ago

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.