Skip to content

Commit

Permalink
fix: common link is detected as a video link (#1978)
Browse files Browse the repository at this point in the history
* fix: common link is detected as a video link

* chore: dart fixes

---------

Co-authored-by: CatHood0 <santiagowmar@gmail.com>
  • Loading branch information
CatHood0 and CatHood0 authored Jul 6, 2024
1 parent 018db26 commit b00b29d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/src/utils/delta_x_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UnderlineSyntax extends md.DelimiterSyntax {
class VideoSyntax extends md.LinkSyntax {
VideoSyntax({super.linkResolver})
: super(
pattern: r'\[',
pattern: r'\[!\[',
startCharacter: _$lbracket,
);

Expand Down Expand Up @@ -60,13 +60,13 @@ final videoRule = hmd.Rule('video', filters: ['iframe', 'video'],
if (!_youtubeVideoUrlValidator.hasMatch(src ?? '')) {
return '<video>${child.outerHTML}</video>';
}
return '[$content]($src)';
return '[![$content]($src)';
}
final src = node.getAttribute('src');
if (src == null || !_youtubeVideoUrlValidator.hasMatch(src)) {
return node.outerHTML;
}
return '[$content]($src)';
return '[![$content]($src)';
}
//by now, we can only access to src
final src = node.getAttribute('src');
Expand All @@ -76,5 +76,5 @@ final videoRule = hmd.Rule('video', filters: ['iframe', 'video'],
return node.outerHTML;
}
final title = node.getAttribute('title');
return '[$title]($src)';
return '[![$title]($src)';
});
19 changes: 17 additions & 2 deletions test/utils/delta_x_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ void main() {
'<iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" title="YouTube video player"></iframe>';

const htmlWithVideoTag =
'''<video src="https://www.youtube.com/embed/dQw4w9WgXcQ">Your browser does not support the video tag.</video>
''';
'<video src="https://www.youtube.com/embed/dQw4w9WgXcQ">Your browser does not support the video tag.</video>';

const htmlWithNormalLinkAndVideo =
'<a href="https://www.macrumors.com/" type="text/html">fdsfsd</a><br><video src="https://www.youtube.com/embed/dQw4w9WgXcQ">Your browser does not support the video tag.</video>';

final expectedDeltaEmp = Delta.fromOperations([
Operation.insert(
'This is a normal sentence, and this section has greater emp'),
Expand All @@ -34,6 +37,13 @@ void main() {
Operation.insert('\n'),
]);

final expectedDeltaLinkAndVideoLink = Delta.fromOperations([
Operation.insert('fdsfsd', {'link': 'https://www.macrumors.com/'}),
Operation.insert('\n\n'),
Operation.insert({'video': 'https://www.youtube.com/embed/dQw4w9WgXcQ'}),
Operation.insert('\n'),
]);

test('should detect emphasis and parse correctly', () {
final delta = DeltaX.fromHtml(htmlWithEmp);
expect(delta, expectedDeltaEmp);
Expand All @@ -53,4 +63,9 @@ void main() {
final delta = DeltaX.fromHtml(htmlWithVideoTag);
expect(delta, expectedDeltaVideo);
});

test('should detect by different way normal link and video link', () {
final delta = DeltaX.fromHtml(htmlWithNormalLinkAndVideo);
expect(delta, expectedDeltaLinkAndVideoLink);
});
}

0 comments on commit b00b29d

Please sign in to comment.