diff --git a/lib/pages/chat/events/html_message.dart b/lib/pages/chat/events/html_message.dart
index cab5a94f..5aaacd91 100644
--- a/lib/pages/chat/events/html_message.dart
+++ b/lib/pages/chat/events/html_message.dart
@@ -6,6 +6,7 @@ import 'package:flutter_highlighter/themes/shades-of-purple.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html_table/flutter_html_table.dart';
import 'package:flutter_math_fork/flutter_math.dart';
+import 'package:linkify/linkify.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
@@ -45,16 +46,30 @@ class HtmlMessage extends StatelessWidget {
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
+ final linkifiedRenderHtml = linkify(
+ renderHtml,
+ options: const LinkifyOptions(humanize: false),
+ ).map(
+ (element) {
+ if (element is! UrlElement || element.text.contains('>')) {
+ return element.text;
+ }
+ return '${element.text}';
+ },
+ ).join('');
+
+ final linkColor = textColor.withAlpha(150);
+
// there is no need to pre-validate the html, as we validate it while rendering
return Html(
- data: renderHtml,
+ data: linkifiedRenderHtml,
style: {
'*': Style(
color: textColor,
margin: Margins.all(0),
fontSize: FontSize(fontSize),
),
- 'a': Style(color: textColor.withAlpha(150)),
+ 'a': Style(color: linkColor, textDecorationColor: linkColor),
'h1': Style(
fontSize: FontSize(fontSize * 2),
lineHeight: LineHeight.number(1.5),
@@ -369,7 +384,10 @@ class CodeExtension extends HtmlExtension {
.last ??
'md',
theme: shadesOfPurpleTheme,
- padding: const EdgeInsets.all(6),
+ padding: EdgeInsets.symmetric(
+ horizontal: 6,
+ vertical: context.element?.parent?.localName == 'pre' ? 6 : 0,
+ ),
textStyle: TextStyle(fontSize: fontSize),
),
),
diff --git a/pubspec.lock b/pubspec.lock
index 378449ad..8842c99c 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1000,7 +1000,7 @@ packages:
source: hosted
version: "0.8.1"
linkify:
- dependency: transitive
+ dependency: "direct main"
description:
name: linkify
sha256: "4139ea77f4651ab9c315b577da2dd108d9aa0bd84b5d03d33323f1970c645832"
diff --git a/pubspec.yaml b/pubspec.yaml
index ee03921c..c7da91a4 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -61,6 +61,7 @@ dependencies:
just_audio_mpv: ^0.1.6
keyboard_shortcuts: ^0.1.4
latlong2: ^0.8.1
+ linkify: ^5.0.0
matrix: ^0.20.1
matrix_homeserver_recommendations: ^0.3.0
native_imaging: ^0.1.0