Skip to content

Commit

Permalink
Added unescaped elements to elements.js
Browse files Browse the repository at this point in the history
  • Loading branch information
caramboleyo committed Dec 18, 2022
1 parent ee97d46 commit 163abbf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ export const VOID = {
track: true,
wbr: true,
};

export const UNESCAPED = {
script: true,
};
16 changes: 11 additions & 5 deletions init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import escape from './utils/escape.js';
import parseSelector from './utils/parse-selector.js';
import { VOID as VOID_ELEMENTS, CONTAINER as CONTAINER_ELEMENTS } from './elements.js';
import {
UNESCAPED as UNESCAPED_ELEMENTS,
VOID as VOID_ELEMENTS,
CONTAINER as CONTAINER_ELEMENTS,
} from './elements.js';

export default function init(modules) {
function parse(vnode, node) {
Expand All @@ -23,13 +27,13 @@ export default function init(modules) {
return result.join(' ');
}

return function renderToString(vnode) {
return function renderToString(vnode, escapeText = true) {
if (typeof vnode === 'undefined' || vnode === null) {
return '';
}

if (!vnode.sel && typeof vnode.text === 'string') {
return escape(vnode.text);
return escapeText ? escape(vnode.text) : vnode.text;
}

vnode.data = vnode.data || {};
Expand Down Expand Up @@ -71,10 +75,12 @@ export default function init(modules) {
if (vnode.data.props && vnode.data.props.innerHTML) {
tag.push(vnode.data.props.innerHTML);
} else if (vnode.text) {
tag.push(escape(vnode.text));
tag.push(escapeText ? escape(vnode.text) : vnode.text);
} else if (vnode.children) {
vnode.children.forEach(function (child) {
tag.push(renderToString(child));
tag.push(
renderToString(child, UNESCAPED_ELEMENTS[tagName] === true ? false : true),
);
});
}
tag.push('</' + tagName + '>');
Expand Down

0 comments on commit 163abbf

Please sign in to comment.