Created
November 18, 2019 18:22
-
-
Save bernardoadc/11ce779521dc7a7fc404a8fb2320c408 to your computer and use it in GitHub Desktop.
Simple HTML If eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function $$(selector, context) { | |
// context = context || document; | |
// var elements = context.querySelectorAll(selector); | |
// return Array.prototype.slice.call(elements); | |
// } | |
let html = $$('html')[0].innerHTML | |
let result | |
while (result = /{{#if.+}}[^]+?{{\/if}}/g.exec(html)) { | |
let block = result[0] | |
let expr = /{{#if \((.+)\)}}/y.exec(block)[1] | |
let content = /{{#if.+}}([^]+){{\/if}}/y.exec(block)[1] | |
if (!eval(expr)) | |
$$('html')[0].innerHTML = html.replace(block, '') | |
else | |
$$('html')[0].innerHTML = html.replace(block, content) | |
html = $$('html')[0].innerHTML | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment