htmlparser2-parse5-tree-adapter

This issue has been tracked since 2022-10-18.

im looking for the inverse of parse5-htmlparser2-tree-adapter

aka

  • htmlparser2-parse5-tree-adapter
  • htmlparser2-to-parse5-tree-adapter

does it exist?
if no, contributions welcome?

why

add htmlparser2 to a project that is currently using only parse5
so the internals are based on parse5

see rehypejs/rehype#112

cheerio

projects like cheerio use both parsers, parse5 for html, htmlparser2 for xhtml

cheerio internals are based on htmlparser2, so parse5 is used via adapter

cheerio/src/index.ts

import { parseDocument as parseWithHtmlparser2 } from 'htmlparser2';
import { renderWithParse5, parseWithParse5 } from './parsers/parse5-adapter.js';

const parse = getParse((content, options, isDocument, context) =>
  options.xmlMode || options._useHtmlParser2
    ? parseWithHtmlparser2(content, options)
    : parseWithParse5(content, options, isDocument, context)
);

export const load = getLoad(parse, (dom, options) =>
  options.xmlMode || options._useHtmlParser2
    ? renderWithHtmlparser2(dom, options)
    : renderWithParse5(dom)
);

cheerio/src/parsers/parse5-adapter.ts

import { adapter as htmlparser2Adapter } from 'parse5-htmlparser2-tree-adapter';

const renderOpts = { treeAdapter: htmlparser2Adapter };

related

milahu wrote this answer on 2022-11-02

closing, i dont need this

More Details About Repo
Owner Name fb55
Repo Name htmlparser2
Full Name fb55/htmlparser2
Language TypeScript
Created Date 2011-08-27
Updated Date 2023-03-19
Star Count 3793
Watcher Count 50
Fork Count 370
Issue Count 4

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date