From 6d6e5a20cba42bc7ead596e80453349e714740ef Mon Sep 17 00:00:00 2001 From: Mukund-Tandon Date: Fri, 21 Jul 2023 06:14:46 +0530 Subject: [PATCH 1/2] fix: fixed numbered list being treated as a paragraph --- .../decoder/document_markdown_decoder.dart | 8 +++++ .../document_markdown_decoder_test.dart | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart index 6529bbd60..62b8205f7 100644 --- a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart +++ b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart @@ -7,6 +7,7 @@ class DocumentMarkdownDecoder extends Converter { final imageRegex = RegExp(r'^!\[[^\]]*\]\((.*?)\)'); final assetRegex = RegExp(r'^\[[^\]]*\]\((.*?)\)'); final htmlRegex = RegExp('^(http|https)://'); + final numberedlistRegex = RegExp(r'^\d+\. '); @override Document convert(String input) { @@ -109,6 +110,13 @@ class DocumentMarkdownDecoder extends Converter { if (filepath != null && !htmlRegex.hasMatch(filepath)) { return paragraphNode(text: line); } + } else if (numberedlistRegex.hasMatch(line)) { + return numberedListNode( + attributes: { + 'delta': + decoder.convert(line.substring(line.indexOf('.') + 1)).toJson() + }, + ); } if (line.isNotEmpty) { diff --git a/test/plugins/markdown/decoder/document_markdown_decoder_test.dart b/test/plugins/markdown/decoder/document_markdown_decoder_test.dart index 3040a5537..106f322cd 100644 --- a/test/plugins/markdown/decoder/document_markdown_decoder_test.dart +++ b/test/plugins/markdown/decoder/document_markdown_decoder_test.dart @@ -192,6 +192,32 @@ void main() async { "delta": [] } }, + { + "type": "numbered_list", + "data": { + "delta": [ + { + "insert": " list item 1" + } + ] + } + }, + { + "type": "numbered_list", + "data": { + "delta": [ + { + "insert": " list item 2" + } + ] + } + }, + { + "type": "paragraph", + "data": { + "delta": [] + } + }, { "type": "paragraph", "data": { @@ -364,6 +390,9 @@ You can also use ***AppFlowy Editor*** as a component to build your own app. If you have questions or feedback, please submit an issue on Github or join the community along with 1000+ builders! +1. list item 1 +2. list item 2 + [Example file.pdf](path/to/file.pdf) ![Example image](path/to/image.png) From 7f553e6acae50e1a10a7fd7b5b6f58e1f47d5fcf Mon Sep 17 00:00:00 2001 From: Mukund-Tandon Date: Fri, 21 Jul 2023 11:47:19 +0530 Subject: [PATCH 2/2] test: updated test --- .../document_markdown_decoder_test.dart | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/plugins/markdown/decoder/document_markdown_decoder_test.dart b/test/plugins/markdown/decoder/document_markdown_decoder_test.dart index 106f322cd..ec97e0467 100644 --- a/test/plugins/markdown/decoder/document_markdown_decoder_test.dart +++ b/test/plugins/markdown/decoder/document_markdown_decoder_test.dart @@ -218,6 +218,32 @@ void main() async { "delta": [] } }, + { + "type": "paragraph", + "data": { + "delta": [ + { + "insert": "1 list item 1" + } + ] + } + }, + { + "type": "paragraph", + "data": { + "delta": [ + { + "insert": "2 list item 2" + } + ] + } + }, + { + "type": "paragraph", + "data": { + "delta": [] + } + }, { "type": "paragraph", "data": { @@ -393,6 +419,9 @@ If you have questions or feedback, please submit an issue on Github or join the 1. list item 1 2. list item 2 +1 list item 1 +2 list item 2 + [Example file.pdf](path/to/file.pdf) ![Example image](path/to/image.png)