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), padding: EdgeInsets.all(8),
child: SelectableText( child: SelectableText(
code, code,
maxLines: 99,
style: TextStyle(fontFamily: "monospace"), style: TextStyle(fontFamily: "monospace"),
), ),
), ),

View file

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

View file

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