|
2 | 2 |
|
3 | 3 | One of the best features of diffHTML is the parser. This drives the compiling
|
4 | 4 | of declarative markup and supports a variety of syntaxes. You can make compound
|
5 |
| -documents that are comprised of HTML, SVG, or XML. The result is a JSX-like |
6 |
| -object which is used by the core engine and the Babel transform. |
| 5 | +documents that are comprised of HTML, SVG, or XML. The result is a VTree which |
| 6 | +makes it equivalent to the `createTree` function. |
7 | 7 |
|
8 |
| -When you use `innerHTML`, `outerHTML`, or `html` and pass markup, it will run |
9 |
| -through this very fast and efficient parser. Usually production code does not |
10 |
| -run the parser. You will pre-compile your markup using the [Babel |
11 |
| -transform](/tools.html#babel-transform). |
| 8 | +Usually production code does not run the parser. You will pre-compile your markup |
| 9 | +using the [Babel transform](/tools.html#babel-transform) that also conveniently |
| 10 | +uses the same parser to ensure parity. |
12 | 11 |
|
13 |
| -The parser can read full HTML documents including doctype, html/head/body/title |
14 |
| -etc tags, unwrapped fragments, and more! |
| 12 | +The built in parser can read full HTML documents including comments, doctype, |
| 13 | +html/head/body/title page tags, multiple unwrapped top-level root elements, |
| 14 | +and has support for optional tags. It even supports nested markup within tags, |
| 15 | +such as <code>srcdoc="<some markup />"</code> in <code><iframe/></code>. |
| 16 | + |
| 17 | +While the parser works for most use cases out-of-the-box, you may want to use |
| 18 | +something else. The parser is fully overrieable and allows for any string-based |
| 19 | +input, so long as it can be compiled to a tree structure. |
15 | 20 |
|
16 | 21 | **Using with innerHTML:**
|
17 | 22 |
|
@@ -113,56 +118,12 @@ console.log(Internals.parse(`
|
113 | 118 |
|
114 | 119 | ## <a href="#options">Options</a>
|
115 | 120 |
|
116 |
| -The parser is somewhat configurable, allowing you to opt into a strict-mode for |
117 |
| -erroring if invalid markup is passed. This could be useful to pair with the |
118 |
| -[HTML Linter Middleware](/middleware.html#html-linter). |
119 |
| - |
120 |
| -- [`strict`](#strict-mode) - Toggle strict mode parsing |
121 |
| -- [`rawElements`](#block-elements) - Modify the list of elements that have raw values |
122 |
| -- [`selfClosingElements`](#self-closing) - Modify the list of elements that can self close |
123 |
| - |
124 |
| -<a name="strict-mode"></a> |
125 |
| - |
126 |
| ---- |
127 |
| - |
128 |
| -### <a href="#strict-mode">Strict mode</a> |
129 |
| - |
130 |
| -By default the parser operates in loose-mode which is forgiving of missing |
131 |
| -closing tags, poor markup, and other common issues. When opting into strict |
132 |
| -mode you will receive errors if you don't properly self close tags, have |
133 |
| -mismatched tag names, etc. |
134 |
| - |
135 |
| -```js |
136 |
| -import { innerHTML } from 'diffhtml'; |
137 |
| - |
138 |
| -const options = { |
139 |
| - parser: { |
140 |
| - strict: true, |
141 |
| - } |
142 |
| -}; |
| 121 | +The parser is somewhat configurable, allowing you to change the list of self |
| 122 | +closing items. This could be useful to pair with the [HTML Linter |
| 123 | +Middleware](/middleware.html#html-linter). |
143 | 124 |
|
144 |
| -// Will be fine since the elements match |
145 |
| -innerHTML(document.body, ` |
146 |
| - <h1>Hello world</h1> |
147 |
| -`, options); |
148 |
| - |
149 |
| -// Will throw since the elements do not match |
150 |
| -innerHTML(document.body, ` |
151 |
| - <h1>Hello world</h2> |
152 |
| -`, options); |
153 |
| -``` |
154 |
| - |
155 |
| -Unlike the other two options below, this feature can be configured using the |
156 |
| -tagged template [`html`](/api.html#html) directly. |
157 |
| - |
158 |
| -```js |
159 |
| -import { html } from 'diffhtml'; |
160 |
| - |
161 |
| -// Will throw an error due to the tag mismatch |
162 |
| -html.strict` |
163 |
| - <p></div> |
164 |
| -`; |
165 |
| -``` |
| 125 | +- [`rawElements`](#block-elements) - Modify the list of elements that have text values instead of markup |
| 126 | +- [`voidElements`](#self-closing) - Modify the list of elements that can self close |
166 | 127 |
|
167 | 128 | <a name="block-elements"></a>
|
168 | 129 |
|
|
0 commit comments