Skip to content

Instantly share code, notes, and snippets.

@brigand
Last active Jun 25, 2021
Embed
What would you like to do?
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