Skip to content

Commit

Permalink
fix: unable to parse image if the image is inside the paragraph
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jan 6, 2025
1 parent 2490f69 commit 33d1c19
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependency_overrides:
git:
url: https://github.com/AppFlowy-IO/AppFlowy-plugins.git
path: "packages/appflowy_editor_plugins"
ref: "3f82111"
ref: "ca82890"

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DocumentMarkdownDecoder extends Converter<String, Document> {
@override
Document convert(String input) {
final List<md.Node> mdNodes = md.Document(
extensionSet: md.ExtensionSet.gitHubWeb,
extensionSet: md.ExtensionSet.gitHubFlavored,
inlineSyntaxes: [
...inlineSyntaxes,
UnderlineInlineSyntax(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class MarkdownImageParserV2 extends CustomMarkdownParser {
return [];
}

if (element.attributes['src'] != null) {
return [
imageNode(url: element.attributes['src']!),
];
}

if (element.children?.length != 1 ||
element.children?.first is! md.Element) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,25 @@ class MarkdownParagraphParserV2 extends CustomMarkdownParser {
final splitContent = _splitByBrTag(ec);

// Transform each split content into a paragraph node
return splitContent.map((content) {
final deltaDecoder = DeltaMarkdownDecoder();
final delta = deltaDecoder.convertNodes(content);
return paragraphNode(delta: delta);
}).toList();
final result = <Node>[];
for (final content in splitContent) {
for (final node in content) {
if (node is md.Element && node.tag == 'img') {
final image = const MarkdownImageParserV2()
.transform(node, parsers)
.firstOrNull;
if (image != null) {
result.add(image);
continue;
}
}
final deltaDecoder = DeltaMarkdownDecoder();
final delta = deltaDecoder.convertNodes([node]);
result.add(paragraphNode(delta: delta));
}
}

return result;
}
}

Expand Down

0 comments on commit 33d1c19

Please sign in to comment.