Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1# hast-util-from-html2 3[![Build][build-badge]][build]4[![Coverage][coverage-badge]][coverage]5[![Downloads][downloads-badge]][downloads]6[![Size][size-badge]][size]7[![Sponsors][sponsors-badge]][collective]8[![Backers][backers-badge]][collective]9[![Chat][chat-badge]][chat]10 11[hast][] utility that turns HTML into a syntax tree.12 13## Contents14 15* [What is this?](#what-is-this)16* [When should I use this?](#when-should-i-use-this)17* [Install](#install)18* [Use](#use)19* [API](#api)20 * [`fromHtml(value[, options])`](#fromhtmlvalue-options)21 * [`ErrorCode`](#errorcode)22 * [`ErrorSeverity`](#errorseverity)23 * [`OnError`](#onerror)24 * [`Options`](#options)25* [Examples](#examples)26 * [Example: fragment versus document](#example-fragment-versus-document)27 * [Example: whitespace around and inside `<html>`](#example-whitespace-around-and-inside-html)28 * [Example: parse errors](#example-parse-errors)29* [Syntax](#syntax)30* [Types](#types-2)31* [Compatibility](#compatibility)32* [Security](#security)33* [Related](#related)34* [Contribute](#contribute)35* [License](#license)36 37## What is this?38 39This package is a utility that takes HTML input and turns it into a hast syntax40tree.41 42## When should I use this?43 44If you want to handle syntax trees manually, use this.45 46Use [`parse5`][parse5] instead when you just want to parse HTML and don’t care47about [hast][].48You can also use [`hast-util-from-parse5`][hast-util-from-parse5] and49[`parse5`][parse5] yourself, or use the rehype plugin50[`rehype-parse`][rehype-parse], which wraps this utility to also parse HTML at51a higher-level (easier) abstraction.52[`xast-util-from-xml`][xast-util-from-xml] can be used if you are dealing with53XML instead of HTML.54 55If you might run in a browser and prefer a ligher alternative, while not caring56about positional info, parse errors, and consistency across browsers, use57[`hast-util-from-html-isomorphic`][hast-util-from-html-isomorphic], which58wraps this in Node and uses browser APIs otherwise.59 60Finally you can use the utility [`hast-util-to-html`][hast-util-to-html] for61the inverse of this utility.62It turns hast into HTML.63 64## Install65 66This package is [ESM only][esm].67In Node.js (version 16+), install with [npm][]:68 69```sh70npm install hast-util-from-html71```72 73In Deno with [`esm.sh`][esmsh]:74 75```js76import {fromHtml} from 'https://esm.sh/hast-util-from-html@2'77```78 79In browsers with [`esm.sh`][esmsh]:80 81```html82<script type="module">83 import {fromHtml} from 'https://esm.sh/hast-util-from-html@2?bundle'84</script>85```86 87## Use88 89```js90import {fromHtml} from 'hast-util-from-html'91 92const tree = fromHtml('<h1>Hello, world!</h1>', {fragment: true})93 94console.log(tree)95```96 97Yields:98 99```js100{101 type: 'root',102 children: [103 {104 type: 'element',105 tagName: 'h1',106 properties: {},107 children: [Array],108 position: [Object]109 }110 ],111 data: { quirksMode: false },112 position: {113 start: { line: 1, column: 1, offset: 0 },114 end: { line: 1, column: 23, offset: 22 }115 }116}117```118 119## API120 121This package exports the identifier [`fromHtml`][api-from-html].122There is no default export.123 124### `fromHtml(value[, options])`125 126Turn serialized HTML into a hast tree.127 128###### Parameters129 130* `value` ([`Compatible`][compatible])131 — serialized HTML to parse132* `options` ([`Options`][api-options], optional)133 — configuration134 135###### Returns136 137Tree ([`Root`][root]).138 139### `ErrorCode`140 141Known names of parse errors (TypeScript type).142 143###### Types144 145```ts146type ErrorCode =147 | 'abandonedHeadElementChild'148 | 'abruptClosingOfEmptyComment'149 | 'abruptDoctypePublicIdentifier'150 // … see readme on `options[key in ErrorCode]` above.151```152 153### `ErrorSeverity`154 155Error severity (TypeScript type).156 157###### Types158 159```ts160export type ErrorSeverity =161 // Turn the parse error off:162 | 0163 | false164 // Turn the parse error into a warning:165 | 1166 | true167 // Turn the parse error into an actual error: processing stops.168 | 2169```170 171### `OnError`172 173Function called when encountering [HTML parse errors][parse-errors].174 175###### Parameters176 177* `error` ([`VFileMessage`][vfile-message])178 — message179 180###### Returns181 182Nothing (`void`).183 184### `Options`185 186Configuration (TypeScript type).187 188##### Fields189 190###### `options.space`191 192Which space the document is in (`'html'` or `'svg'`, default: `'html'`).193 194When an `<svg>` element is found in the HTML space, `hast-util-from-html`195already automatically switches to and from the SVG space when entering and196exiting it.197 198> 👉 **Note**: this is not an XML parser.199> It supports SVG as embedded in HTML.200> It does not support the features available in XML.201> Passing SVG files might break but fragments of modern SVG should be fine.202> Use [`xast-util-from-xml`][xast-util-from-xml] to parse XML.203 204> 👉 **Note**: make sure to set `fragment: true` if `space: 'svg'`.205 206###### `options.verbose`207 208Add extra positional info about attributes, start tags, and end tags209(`boolean`, default: `false`).210 211###### `options.fragment`212 213Whether to parse as a fragment (`boolean`, default: `false`).214The default is to expect a whole document.215In document mode, unopened `html`, `head`, and `body` elements are opened.216 217###### `options.onerror`218 219Function called when encountering [HTML parse errors][parse-errors]220([`OnError`][api-on-error], optional).221 222###### `options[key in ErrorCode]`223 224Specific parse errors can be configured by setting their identifiers (see225[`ErrorCode`][api-error-code]) as keys directly in `options` to an226[`ErrorSeverity`][api-error-severity] as value.227 228The list of parse errors:229 230<!-- parse-error start -->231 232* `abandonedHeadElementChild` — unexpected metadata element after head ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/abandoned-head-element-child/index.html))233* [`abruptClosingOfEmptyComment`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment) — unexpected abruptly closed empty comment ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/abrupt-closing-of-empty-comment/index.html))234* [`abruptDoctypePublicIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-doctype-public-identifier) — unexpected abruptly closed public identifier ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/abrupt-doctype-public-identifier/index.html))235* [`abruptDoctypeSystemIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-doctype-system-identifier) — unexpected abruptly closed system identifier ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/abrupt-doctype-system-identifier/index.html))236* [`absenceOfDigitsInNumericCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-absence-of-digits-in-numeric-character-reference) — unexpected non-digit at start of numeric character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/absence-of-digits-in-numeric-character-reference/index.html))237* [`cdataInHtmlContent`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-cdata-in-html-content) — unexpected CDATA section in HTML ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/cdata-in-html-content/index.html))238* [`characterReferenceOutsideUnicodeRange`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-character-reference-outside-unicode-range) — unexpected too big numeric character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/character-reference-outside-unicode-range/index.html))239* `closingOfElementWithOpenChildElements` — unexpected closing tag with open child elements ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/closing-of-element-with-open-child-elements/index.html))240* [`controlCharacterInInputStream`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-control-character-in-input-stream) — unexpected control character ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/control-character-in-input-stream/index.html))241* [`controlCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-control-character-reference) — unexpected control character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/control-character-reference/index.html))242* `disallowedContentInNoscriptInHead` — disallowed content inside `<noscript>` in `<head>` ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/disallowed-content-in-noscript-in-head/index.html))243* [`duplicateAttribute`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-duplicate-attribute) — unexpected duplicate attribute ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/duplicate-attribute/index.html))244* [`endTagWithAttributes`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-end-tag-with-attributes) — unexpected attribute on closing tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/end-tag-with-attributes/index.html))245* [`endTagWithTrailingSolidus`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-end-tag-with-trailing-solidus) — unexpected slash at end of closing tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/end-tag-with-trailing-solidus/index.html))246* `endTagWithoutMatchingOpenElement` — unexpected unopened end tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/end-tag-without-matching-open-element/index.html))247* [`eofBeforeTagName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-before-tag-name) — unexpected end of file ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-before-tag-name/index.html))248* [`eofInCdata`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-in-cdata) — unexpected end of file in CDATA ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-in-cdata/index.html))249* [`eofInComment`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-in-comment) — unexpected end of file in comment ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-in-comment/index.html))250* [`eofInDoctype`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-in-doctype) — unexpected end of file in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-in-doctype/index.html))251* `eofInElementThatCanContainOnlyText` — unexpected end of file in element that can only contain text ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-in-element-that-can-contain-only-text/index.html))252* [`eofInScriptHtmlCommentLikeText`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-in-script-html-comment-like-text) — unexpected end of file in comment inside script ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-in-script-html-comment-like-text/index.html))253* [`eofInTag`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-eof-in-tag) — unexpected end of file in tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/eof-in-tag/index.html))254* [`incorrectlyClosedComment`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment) — incorrectly closed comment ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/incorrectly-closed-comment/index.html))255* [`incorrectlyOpenedComment`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-opened-comment) — incorrectly opened comment ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/incorrectly-opened-comment/index.html))256* [`invalidCharacterSequenceAfterDoctypeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-invalid-character-sequence-after-doctype-name) — invalid sequence after doctype name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/invalid-character-sequence-after-doctype-name/index.html))257* [`invalidFirstCharacterOfTagName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-invalid-first-character-of-tag-name) — invalid first character in tag name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/invalid-first-character-of-tag-name/index.html))258* `misplacedDoctype` — misplaced doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/misplaced-doctype/index.html))259* `misplacedStartTagForHeadElement` — misplaced `<head>` start tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/misplaced-start-tag-for-head-element/index.html))260* [`missingAttributeValue`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-attribute-value) — missing attribute value ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-attribute-value/index.html))261* `missingDoctype` — missing doctype before other content ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-doctype/index.html))262* [`missingDoctypeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-doctype-name) — missing doctype name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-doctype-name/index.html))263* [`missingDoctypePublicIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-doctype-public-identifier) — missing public identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-doctype-public-identifier/index.html))264* [`missingDoctypeSystemIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-doctype-system-identifier) — missing system identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-doctype-system-identifier/index.html))265* [`missingEndTagName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-end-tag-name) — missing name in end tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-end-tag-name/index.html))266* [`missingQuoteBeforeDoctypePublicIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-quote-before-doctype-public-identifier) — missing quote before public identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-quote-before-doctype-public-identifier/index.html))267* [`missingQuoteBeforeDoctypeSystemIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-quote-before-doctype-system-identifier) — missing quote before system identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-quote-before-doctype-system-identifier/index.html))268* [`missingSemicolonAfterCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-semicolon-after-character-reference) — missing semicolon after character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-semicolon-after-character-reference/index.html))269* [`missingWhitespaceAfterDoctypePublicKeyword`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-after-doctype-public-keyword) — missing whitespace after public identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-whitespace-after-doctype-public-keyword/index.html))270* [`missingWhitespaceAfterDoctypeSystemKeyword`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-after-doctype-system-keyword) — missing whitespace after system identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-whitespace-after-doctype-system-keyword/index.html))271* [`missingWhitespaceBeforeDoctypeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-before-doctype-name) — missing whitespace before doctype name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-whitespace-before-doctype-name/index.html))272* [`missingWhitespaceBetweenAttributes`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-between-attributes) — missing whitespace between attributes ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-whitespace-between-attributes/index.html))273* [`missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-between-doctype-public-and-system-identifiers) — missing whitespace between public and system identifiers in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/missing-whitespace-between-doctype-public-and-system-identifiers/index.html))274* [`nestedComment`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-nested-comment) — unexpected nested comment ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/nested-comment/index.html))275* `nestedNoscriptInHead` — unexpected nested `<noscript>` in `<head>` ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/nested-noscript-in-head/index.html))276* `nonConformingDoctype` — unexpected non-conforming doctype declaration ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/non-conforming-doctype/index.html))277* [`nonVoidHtmlElementStartTagWithTrailingSolidus`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-non-void-html-element-start-tag-with-trailing-solidus) — unexpected trailing slash on start tag of non-void element ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/non-void-html-element-start-tag-with-trailing-solidus/index.html))278* [`noncharacterCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-noncharacter-character-reference) — unexpected noncharacter code point referenced by character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/noncharacter-character-reference/index.html))279* [`noncharacterInInputStream`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-noncharacter-in-input-stream) — unexpected noncharacter character ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/noncharacter-in-input-stream/index.html))280* [`nullCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-null-character-reference) — unexpected NULL character referenced by character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/null-character-reference/index.html))281* `openElementsLeftAfterEof` — unexpected end of file ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/open-elements-left-after-eof/index.html))282* [`surrogateCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-surrogate-character-reference) — unexpected surrogate character referenced by character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/surrogate-character-reference/index.html))283* [`surrogateInInputStream`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-surrogate-in-input-stream) — unexpected surrogate character284* [`unexpectedCharacterAfterDoctypeSystemIdentifier`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-character-after-doctype-system-identifier) — invalid character after system identifier in doctype ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-character-after-doctype-system-identifier/index.html))285* [`unexpectedCharacterInAttributeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-character-in-attribute-name) — unexpected character in attribute name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-character-in-attribute-name/index.html))286* [`unexpectedCharacterInUnquotedAttributeValue`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-character-in-unquoted-attribute-value) — unexpected character in unquoted attribute value ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-character-in-unquoted-attribute-value/index.html))287* [`unexpectedEqualsSignBeforeAttributeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-equals-sign-before-attribute-name) — unexpected equals sign before attribute name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-equals-sign-before-attribute-name/index.html))288* [`unexpectedNullCharacter`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-null-character) — unexpected NULL character ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-null-character/index.html))289* [`unexpectedQuestionMarkInsteadOfTagName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-question-mark-instead-of-tag-name) — unexpected question mark instead of tag name ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-question-mark-instead-of-tag-name/index.html))290* [`unexpectedSolidusInTag`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-solidus-in-tag) — unexpected slash in tag ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unexpected-solidus-in-tag/index.html))291* [`unknownNamedCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unknown-named-character-reference) — unexpected unknown named character reference ([example](https://github.com/syntax-tree/hast-util-from-html/blob/main/test/parse-error/unknown-named-character-reference/index.html))292 293<!-- parse-error end -->294 295## Examples296 297### Example: fragment versus document298 299The following example shows the difference between parsing as a document and300parsing as a fragment:301 302```js303import {fromHtml} from 'hast-util-from-html'304 305const doc = '<title>Hi!</title><h1>Hello!</h1>'306 307console.log(fromHtml(doc))308 309console.log(fromHtml(doc, {fragment: true}))310```311 312…yields (positional info and data omitted for brevity):313 314```js315{316 type: 'root',317 children: [318 {type: 'element', tagName: 'html', properties: {}, children: [Array]}319 ]320}321```322 323```js324{325 type: 'root',326 children: [327 {type: 'element', tagName: 'title', properties: {}, children: [Array]},328 {type: 'element', tagName: 'h1', properties: {}, children: [Array]}329 ]330}331```332 333> 👉 **Note**: observe that when a whole document is expected (first example),334> missing elements are opened and closed.335 336### Example: whitespace around and inside `<html>`337 338The following example shows how whitespace is handled when around and directly339inside the `<html>` element:340 341```js342import {fromHtml} from 'hast-util-from-html'343import {inspect} from 'unist-util-inspect'344 345const doc = `<!doctype html>346<html lang=en>347 <head>348 <title>Hi!</title>349 </head>350 <body>351 <h1>Hello!</h1>352 </body>353</html>`354 355console.log(inspect(fromHtml(doc)))356```357 358…yields:359 360```txt361root[2] (1:1-9:8, 0-119)362│ data: {"quirksMode":false}363├─0 doctype (1:1-1:16, 0-15)364└─1 element<html>[3] (2:1-9:8, 16-119)365 │ properties: {"lang":"en"}366 ├─0 element<head>[3] (3:3-5:10, 33-72)367 │ │ properties: {}368 │ ├─0 text "\n " (3:9-4:5, 39-44)369 │ ├─1 element<title>[1] (4:5-4:23, 44-62)370 │ │ │ properties: {}371 │ │ └─0 text "Hi!" (4:12-4:15, 51-54)372 │ └─2 text "\n " (4:23-5:3, 62-65)373 ├─1 text "\n " (5:10-6:3, 72-75)374 └─2 element<body>[3] (6:3-8:10, 75-111)375 │ properties: {}376 ├─0 text "\n " (6:9-7:5, 81-86)377 ├─1 element<h1>[1] (7:5-7:20, 86-101)378 │ │ properties: {}379 │ └─0 text "Hello!" (7:9-7:15, 90-96)380 └─2 text "\n \n" (7:20-9:1, 101-112)381```382 383> 👉 **Note**: observe that the line ending before `<html>` is ignored, the line384> ending and two spaces before `<head>` is moved inside it, and the line ending385> after `</body>` is moved before it.386 387This behavior is described by the HTML standard (see the section 13.2.6.4.1388“The ‘initial’ insertion mode” and adjacent states) which we follow.389 390The changes to this meaningless whitespace should not matter, except when391formatting markup, in which case [`rehype-format`][rehype-format] can be used to392improve the source code.393 394### Example: parse errors395 396The following example shows how HTML parse errors can be enabled and configured:397 398```js399import {fromHtml} from 'hast-util-from-html'400 401const doc = `<!doctypehtml>402<title class="a" class="b">Hello…</title>403<h1/>World!</h1>`404 405fromHtml(doc, {406 onerror: console.log,407 missingWhitespaceBeforeDoctypeName: 2, // Mark one as a fatal error.408 nonVoidHtmlElementStartTagWithTrailingSolidus: false // Ignore one.409})410```411 412…yields:413 414```txt415[1:10-1:10: Missing whitespace before doctype name] {416 ancestors: undefined,417 cause: undefined,418 column: 10,419 fatal: true,420 line: 1,421 place: {422 start: { line: 1, column: 10, offset: 9 },423 end: { line: 1, column: 10, offset: 9 }424 },425 reason: 'Missing whitespace before doctype name',426 ruleId: 'missing-whitespace-before-doctype-name',427 source: 'hast-util-from-html',428 note: 'Unexpected `h`. Expected ASCII whitespace instead',429 url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-before-doctype-name'430}431[2:23-2:23: Unexpected duplicate attribute] {432 ancestors: undefined,433 cause: undefined,434 column: 23,435 fatal: false,436 line: 2,437 place: {438 start: { line: 2, column: 23, offset: 37 },439 end: { line: 2, column: 23, offset: 37 }440 },441 reason: 'Unexpected duplicate attribute',442 ruleId: 'duplicate-attribute',443 source: 'hast-util-from-html',444 note: 'Unexpectedly double attribute. Expected attributes to occur only once',445 url: 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-duplicate-attribute'446}447```448 449> 🧑🏫 **Info**: messages in unified are warnings instead of errors.450> Other linters (such as ESLint) almost always use errors.451> Why?452> Those tools *only* check code style.453> They don’t generate, transform, and format code, which is what we focus on,454> too.455> Errors in unified mean the same as an exception in your JavaScript code: a456> crash.457> That’s why we use warnings instead, because we can continue doing work.458 459## Syntax460 461HTML is parsed according to WHATWG HTML (the living standard), which is also462followed by browsers such as Chrome and Firefox.463 464## Types465 466This package is fully typed with [TypeScript][].467It exports the additional types468[`ErrorCode`][api-error-code], [`ErrorSeverity`][api-error-severity],469[`OnError`][api-on-error], and [`Options`][api-options].470 471## Compatibility472 473Projects maintained by the unified collective are compatible with maintained474versions of Node.js.475 476When we cut a new major release, we drop support for unmaintained versions of477Node.478This means we try to keep the current release line, `hast-util-from-html@^2`,479compatible with Node.js 16.480 481## Security482 483Parsing HTML is safe but using user-provided content can open you up to a484[cross-site scripting (XSS)][xss] attack.485Use [`hast-util-santize`][hast-util-sanitize] to make the hast tree safe.486 487## Related488 489* [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)490 — serialize hast491* [`hast-util-sanitize`](https://github.com/syntax-tree/hast-util-sanitize)492 — sanitize hast493* [`xast-util-from-xml`][xast-util-from-xml]494 — parse XML495 496## Contribute497 498See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for499ways to get started.500See [`support.md`][support] for ways to get help.501 502This project has a [code of conduct][coc].503By interacting with this repository, organization, or community you agree to504abide by its terms.505 506## License507 508[MIT][license] © [Titus Wormer][author]509 510<!-- Definitions -->511 512[build-badge]: https://github.com/syntax-tree/hast-util-from-html/workflows/main/badge.svg513 514[build]: https://github.com/syntax-tree/hast-util-from-html/actions515 516[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-from-html.svg517 518[coverage]: https://codecov.io/github/syntax-tree/hast-util-from-html519 520[downloads-badge]: https://img.shields.io/npm/dm/hast-util-from-html.svg521 522[downloads]: https://www.npmjs.com/package/hast-util-from-html523 524[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-from-html525 526[size]: https://bundlejs.com/?q=hast-util-from-html527 528[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg529 530[backers-badge]: https://opencollective.com/unified/backers/badge.svg531 532[collective]: https://opencollective.com/unified533 534[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg535 536[chat]: https://github.com/syntax-tree/unist/discussions537 538[npm]: https://docs.npmjs.com/cli/install539 540[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c541 542[esmsh]: https://esm.sh543 544[typescript]: https://www.typescriptlang.org545 546[license]: license547 548[author]: https://wooorm.com549 550[health]: https://github.com/syntax-tree/.github551 552[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md553 554[support]: https://github.com/syntax-tree/.github/blob/main/support.md555 556[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md557 558[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting559 560[hast]: https://github.com/syntax-tree/hast561 562[root]: https://github.com/syntax-tree/hast#root563 564[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize565 566[hast-util-from-parse5]: https://github.com/syntax-tree/hast-util-from-parse5567 568[hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html569 570[xast-util-from-xml]: https://github.com/syntax-tree/xast-util-from-xml571 572[rehype-parse]: https://github.com/rehypejs/rehype/tree/main/packages/rehype-parse#readme573 574[rehype-format]: https://github.com/rehypejs/rehype-format575 576[parse5]: https://github.com/inikulin/parse5577 578[parse-errors]: https://html.spec.whatwg.org/multipage/parsing.html#parse-errors579 580[vfile-message]: https://github.com/vfile/vfile-message#vfilemessagereason-place-origin581 582[hast-util-from-html-isomorphic]: https://github.com/syntax-tree/hast-util-from-html-isomorphic583 584[compatible]: https://github.com/vfile/vfile#compatible585 586[api-from-html]: #fromhtmlvalue-options587 588[api-error-code]: #errorcode589 590[api-error-severity]: #errorseverity591 592[api-on-error]: #onerror593 594[api-options]: #options595 