parseDocument method
Parses Document based on mime (e.g. 'text/html').
The result is either HtmlDocument or XmlDocument.
Implementation
Document parseDocument({
required String content,
required String mime,
required Window window,
}) {
switch (mime) {
case 'text/plain':
final document = HtmlDocument.internal(
window: window,
contentType: mime,
filled: true,
);
final body = document.body!;
body.appendText(content);
return document;
// HTML
case 'text/html':
return parseHtml(window: window, content: content, mime: mime);
case 'application/html':
return parseHtml(window: window, content: content, mime: mime);
// XHTML
case 'application/xhtml+xml':
return parseXml(window: window, content: content, mime: mime);
// SVG
case 'text/svg':
return parseSvg(window: window, content: content, mime: mime);
case 'application/svg':
return parseSvg(window: window, content: content, mime: mime);
// XML
case 'text/xml':
return parseXml(window: window, content: content, mime: mime);
case 'application/xml':
return parseXml(window: window, content: content, mime: mime);
default:
throw ArgumentError.value(mime, 'mime', 'Unsupported MIME type');
}
}