Skip to content

Instantly share code, notes, and snippets.

@fabiangarga
Last active April 3, 2022 18:41
Show Gist options
  • Save fabiangarga/68df2dc50c170c9e32a74cced1bfd6ad to your computer and use it in GitHub Desktop.
Save fabiangarga/68df2dc50c170c9e32a74cced1bfd6ad to your computer and use it in GitHub Desktop.
Render Elements
function el (parent) {
return function (...args) {
let out = '';
if(args.length > 1) {
let outChild = '';
args.forEach(arg => {
outChild += arg;
});
out += renderElChild(parent, outChild)
}
else {
return renderElChild(parent, args[0]);
}
return out;
}
}
function renderElChild (parent, child) {
return `<${parent}>${child}</${parent}>`
}
function main() {
const div = el('div');
const p = el('p');
const html = div(
p(' Hello '),
p(' Random '),
div(
p(' Hi from p '),
),
p(' Last message ')
);
console.log(html);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment