mirror of
https://github.com/zoldar/jenot.git
synced 2026-01-03 06:22:55 +00:00
19 lines
493 B
JavaScript
19 lines
493 B
JavaScript
export function stringToHTML(str, allChildren) {
|
|
var parser = new DOMParser();
|
|
var doc = parser.parseFromString(str, "text/html");
|
|
|
|
if (allChildren) {
|
|
return Array.from(doc.body.childNodes);
|
|
} else {
|
|
return doc.body.firstChild;
|
|
}
|
|
}
|
|
|
|
export function html(strings, ...values) {
|
|
return stringToHTML(String.raw({ raw: strings }));
|
|
}
|
|
|
|
export function renderText(text) {
|
|
const content = text.replace(/(?:\r\n|\r|\n)/g, "<br>") + "<br>";
|
|
return stringToHTML(content, true);
|
|
}
|