Skip to content

Commit

Permalink
fix: fixed numbered list being treated as a paragraph (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mukund-Tandon authored Jul 21, 2023
1 parent 1205e7b commit d77ff1b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {
final imageRegex = RegExp(r'^!\[[^\]]*\]\((.*?)\)');
final assetRegex = RegExp(r'^\[[^\]]*\]\((.*?)\)');
final htmlRegex = RegExp('^(http|https)://');
final numberedlistRegex = RegExp(r'^\d+\. ');

@override
Document convert(String input) {
Expand Down Expand Up @@ -109,6 +110,13 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {
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) {
Expand Down
58 changes: 58 additions & 0 deletions test/plugins/markdown/decoder/document_markdown_decoder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,58 @@ 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": {
"delta": [
{
"insert": "1 list item 1"
}
]
}
},
{
"type": "paragraph",
"data": {
"delta": [
{
"insert": "2 list item 2"
}
]
}
},
{
"type": "paragraph",
"data": {
"delta": []
}
},
{
"type": "paragraph",
"data": {
Expand Down Expand Up @@ -364,6 +416,12 @@ 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
1 list item 1
2 list item 2
[Example file.pdf](path/to/file.pdf)
![Example image](path/to/image.png)
Expand Down

0 comments on commit d77ff1b

Please sign in to comment.