File tree Expand file tree Collapse file tree 2 files changed +19
-13
lines changed Expand file tree Collapse file tree 2 files changed +19
-13
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * @typedef {typeof import('./index.js').fromHtmlIsomorphic } FromHtmlIsomorphic
3
2
* @typedef {import('hast').Root } Root
3
+ * @typedef {typeof import('./index.js').fromHtmlIsomorphic } FromHtmlIsomorphic
4
4
*/
5
5
6
6
import { fromDom } from 'hast-util-from-dom'
7
7
8
8
const parser = new DOMParser ( )
9
9
10
- /**
11
- * @param {string } value
12
- */
13
- function parseFragment ( value ) {
14
- const template = document . createElement ( 'template' )
15
- template . innerHTML = value
16
- return template . content
17
- }
18
-
19
10
/** @type {FromHtmlIsomorphic } */
20
11
export function fromHtmlIsomorphic ( value , options ) {
21
12
const node = options ?. fragment
@@ -24,3 +15,15 @@ export function fromHtmlIsomorphic(value, options) {
24
15
25
16
return /** @type {Root } */ ( fromDom ( node ) )
26
17
}
18
+
19
+ /**
20
+ * Parse as a fragment.
21
+ *
22
+ * @param {string } value
23
+ * @returns {DocumentFragment }
24
+ */
25
+ function parseFragment ( value ) {
26
+ const template = document . createElement ( 'template' )
27
+ template . innerHTML = value
28
+ return template . content
29
+ }
Original file line number Diff line number Diff line change @@ -7,12 +7,15 @@ import {fromHtml} from 'hast-util-from-html'
7
7
import { removePosition } from 'unist-util-remove-position'
8
8
9
9
/**
10
+ * Turn HTML into a syntax tree, using browser APIs when available, so it has
11
+ * a smaller bundle size there.
12
+ *
10
13
* @param {string } value
11
14
* Serialized HTML to parse.
12
- * @param {Options } [options]
15
+ * @param {Options | null | undefined } [options]
13
16
* Configuration (optional).
14
- * @returns {import('hast'). Root }
15
- * Tree
17
+ * @returns {Root }
18
+ * Tree.
16
19
*/
17
20
export function fromHtmlIsomorphic ( value , options ) {
18
21
const tree = fromHtml ( value , options )
You can’t perform that action at this time.
0 commit comments