Merge pull request #2178 from famedly/krille/escape-html-tags-before-markdown-rendering

refactor: Escape HTML tags before markdown rendering
This commit is contained in:
Reza 2025-11-06 09:38:01 +01:00 committed by GitHub
commit 3106b5d877
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -212,7 +212,13 @@ String markdown(
bool convertLinebreaks = true,
}) {
var ret = markdownToHtml(
text.replaceNewlines(),
text
.replaceAllMapped(
// Replace HTML tags
RegExp(r'<([^>]*)>'),
(match) => '&lt;${match.group(1)}&gt;',
)
.replaceNewlines(),
extensionSet: ExtensionSet.gitHubFlavored,
blockSyntaxes: [
BlockLatexSyntax(),

View File

@ -220,6 +220,10 @@ void main() {
),
'<p>The first<br/>codeblock</p><pre><code class="language-dart">void main(){\nprint(something);\n}\n</code></pre><p>And the second code block</p><pre><code class="language-js">meow\nmeow\n</code></pre>',
);
expect(
markdown('Test <m> *unescaped*'),
'Test &lt;m&gt; <em>unescaped</em>',
);
});
test('Checkboxes', () {
expect(