-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.js
More file actions
34 lines (24 loc) · 1.08 KB
/
html.js
File metadata and controls
34 lines (24 loc) · 1.08 KB
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
29
30
31
32
33
34
import { elements, attributes } from '@aegisjsproject/sanitizer/config/base.js';
import { stringify } from './utils.js';
const sanitizer = { elements, attributes, dataAttributes: true, comments: true };
const raw = (strings, values, mapper = stringify) => String.raw(strings, ...values.map(mapper)).trim();
export function createHTMLParser(config = sanitizer, { mapper = stringify } = {}) {
return (strings, ...values) => {
const tmp = document.createElement('template');
tmp.setHTML(raw(strings, values, mapper), { sanitizer: config });
return tmp.content;
};
}
export const html = createHTMLParser(sanitizer, { mapper: stringify });
export function htmlUnsafe(strings, ...values) {
const tmp = document.createElement('template');
tmp.setHTMLUnsafe(raw(strings, values));
return tmp.content;
}
export const el = (...args) => html.apply(null, args).firstElementChild;
export function doc(strings, ...values) {
return Document.parseHTML(raw(strings, values), { sanitizer });
}
export function docUnsafe(strings, ...values) {
return Document.parseHTMLUnsafe(raw(strings, values));
}