Skip to content

Commit

Permalink
chore: Follow up html lists
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Feb 3, 2025
1 parent 6cdfced commit 49453e3
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions lib/pages/chat/events/html_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,6 @@ class HtmlMessage extends StatelessWidget {
// Inside of a list so we add some prefix text:
var text = node.text ?? '';
if (text == '\n') text = '';
if (node.parent?.localName == 'li' &&
node.parent?.nodes.indexOf(node) == 0) {
if (node.parent?.parent?.localName == 'ul') {
text = '• $text';
}
if (node.parent?.parent?.localName == 'ol') {
final start =
int.tryParse(node.parent?.parent?.attributes['start'] ?? '1') ??
1;
text =
'${(node.parent?.parent?.nodes.indexOf(node.parent) ?? 0) + start}. $text';
}
if (node.parent?.parent?.parent?.localName == 'li') {
text = ' $text';
}
}

return LinkifySpan(
text: text,
Expand Down Expand Up @@ -216,6 +200,34 @@ class HtmlMessage extends StatelessWidget {
),
),
);
case 'li':
if (!{'ol', 'ul'}.contains(node.parent?.localName)) {
continue block;
}
return WidgetSpan(
child: Padding(
padding: EdgeInsets.only(left: fontSize),
child: Text.rich(
TextSpan(
children: [
if (node.parent?.localName == 'ul')
const TextSpan(text: '• '),
if (node.parent?.localName == 'ol')
TextSpan(
text:
'${(node.parent?.nodes.indexOf(node) ?? 0) + (int.tryParse(node.parent?.attributes['start'] ?? '1') ?? 1)}. ',
),
..._renderWithLineBreaks(
node.nodes,
context,
depth: depth,
),
],
style: TextStyle(fontSize: fontSize, color: textColor),
),
),
),
);
case 'blockquote':
return WidgetSpan(
child: Container(
Expand Down

0 comments on commit 49453e3

Please sign in to comment.