Fix newlines in codeblocks

This commit is contained in:
Henry Hiles 2026-02-11 10:44:19 -05:00
commit 6cb121c46a
No known key found for this signature in database
3 changed files with 13 additions and 5 deletions

View file

@ -41,6 +41,7 @@ class CodeBlock extends StatelessWidget {
padding: EdgeInsets.all(8),
child: SelectableText(
code,
maxLines: 99,
style: TextStyle(fontFamily: "monospace"),
),
),

View file

@ -30,10 +30,14 @@ class Html extends ConsumerWidget {
return switch (element.localName) {
"code" =>
element.parent?.localName == "pre"
? CodeBlock(
element.text,
lang: element.className.replaceAll("language-", ""),
)
? element.outerHtml.contains("<br class=\"fake-break\">")
? Html(
"""<pre>${element.outerHtml.replaceAll("<br class=\"fake-break\">", "\n")}</pre>""",
)
: CodeBlock(
element.text,
lang: element.className.replaceAll("language-", ""),
)
: null,
"blockquote" => Quoted(Html(element.innerHtml)),

View file

@ -409,7 +409,10 @@ class RoomChat extends HookConsumerWidget {
return "<a href=\"$url\">$url</a>";
},
)
.replaceAll("\n", "<br/>"),
.replaceAll(
"\n",
"<br class=\"fake-break\"/>",
),
),
if (message.editedAt != null)
Text(