From fdeb52bf3823038f56b0e791b431a9e40d05a3fe Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 29 Jun 2024 18:19:52 +0800 Subject: [PATCH] :lipstick: Better post rendering --- lib/widgets/chat/chat_event_message.dart | 9 +++++++++ lib/widgets/posts/post_item.dart | 8 ++++++++ pubspec.lock | 2 +- pubspec.yaml | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/widgets/chat/chat_event_message.dart b/lib/widgets/chat/chat_event_message.dart index 4b43762..dbf51b8 100644 --- a/lib/widgets/chat/chat_event_message.dart +++ b/lib/widgets/chat/chat_event_message.dart @@ -6,6 +6,7 @@ import 'package:get/get.dart'; import 'package:solian/models/event.dart'; import 'package:solian/widgets/attachments/attachment_list.dart'; import 'package:url_launcher/url_launcher_string.dart'; +import 'package:markdown/markdown.dart' as markdown; class ChatEventMessage extends StatelessWidget { final Event item; @@ -27,6 +28,7 @@ class ChatEventMessage extends StatelessWidget { final body = EventMessageBody.fromJson(item.body); return SizedBox( + key: Key('m${item.uuid}attachments-box'), width: min(MediaQuery.of(context).size.width, 640), child: AttachmentList( key: Key('m${item.uuid}attachments'), @@ -48,6 +50,13 @@ class ChatEventMessage extends StatelessWidget { data: body.text, selectable: true, padding: const EdgeInsets.all(0), + extensionSet: markdown.ExtensionSet( + markdown.ExtensionSet.gitHubFlavored.blockSyntaxes, + [ + markdown.EmojiSyntax(), + ...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes + ], + ), onTapLink: (text, href, title) async { if (href == null) return; await launchUrlString( diff --git a/lib/widgets/posts/post_item.dart b/lib/widgets/posts/post_item.dart index d7d2ae4..0afa057 100644 --- a/lib/widgets/posts/post_item.dart +++ b/lib/widgets/posts/post_item.dart @@ -11,6 +11,7 @@ import 'package:solian/widgets/attachments/attachment_list.dart'; import 'package:solian/widgets/posts/post_quick_action.dart'; import 'package:timeago/timeago.dart' show format; import 'package:url_launcher/url_launcher_string.dart'; +import 'package:markdown/markdown.dart' as markdown; class PostItem extends StatefulWidget { final Post item; @@ -78,6 +79,13 @@ class _PostItemState extends State { physics: const NeverScrollableScrollPhysics(), data: item.content, padding: const EdgeInsets.all(0), + extensionSet: markdown.ExtensionSet( + markdown.ExtensionSet.gitHubFlavored.blockSyntaxes, + [ + markdown.EmojiSyntax(), + ...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes + ], + ), onTapLink: (text, href, title) async { if (href == null) return; await launchUrlString( diff --git a/pubspec.lock b/pubspec.lock index a9ac0fc..0f9a94a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -905,7 +905,7 @@ packages: source: hosted version: "1.5.0" markdown: - dependency: transitive + dependency: "direct main" description: name: markdown sha256: ef2a1298144e3f985cc736b22e0ccdaf188b5b3970648f2d9dc13efd1d9df051 diff --git a/pubspec.yaml b/pubspec.yaml index 0abbe7d..7ea853d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,6 +50,7 @@ dependencies: floor: ^1.5.0 sqflite: ^2.3.3+1 protocol_handler: ^0.2.0 + markdown: ^7.2.2 dev_dependencies: flutter_test: