Replies: 2 comments
-
|
I do think we should make this a documented option, and ideally drop the underscore in front of the name. |
Beta Was this translation helpful? Give feedback.
-
|
@fb55 I think you're right that passing the DOM tree directly into cheerio is the way to go. Suggested Solution1. Make loading separate parsers slightly easier Instead of: const dom = htmlparser2.parseDOM(file.contents, options)
const $ = cheerio.load(dom)
// or
const dom = parse5.parse(content, {
treeAdapter: htmlparser2Adapter,
sourceCodeLocationInfo: options.sourceCodeLocationInfo,
});
const $ = cheerio.load(dom)It's something like: const parse5 = require("cheerio/parse5")
const htmlparser2 = require("cheerio/htmlparser2")
cheerio.load(htmlparser2("<h2>hi world</h2>"))
cheerio.load(parse5("<h2>hi world</h2>"))By default We'd also need to document this, since that's part of this issue. @voithos wasn't sure if this was the recommended approach. 2. Remove _useHtmlParser2 altogether
We could either keep this switch (undocumented) for 1.0.0 or choose to remove it and break folks. Since 1.0.0 is a major change, I think we're allowed to break things. I don't have strong opinions on this though. 3. Remove
I think this option is only relevant with const ast = htmlparser2("<h2>hi world</h2>", { xml: true })
const $ = cheerio.load(ast)🙏 Really curious to hear everyone's thoughts! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to configure Cheerio to use htmlparser2 internally since it works better with the template code I'm trying to parse, but I don't want to use
xmlModeas that causes other problems. I found that there's a hidden_useHtmlParser2option that you can pass into the configuration, which works, but seems a bit sketchy. Would it be possible to make this into a real option?Alternatively, I saw elsewhere in the issue tracker that the future-proof way to do this is:
Which is fine, if that's the case - just would like confirmation that this is the recommended approach, and that there isn't a desire to expose
useHtmlParser2.Beta Was this translation helpful? Give feedback.
All reactions