diff --git a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart index 6b1d7053c..19ab24324 100644 --- a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart +++ b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart @@ -4,7 +4,6 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/plugins/markdown/decoder/parser/custom_node_parser.dart'; import 'package:appflowy_editor/src/plugins/markdown/decoder/table_markdown_decoder.dart'; import 'package:markdown/markdown.dart' as md; -import 'package:path/path.dart' as p; class DocumentMarkdownDecoder extends Converter { DocumentMarkdownDecoder({ @@ -207,9 +206,11 @@ class DocumentMarkdownDecoder extends Converter { return codeBlockNodeFromMarkdown(line, decoder); } else if (imageRegex.hasMatch(line.trim())) { final filePath = extractImagePath(line.trim()); - // checking if filepath is present or if the filepath is an image or not - if (filePath == null || - !['.png', '.jpg', 'jpeg'].contains(p.extension(filePath))) { + final regex = RegExp( + r'\.(png|jpg|jpeg|gif|bmp|svg|webp|tiff|ico)(\?.*)?$', + caseSensitive: false, + ); + if (filePath == null || !regex.hasMatch(filePath)) { return paragraphNode(text: line.trim()); } return imageNode(url: filePath); diff --git a/test/plugins/markdown/decoder/document_markdown_decoder_test.dart b/test/plugins/markdown/decoder/document_markdown_decoder_test.dart index 808f510b9..33223e0f2 100644 --- a/test/plugins/markdown/decoder/document_markdown_decoder_test.dart +++ b/test/plugins/markdown/decoder/document_markdown_decoder_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/plugins/markdown/decoder/document_markdown_decoder.dart'; import 'package:appflowy_editor/src/plugins/markdown/decoder/parser/custom_node_parser.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -953,5 +954,25 @@ Hello [AppFlowy Subpage](123456789abcd) **Hello** [AppFlowy Subpage](987654321ab expect(result.toJson(), data); }); + + test('image with properties after extension', () async { + const markdown = ''' +## Welcome to AppFlowy + +![Example image](https://example.com/image.png?key=value)'''; + + final expected = Document.blank() + ..insert( + [0], + [ + headingNode(text: 'Welcome to AppFlowy', level: 2), + paragraphNode(), + imageNode(url: 'https://example.com/image.png?key=value'), + ], + ); + final result = DocumentMarkdownDecoder().convert(markdown); + + expect(result.toJson(), expected.toJson()); + }); }); }