Merge branch 'main' into weblate-fluffychat-translations

This commit is contained in:
Krille-chan 2025-12-02 12:09:57 +01:00 committed by GitHub
commit 6e3cb85a57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 15 deletions

View file

@ -86,10 +86,10 @@ class HtmlMessage extends StatelessWidget {
'rt', 'rt',
'html', 'html',
'body', 'body',
// Workaround for https://github.com/krille-chan/fluffychat/issues/507
'tg-forward',
}; };
static const Set<String> ignoredHtmlTags = {'mx-reply'};
/// We add line breaks before these tags: /// We add line breaks before these tags:
static const Set<String> blockHtmlTags = { static const Set<String> blockHtmlTags = {
'p', 'p',
@ -156,8 +156,13 @@ class HtmlMessage extends StatelessWidget {
// We must not render elements nested more than 100 elements deep: // We must not render elements nested more than 100 elements deep:
if (depth >= 100) return const TextSpan(); if (depth >= 100) return const TextSpan();
// This is a text node, so we render it as text: if (node is dom.Element &&
if (node is! dom.Element) { ignoredHtmlTags.contains(node.localName?.toLowerCase())) {
return const TextSpan();
}
// This is a text node or not permitted node, so we render it as text:
if (node is! dom.Element || !allowedHtmlTags.contains(node.localName)) {
var text = node.text ?? ''; var text = node.text ?? '';
// Single linebreak nodes between Elements are ignored: // Single linebreak nodes between Elements are ignored:
if (text == '\n') text = ''; if (text == '\n') text = '';
@ -170,9 +175,6 @@ class HtmlMessage extends StatelessWidget {
); );
} }
// We must not render tags which are not in the allow list:
if (!allowedHtmlTags.contains(node.localName)) return const TextSpan();
switch (node.localName) { switch (node.localName) {
case 'br': case 'br':
return const TextSpan(text: '\n'); return const TextSpan(text: '\n');
@ -261,13 +263,15 @@ class HtmlMessage extends StatelessWidget {
child: Text.rich( child: Text.rich(
TextSpan( TextSpan(
children: [ children: [
if (node.parent?.localName == 'ul') if (!isCheckbox) ...[
const TextSpan(text: ''), if (node.parent?.localName == 'ul')
if (node.parent?.localName == 'ol') const TextSpan(text: ''),
TextSpan( if (node.parent?.localName == 'ol')
text: TextSpan(
'${(node.parent?.nodes.whereType<dom.Element>().toList().indexOf(node) ?? 0) + (int.tryParse(node.parent?.attributes['start'] ?? '1') ?? 1)}. ', text:
), '${(node.parent?.nodes.whereType<dom.Element>().toList().indexOf(node) ?? 0) + (int.tryParse(node.parent?.attributes['start'] ?? '1') ?? 1)}. ',
),
],
if (node.className == 'task-list-item') if (node.className == 'task-list-item')
WidgetSpan( WidgetSpan(
child: Padding( child: Padding(

View file

@ -241,7 +241,7 @@ class MessageContent extends StatelessWidget {
} }
var html = AppSettings.renderHtml.value && event.isRichMessage var html = AppSettings.renderHtml.value && event.isRichMessage
? event.formattedText ? event.formattedText
: event.body; : event.body.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
if (event.messageType == MessageTypes.Emote) { if (event.messageType == MessageTypes.Emote) {
html = '* $html'; html = '* $html';
} }