diff --git a/lib/src/utils/html2md_utils.dart b/lib/src/utils/html2md_utils.dart
index 14d4f711..6978dbed 100644
--- a/lib/src/utils/html2md_utils.dart
+++ b/lib/src/utils/html2md_utils.dart
@@ -55,8 +55,29 @@ class Html2MdRules {
//Is used a local underline implemenation since markdown just use underline with html tags
return '$content';
});
- static final videoRule =
- hmd.Rule('video', filters: ['iframe'], replacement: (content, node) {
+ static final videoRule = hmd.Rule('video', filters: ['iframe', 'video'],
+ replacement: (content, node) {
+ //This need to be verified by a different way of iframes, since video tag can have children
+ if (node.nodeName == 'video') {
+ //if has children then just will be taked as different part of code
+ if (node.childNum > 0) {
+ var child = node.firstChild!;
+ var src = child.getAttribute('src');
+ if (src == null) {
+ child = node.childNodes().last;
+ src = child.getAttribute('src');
+ }
+ if (!youtubeVideoUrlValidator.hasMatch(src ?? '')) {
+ return '';
+ }
+ return '[$content]($src)';
+ }
+ final src = node.getAttribute('src');
+ if (src == null || !youtubeVideoUrlValidator.hasMatch(src)) {
+ return node.outerHTML;
+ }
+ return '[$content]($src)';
+ }
//by now, we can only access to src
final src = node.getAttribute('src');
//if the source is null or is not valid youtube url, then just return the html instead remove it
diff --git a/test/utils/delta_x_test.dart b/test/utils/delta_x_test.dart
index 092fc838..489a7493 100644
--- a/test/utils/delta_x_test.dart
+++ b/test/utils/delta_x_test.dart
@@ -9,8 +9,12 @@ void main() {
const htmlWithUnderline =
'
This is a normal sentence, and this section has greater underline';
- const htmlWithVideo =
+ const htmlWithIframeVideo =
'';
+
+ const htmlWithVideoTag =
+ '''
+''';
final expectedDeltaEmp = Delta.fromOperations([
Operation.insert(
'This is a normal sentence, and this section has greater emp'),
@@ -40,8 +44,13 @@ void main() {
expect(delta, expectedDeltaUnderline);
});
+ test('should detect iframe and parse correctly', () {
+ final delta = DeltaX.fromHtml(htmlWithIframeVideo);
+ expect(delta, expectedDeltaVideo);
+ });
+
test('should detect video and parse correctly', () {
- final delta = DeltaX.fromHtml(htmlWithVideo);
+ final delta = DeltaX.fromHtml(htmlWithVideoTag);
expect(delta, expectedDeltaVideo);
});
}