html static method

Future<MediaType?> html(
  1. SnifferContext context
)

Sniffs an HTML document.

Implementation

static Future<MediaType?> html(SnifferContext context) async {
  if (context.hasFileExtension(["htm", "html", "xht", "xhtml"]) ||
      context.hasAnyOfMediaTypes(["text/html", "application/xhtml+xml"])) {
    return MediaType.html;
  }
  // [contentAsXml] will fail if the HTML is not a proper XML document, hence the doctype check.
  if ((await context.contentAsXml())?.name.local.toLowerCase() == "html" ||
      (await context.contentAsString())
              ?.trimLeft()
              .startsWith("<!DOCTYPE html>") ==
          true) {
    return MediaType.html;
  }
  return null;
}