You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: patching-explainer.md
+54Lines changed: 54 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -204,6 +204,60 @@ The patches uses a single marker node:
204
204
205
205
</details>
206
206
207
+
##### Markers with start/end attributes
208
+
209
+
This alternative adds `start` and `end` boolean attributes to the marker nodes, so that the start/end of a range are defined by the markers, not attributes on `<template>`.
210
+
211
+
This makes it possible to replace a `<title>` element.
212
+
213
+
<details>
214
+
<summary>Example</summary>
215
+
216
+
```html
217
+
<head>
218
+
<?marker name="metadata" start?>
219
+
<title>Page 1</title>
220
+
<?marker name="metadata" end?>
221
+
</head>
222
+
223
+
<templatecontentname="metadata">
224
+
<title>Page 2</title>
225
+
</template>
226
+
```
227
+
228
+
</details>
229
+
230
+
Details around `<title>` and the RCDATA tokenizer state are the main reason that the tag name needs to be repeated in other alterantives, but this isn't needed in this option, the children of `<template>` elements are just the new content. The `contentname` attribute can refer to either marker node(s) or an element.
231
+
232
+
When `start` and `end` aren't used, the marker node is replaced. The interleaved patching example then becomes:
233
+
234
+
<details>
235
+
<summary>Example</summary>
236
+
237
+
```html
238
+
<templatecontentname=search-results>
239
+
<p>first result</p>
240
+
<!-- add markers to allow for "append" -->
241
+
<?marker name=search-results-more?>
242
+
</template>
243
+
244
+
<templatecontentname=product-carousel>
245
+
Actual carousel content
246
+
</template>
247
+
248
+
<templatecontentname=search-results-more>
249
+
<p>second result</p>
250
+
<!-- new markers are needed for the next "append". -->
251
+
<?marker name=search-results-more?>
252
+
</template>
253
+
254
+
<templatecontentname=search-results-more>
255
+
<p>third result</p>
256
+
</template>
257
+
```
258
+
259
+
</details>
260
+
207
261
## Script-initiated patching
208
262
209
263
`streamHTMLUnsafe()` is being pursued as a [separate proposal](https://github.com/whatwg/html/issues/2142), but will also work with patching. When `<template contentmethod>` appears in the streamed HTML, those patches can apply to descendants of element on which `streamHTMLUnsafe()` was called.
0 commit comments