Skip to content

Commit

Permalink
Catch markdown rendering errors and output in <pre> block. (#7498)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Feb 22, 2024
1 parent ef30b1c commit 1a6c842
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/lib/shared/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ String markdownToHtml(
nodes = _groupChangelogNodes(nodes).toList();
}
return _renderSafeHtml(nodes, disableHashIds: disableHashIds);
} catch (e, st) {
_logger.shout('Error rendering markdown.', e, st);
// safe content inside the <pre> element
final safeText = text
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll("'", '&#39;')
.replaceAll('"', '&quot;');
return '<p>Error rendering markdown.</p>\n<pre><code>\n$safeText\n</code></pre>\n';
} finally {
if (sw.elapsed.inSeconds >= 3) {
_logger.shout('Markdown rendering taking too long: ${sw.elapsed}');
Expand Down

0 comments on commit 1a6c842

Please sign in to comment.