Skip to content

Commit

Permalink
feat(neon_framework): Render markdown in rich text
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Nov 11, 2024
1 parent e850437 commit d7d7f8e
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 60 deletions.
541 changes: 514 additions & 27 deletions packages/neon_framework/lib/src/widgets/rich_text/rich_text.dart

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class NotificationsNotification extends StatelessWidget {
final subject = notification.subjectRichParameters!.isNotEmpty
? Text.rich(
buildRichTextSpan(
account: NeonProvider.of<Account>(context),
text: notification.subjectRich!,
isMarkdown: false,
parameters: notification.subjectRichParameters!,
references: BuiltList(),
style: Theme.of(context).textTheme.bodyLarge!,
textStyle: Theme.of(context).textTheme.bodyLarge!,
onReferenceClicked: (_) {},
),
)
Expand All @@ -37,10 +39,12 @@ class NotificationsNotification extends StatelessWidget {
final message = notification.messageRichParameters!.isNotEmpty
? Text.rich(
buildRichTextSpan(
account: NeonProvider.of<Account>(context),
text: notification.messageRich!,
isMarkdown: false,
parameters: notification.messageRichParameters!,
references: BuiltList(),
style: Theme.of(context).textTheme.bodyMedium!,
textStyle: Theme.of(context).textTheme.bodyMedium!,
onReferenceClicked: (_) {},
),
overflow: TextOverflow.ellipsis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ class TalkMessagePreview extends StatelessWidget {
),
),
buildRichTextSpan(
account: NeonProvider.of<Account>(context),
text: chatMessage.message,
isMarkdown: false,
parameters: chatMessage.messageParameters,
references: BuiltList(),
isPreview: true,
style: Theme.of(context).textTheme.bodyMedium!,
textStyle: Theme.of(context).textTheme.bodyMedium!,
onReferenceClicked: (url) async => launchUrl(NeonProvider.of<Account>(context), url),
),
],
Expand Down Expand Up @@ -174,10 +176,12 @@ class TalkSystemMessage extends StatelessWidget {
child: Center(
child: RichText(
text: buildRichTextSpan(
account: NeonProvider.of<Account>(context),
text: chatMessage.message,
isMarkdown: chatMessage.markdown,
parameters: chatMessage.messageParameters,
references: BuiltList(),
style: Theme.of(context).textTheme.labelSmall!,
textStyle: Theme.of(context).textTheme.labelSmall!,
onReferenceClicked: (url) async => launchUrl(NeonProvider.of<Account>(context), url),
),
),
Expand Down Expand Up @@ -377,11 +381,13 @@ class _TalkCommentMessageState extends State<TalkCommentMessage> {

Widget text = Text.rich(
buildRichTextSpan(
account: NeonProvider.of<Account>(context),
text: widget.chatMessage.message,
isMarkdown: widget.chatMessage.markdown && !widget.isParent,
parameters: widget.chatMessage.messageParameters,
isPreview: widget.isParent,
references: references.keys.toBuiltList(),
style: textTheme.bodyLarge!.copyWith(
textStyle: textTheme.bodyLarge!.copyWith(
color: widget.isParent || widget.chatMessage.messageType == spreed.MessageType.commentDeleted
? labelColor
: null,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ void main() {
when(() => chatMessage.actorDisplayName).thenReturn('test');
when(() => chatMessage.message).thenReturn('message');
when(() => chatMessage.messageParameters).thenReturn(BuiltMap());
when(() => chatMessage.markdown).thenReturn(false);

replyTo.add(chatMessage);
await tester.pumpAndSettle();
Expand Down Expand Up @@ -320,6 +321,7 @@ void main() {
when(() => chatMessage.actorDisplayName).thenReturn('test');
when(() => chatMessage.message).thenReturn('message');
when(() => chatMessage.messageParameters).thenReturn(BuiltMap());
when(() => chatMessage.markdown).thenReturn(false);

editing.add(chatMessage);
await tester.pumpAndSettle();
Expand Down
Loading

0 comments on commit d7d7f8e

Please sign in to comment.