LibMarkdown: Handle error while rendering JS to HTML
The library logs the error and falls back to not colorizing the js code inside the block instead.
This commit is contained in:
parent
2dfa87814e
commit
80563120e2
Notes:
sideshowbarker
2024-07-17 10:54:57 +09:00
Author: https://github.com/kuzux Commit: https://github.com/SerenityOS/serenity/commit/80563120e2 Pull-request: https://github.com/SerenityOS/serenity/pull/16511 Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 10 additions and 3 deletions
|
@ -29,10 +29,17 @@ DeprecatedString CodeBlock::render_to_html(bool) const
|
|||
else
|
||||
builder.appendff("<code class=\"language-{}\">", escape_html_entities(m_language));
|
||||
|
||||
if (m_language == "js")
|
||||
builder.append(JS::MarkupGenerator::html_from_source(m_code).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
if (m_language == "js") {
|
||||
auto html_or_error = JS::MarkupGenerator::html_from_source(m_code);
|
||||
if (html_or_error.is_error()) {
|
||||
warnln("Could not render js code to html: {}", html_or_error.error());
|
||||
builder.append(escape_html_entities(m_code));
|
||||
} else {
|
||||
builder.append(html_or_error.release_value());
|
||||
}
|
||||
} else {
|
||||
builder.append(escape_html_entities(m_code));
|
||||
}
|
||||
|
||||
builder.append("</code>"sv);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue