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

Small typo in documentation

Open edoardo-bluframe opened this issue 9 months ago • 0 comments

Docs say

import { parse } from 'node-html-parser';

const root = parse('<ul id="list"><li>Hello World</li></ul>');

console.log(root.firstChild.structure);
// ul#list
//   li
//     #text

console.log(root.querySelector('#list'));
// { tagName: 'ul',
//   rawAttrs: 'id="list"',
//   childNodes:
//    [ { tagName: 'li',
//        rawAttrs: '',
//        childNodes: [Object],
//        classNames: [] } ],
//   id: 'list',
//   classNames: [] }
console.log(root.toString());
// <ul id="list"><li>Hello World</li></ul>
root.set_content('<li>Hello World</li>');
root.toString();	// <li>Hello World</li>

We are moving from JSDOM to this - a lot faster - and initial we changed all our tagName matches to lowercase as the examples shows lowercase: tagName: 'ul'

We realized it wasn't working and that it was in fact returning UL just like JSDOM

Later in the docs it does specify Get or Set tag name of HTMLElement. Note that the returned value is an uppercase string.

Isn't it better if the example - which is at the very top and one of the first things we read - actually matches functionality? 😄

edoardo-bluframe avatar Feb 16 '25 14:02 edoardo-bluframe