Configuration
Customize dawm's parsing behavior with ParseOptions and FragmentParseOptions.
Parse Options
The ParseOptions interface controls how dawm parses HTML and XML documents.
import { parseHTML, type ParseOptions } from "dawm";
const options: ParseOptions = {
allowScripts: false,
contentType: "text/html",
exactErrors: false,
quirksMode: "no-quirks",
dropDoctype: false,
iframeSrcdoc: false,
contextElement: null,
};
const doc = parseHTML("<h1>Hello</h1>", options);
Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
allowScripts | boolean | false | When false, preserves <noscript> element hierarchy |
contentType | string | "text/html" | MIME type — use "application/xml" for XML parsing |
exactErrors | boolean | false | Enable detailed error reporting |
quirksMode | string | "no-quirks" | Quirks mode: "no-quirks", "quirks", "limited-quirks" |
dropDoctype | boolean | false | Strip the doctype declaration from output |
iframeSrcdoc | boolean | false | Set to true when parsing iframe srcdoc content |
contextElement | string | null | null | Context element name for fragment parsing |
Content Types
dawm supports two content types:
HTML (text/html)
The default mode. Uses the HTML5 parsing algorithm defined by the WHATWG specification.
const doc = parseHTML("<div><p>Hello</p></div>", {
contentType: "text/html",
});
XML (application/xml)
Strict XML parsing mode. The document must be well-formed XML.
import { parseDocument } from "dawm";
const doc = parseDocument("<root><item>1</item></root>", "application/xml");
Quirks Modes
The quirksMode option controls how the parser handles legacy HTML behaviors:
"no-quirks"— Standards mode (default). Recommended for modern documents."quirks"— Full quirks mode for legacy HTML."limited-quirks"— Almost-standards mode.
Fragment Parsing
When parsing HTML fragments (as opposed to full documents), you can specify a context element:
import { parseFragment } from "dawm/parse";
// Parse list items in the context of a <ul> element
const frag = parseFragment("<li>Item 1</li><li>Item 2</li>", "ul");
console.log(frag.childNodes.length); // 2
The context element determines how the fragment content is interpreted by the
HTML5 parser. For example, <tr> elements are only valid inside a <table>
context.