-
-
Save brigand/80cf6f223de4fbae8228660c1b229d46 to your computer and use it in GitHub Desktop.
This file contains 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
ErrorMime::JavaScript => format!( | |
"{pre}{json};\nlet css = {css_json};\n{code}\n{close}", | |
json = get_json(), | |
pre = "{ let error_json = ", | |
close = "}", | |
code = indoc::indoc!(r#" | |
const h = (tag, {style, ...props}, ...children) => { | |
const element = Object.assign(document.createElement(tag), props); | |
Object.assign(element.style, style); | |
for (const child of children) { | |
if (!child || child === true) continue; | |
if (child instanceof Node) { | |
element.appendChild(child); | |
} else { | |
const text = document.createTextNode(String(child)); | |
element.appendChild(text); | |
} | |
} | |
return element; | |
}; | |
document.head.appendChild( | |
h('style', {}, css), | |
); | |
document.body.appendChild( | |
h('aside', {}, | |
h('h1', { style: { color: 'var(--red)' } }, error_json.title), | |
h('h3', {}, | |
'Code: ', | |
h('span', { style: { color: 'var(--purple)' } }, error_json.code), | |
), | |
h('p', { style: { color: 'var(--yellow)', whiteSpace: 'pre-wrap' } }, error_json.message), | |
), | |
); | |
"#), | |
css_json = serde_json::to_string(colors).unwrap(), | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment