Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: issues with displaying mention text (#7773)

Morn04407fe8ff60
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart
index d7f3e26302..9be73fcc0b 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart
@@ -161,25 +161,13 @@ class CustomLinkPreviewWidget extends StatelessWidget {
}
Widget buildImage(BuildContext context) {
+ if (imageUrl?.isEmpty ?? true) {
+ return SizedBox.shrink();
+ }
final theme = AppFlowyTheme.of(context),
fillScheme = theme.fillColorScheme,
iconScheme = theme.iconColorScheme;
final width = UniversalPlatform.isDesktopOrWeb ? 160.0 : 120.0;
- Widget child;
- if (imageUrl?.isNotEmpty ?? false) {
- child = FlowyNetworkImage(
- url: imageUrl!,
- width: width,
- );
- } else {
- child = Center(
- child: FlowySvg(
- FlowySvgs.toolbar_link_earth_m,
- color: iconScheme.secondary,
- size: Size.square(30),
- ),
- );
- }
return ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16.0),
@@ -188,7 +176,17 @@ class CustomLinkPreviewWidget extends StatelessWidget {
child: Container(
width: width,
color: fillScheme.quaternary,
- child: child,
+ child: FlowyNetworkImage(
+ url: imageUrl!,
+ width: width,
+ errorWidgetBuilder: (_, __, ___) => Center(
+ child: FlowySvg(
+ FlowySvgs.toolbar_link_earth_m,
+ color: iconScheme.secondary,
+ size: Size.square(30),
+ ),
+ ),
+ ),
),
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart
index ab0b246743..7b52994654 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart
@@ -3,6 +3,7 @@ import 'package:appflowy_backend/log.dart';
// ignore: depend_on_referenced_packages
import 'package:html/parser.dart' as html_parser;
import 'package:http/http.dart' as http;
+import 'dart:convert';
abstract class LinkInfoParser {
Future<LinkInfo?> parse(
@@ -38,12 +39,19 @@ class DefaultParser implements LinkInfoParser {
if (code != 200 && isHome) {
throw Exception('Http request error: $code');
}
- // else if (!isHome && code == 403) {
- // uri = Uri.parse('${uri.scheme}://${uri.host}/');
- // response = await http.get(uri).timeout(timeout);
- // }
- final document = html_parser.parse(response.body);
+ final contentType = response.headers['content-type'];
+ final charset = contentType?.split('charset=').lastOrNull;
+ String body = '';
+ if (charset == null ||
+ charset.toLowerCase() == 'latin-1' ||
+ charset.toLowerCase() == 'iso-8859-1') {
+ body = latin1.decode(response.bodyBytes);
+ } else {
+ body = utf8.decode(response.bodyBytes, allowMalformed: true);
+ }
+
+ final document = html_parser.parse(body);
final siteName = document
.querySelector('meta[property="og:site_name"]')