mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-01 07:04:30 +01:00
chore: Follow up linkify in html message
This commit is contained in:
parent
1d0c842bad
commit
85868cc0bd
@ -6,6 +6,7 @@ import 'package:flutter_highlighter/themes/shades-of-purple.dart';
|
|||||||
import 'package:flutter_html/flutter_html.dart';
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
import 'package:flutter_html_table/flutter_html_table.dart';
|
import 'package:flutter_html_table/flutter_html_table.dart';
|
||||||
import 'package:flutter_math_fork/flutter_math.dart';
|
import 'package:flutter_math_fork/flutter_math.dart';
|
||||||
|
import 'package:linkify/linkify.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
@ -45,16 +46,30 @@ class HtmlMessage extends StatelessWidget {
|
|||||||
|
|
||||||
final fontSize = AppConfig.messageFontSize * AppConfig.fontSizeFactor;
|
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 '<a href="${element.url}">${element.text}</a>';
|
||||||
|
},
|
||||||
|
).join('');
|
||||||
|
|
||||||
|
final linkColor = textColor.withAlpha(150);
|
||||||
|
|
||||||
// there is no need to pre-validate the html, as we validate it while rendering
|
// there is no need to pre-validate the html, as we validate it while rendering
|
||||||
return Html(
|
return Html(
|
||||||
data: renderHtml,
|
data: linkifiedRenderHtml,
|
||||||
style: {
|
style: {
|
||||||
'*': Style(
|
'*': Style(
|
||||||
color: textColor,
|
color: textColor,
|
||||||
margin: Margins.all(0),
|
margin: Margins.all(0),
|
||||||
fontSize: FontSize(fontSize),
|
fontSize: FontSize(fontSize),
|
||||||
),
|
),
|
||||||
'a': Style(color: textColor.withAlpha(150)),
|
'a': Style(color: linkColor, textDecorationColor: linkColor),
|
||||||
'h1': Style(
|
'h1': Style(
|
||||||
fontSize: FontSize(fontSize * 2),
|
fontSize: FontSize(fontSize * 2),
|
||||||
lineHeight: LineHeight.number(1.5),
|
lineHeight: LineHeight.number(1.5),
|
||||||
@ -369,7 +384,10 @@ class CodeExtension extends HtmlExtension {
|
|||||||
.last ??
|
.last ??
|
||||||
'md',
|
'md',
|
||||||
theme: shadesOfPurpleTheme,
|
theme: shadesOfPurpleTheme,
|
||||||
padding: const EdgeInsets.all(6),
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 6,
|
||||||
|
vertical: context.element?.parent?.localName == 'pre' ? 6 : 0,
|
||||||
|
),
|
||||||
textStyle: TextStyle(fontSize: fontSize),
|
textStyle: TextStyle(fontSize: fontSize),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1000,7 +1000,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.1"
|
version: "0.8.1"
|
||||||
linkify:
|
linkify:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: linkify
|
name: linkify
|
||||||
sha256: "4139ea77f4651ab9c315b577da2dd108d9aa0bd84b5d03d33323f1970c645832"
|
sha256: "4139ea77f4651ab9c315b577da2dd108d9aa0bd84b5d03d33323f1970c645832"
|
||||||
|
@ -61,6 +61,7 @@ dependencies:
|
|||||||
just_audio_mpv: ^0.1.6
|
just_audio_mpv: ^0.1.6
|
||||||
keyboard_shortcuts: ^0.1.4
|
keyboard_shortcuts: ^0.1.4
|
||||||
latlong2: ^0.8.1
|
latlong2: ^0.8.1
|
||||||
|
linkify: ^5.0.0
|
||||||
matrix: ^0.20.1
|
matrix: ^0.20.1
|
||||||
matrix_homeserver_recommendations: ^0.3.0
|
matrix_homeserver_recommendations: ^0.3.0
|
||||||
native_imaging: ^0.1.0
|
native_imaging: ^0.1.0
|
||||||
|
Loading…
Reference in New Issue
Block a user