-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
Copy pathreconciler.js
28 lines (26 loc) · 1.15 KB
/
reconciler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { DEV } from 'esm-env';
import * as w from '../warnings.js';
/**
* @param {string} html
*/
export function create_fragment_from_html(html) {
var elem = document.createElement('template');
elem.innerHTML = html;
if (DEV) {
let replace_comments = html.replaceAll('<!>', '<!---->');
let remove_attributes_and_text_input = replace_comments
// we remove every attribute since the template automatically adds ="" after boolean attributes
.replace(/<([a-z0-9]+)(\s+[^>]+?)?>/g, '<$1>')
// we remove the text within the elements because the template change & to & (and similar)
.replace(/>([^<>]*)/g, '>');
let remove_attributes_and_text_output = elem.innerHTML
// we remove every attribute since the template automatically adds ="" after boolean attributes
.replace(/<([a-z0-9]+)(\s+[^>]+?)?>/g, '<$1>')
// we remove the text within the elements because the template change & to & (and similar)
.replace(/>([^<>]*)/g, '>');
if (remove_attributes_and_text_input !== remove_attributes_and_text_output) {
w.invalid_html_structure(remove_attributes_and_text_input, remove_attributes_and_text_output);
}
}
return elem.content;
}