TF-806 open new tab when click link or tags a
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
|||||||
|
import 'package:core/data/network/dio_client.dart';
|
||||||
|
import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart';
|
||||||
|
import 'package:html/dom.dart';
|
||||||
|
|
||||||
|
class AddTargetBlankInTagATransformer extends DomTransformer {
|
||||||
|
const AddTargetBlankInTagATransformer();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> process(
|
||||||
|
Document document, {
|
||||||
|
Map<String, String>? mapUrlDownloadCID,
|
||||||
|
DioClient? dioClient,
|
||||||
|
}) async {
|
||||||
|
final elements = document.querySelectorAll('a');
|
||||||
|
await Future.wait(elements.map((element) async {
|
||||||
|
element.attributes['target'] = '_blank';
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,6 @@ class MessageContentTransformer {
|
|||||||
DioClient? dioClient
|
DioClient? dioClient
|
||||||
}
|
}
|
||||||
) async {
|
) async {
|
||||||
await _addTargetBlankInTagA(document);
|
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
if (configuration.domTransformers.isNotEmpty)
|
if (configuration.domTransformers.isNotEmpty)
|
||||||
...configuration.domTransformers.map((domTransformer) async =>
|
...configuration.domTransformers.map((domTransformer) async =>
|
||||||
@@ -27,13 +26,6 @@ class MessageContentTransformer {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _addTargetBlankInTagA(Document document) async {
|
|
||||||
final elements = document.querySelectorAll('a');
|
|
||||||
await Future.wait(elements.map((element) async {
|
|
||||||
element.attributes['target'] = '_blank';
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Document> toDocument(
|
Future<Document> toDocument(
|
||||||
String message,
|
String message,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart';
|
import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/base/text_transformer.dart';
|
import 'package:core/presentation/utils/html_transformer/base/text_transformer.dart';
|
||||||
|
import 'package:core/presentation/utils/html_transformer/dom/add_target_blank_in_tag_a_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/blockcode_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/blockcode_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/blockquoted_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/blockquoted_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart';
|
||||||
@@ -54,6 +55,7 @@ class TransformConfiguration {
|
|||||||
SignatureTransformer(),
|
SignatureTransformer(),
|
||||||
BlockQuotedTransformer(),
|
BlockQuotedTransformer(),
|
||||||
BlockCodeTransformer(),
|
BlockCodeTransformer(),
|
||||||
|
AddTargetBlankInTagATransformer(),
|
||||||
ImageTransformer(),
|
ImageTransformer(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user