HtmlParser constructor

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

Create and configure an HtmlParser.

The input can be a String, a List<int> of bytes, or an HtmlTokenizer.

The strict, tree builder, and generateSpans arguments configure behavior for any type of input.

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, {
  TreeBuilder? tree,
  this.strict = false,
  this.generateSpans = false,
  String? encoding,
  bool parseMeta = true,
  bool lowercaseElementName = true,
  bool lowercaseAttrName = true,
  String? sourceUrl,
})  : 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;
}