HtmlParser constructor

HtmlParser(
  1. dynamic input, {
  2. String? encoding,
  3. bool parseMeta = true,
  4. bool lowercaseElementName = true,
  5. bool lowercaseAttrName = true,
  6. bool strict = false,
  7. bool generateSpans = false,
  8. String? sourceUrl,
  9. TreeBuilder? tree,
})

Create an HtmlParser and configure the tree builder and strict mode. The input can be a String, List<int> of bytes or an HtmlTokenizer.

If input is not a HtmlTokenizer, you can specify a few more arguments.

The encoding must be a string that indicates the encoding. If specified, that encoding will be used, regardless of any BOM or later declaration (such as in a meta element).

Set parseMeta to false if you want to disable parsing the meta element.

Set lowercaseElementName or lowercaseAttrName to false to disable the automatic conversion of element and attribute names to lower case. Note that standard way to parse HTML is to lowercase, which is what the browser DOM will do if you request Element.outerHTML, for example.

Implementation

HtmlParser(dynamic input,
    {String? encoding,
    bool parseMeta = true,
    bool lowercaseElementName = true,
    bool lowercaseAttrName = true,
    this.strict = false,
    this.generateSpans = false,
    String? sourceUrl,
    TreeBuilder? tree})
    : tree = tree ?? TreeBuilder(true),
      tokenizer = input is HtmlTokenizer
          ? input
          : HtmlTokenizer(input,
              encoding: encoding,
              parseMeta: parseMeta,
              lowercaseElementName: lowercaseElementName,
              lowercaseAttrName: lowercaseAttrName,
              generateSpans: generateSpans,
              sourceUrl: sourceUrl) {
  tokenizer.parser = this;
}