parseFragment function

DocumentFragment parseFragment(
  1. dynamic input, {
  2. String container = 'div',
  3. String? encoding,
  4. bool generateSpans = false,
  5. String? sourceUrl,
})

Parse the input html5 document fragment into a tree. The input can be a String, List<int> of bytes or an HtmlTokenizer. The container element can optionally be specified, otherwise it defaults to "div".

If input is not a HtmlTokenizer, you can optionally specify the file's encoding, which must be a string. If specified, that encoding will be used, regardless of any BOM or later declaration (such as in a meta element).

Set generateSpans if you want to generate SourceSpans, otherwise the Node.sourceSpan property will be null. When using generateSpans you can additionally pass sourceUrl to indicate where the input was extracted from.

Implementation

DocumentFragment parseFragment(dynamic input,
    {String container = 'div',
    String? encoding,
    bool generateSpans = false,
    String? sourceUrl}) {
  final p = HtmlParser(input,
      encoding: encoding, generateSpans: generateSpans, sourceUrl: sourceUrl);
  return p.parseFragment(container);
}