markdown support for talk messages
This commit is contained in:
@@ -8,6 +8,7 @@ import '../../../../model/endpoint_data.dart';
|
||||
import '../../../../utils/emoji_detection.dart';
|
||||
import '../../../../utils/url_opener.dart';
|
||||
import '../widgets/highlighted_linkify.dart';
|
||||
import '../widgets/message_markdown.dart';
|
||||
|
||||
class ChatMessage {
|
||||
String originalMessage;
|
||||
@@ -26,7 +27,11 @@ class ChatMessage {
|
||||
);
|
||||
}
|
||||
|
||||
Widget getWidget({String? highlightQuery, TextStyle? style}) {
|
||||
Widget getWidget({
|
||||
String? highlightQuery,
|
||||
TextStyle? style,
|
||||
bool renderMarkdown = false,
|
||||
}) {
|
||||
final emojiFontSize = standaloneEmojiFontSize(content);
|
||||
final effectiveStyle = emojiFontSize == null
|
||||
? style
|
||||
@@ -35,12 +40,21 @@ class ChatMessage {
|
||||
height: 1.15,
|
||||
);
|
||||
|
||||
Widget contentWidget = HighlightedLinkify(
|
||||
text: content,
|
||||
onOpen: UrlOpener.onOpen,
|
||||
highlight: highlightQuery,
|
||||
style: effectiveStyle,
|
||||
);
|
||||
// Markdown replaces the plain linkified text only for regular messages.
|
||||
// Emoji-only bodies keep their enlarged rendering, and while searching we
|
||||
// fall back to the linkify path so matches can still be highlighted (the
|
||||
// search highlight can't be threaded through Markdown formatting).
|
||||
final hasQuery = highlightQuery?.trim().isNotEmpty ?? false;
|
||||
final useMarkdown = renderMarkdown && emojiFontSize == null && !hasQuery;
|
||||
|
||||
var contentWidget = useMarkdown
|
||||
? MessageMarkdown(data: content, style: effectiveStyle)
|
||||
: HighlightedLinkify(
|
||||
text: content,
|
||||
onOpen: UrlOpener.onOpen,
|
||||
highlight: highlightQuery,
|
||||
style: effectiveStyle,
|
||||
);
|
||||
|
||||
// Enlarged emoji glyphs otherwise sit flush against the bubble edges.
|
||||
if (emojiFontSize != null) {
|
||||
|
||||
Reference in New Issue
Block a user