Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed numbered list being treated as a paragraph #335

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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