Skip to content

fix: DocumentMarkdownDecoder convert image error when md.Node.Children > 1 and md.Node.Children include img element #1046

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Linij
Copy link
Contributor

@Linij Linij commented Feb 27, 2025

![](http://test.com/1.png)
**第一幕:奇葩公司新规**  
入职第一天发现我们公司有个祖传制度——迟到1分钟要讲1个笑话。前台小姐姐神秘兮兮地说:"上周市场部Jason讲了三个谐音梗,现在还在走廊罚站呢。"我盯着手机屏幕的9:01分,感觉今天要成为《饥饿游戏》真人版主角。

`![](http://test.com/2.png)  
**第二幕:社恐の终极挑战**  
当我抱着简历冲进会议室时,行政总监、HR和部门主管突然集体转身。别问,问就是三堂会审现场。更可怕的是行政总监脖子上挂着"今日段子质检员"工牌,手里还攥着评分表!此时投影仪突然发出放屁般的故障音,大老板推门而入:"听说新同事准备了特别节目?"

-----–––---–––––––––––––––––-----------------------------------
image

use this text will skip first image, because first element.Children > 1 and include img element.

cause by:

image

so, this fix code will split all img element from P element.

…> 1 and md.Node.Children include img element
@LucasXu0
Copy link
Collaborator

Hi, @Linij. Please format your code.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 7 lines in your changes missing coverage. Please review.

Project coverage is 71.22%. Comparing base (400083f) to head (ea99665).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...ns/markdown/decoder/document_markdown_decoder.dart 66.66% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1046      +/-   ##
==========================================
- Coverage   71.23%   71.22%   -0.01%     
==========================================
  Files         323      323              
  Lines       15590    15615      +25     
==========================================
+ Hits        11105    11122      +17     
- Misses       4485     4493       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LucasXu0
Copy link
Collaborator

Can you add this test into the "document_markdown_test.dart" file as well?

    test('paragraph + image with custom style', () {
      const markdown = '''![](http://test.com/1.png)
**第一幕:奇葩公司新规**
入职第一天发现我们公司有个祖传制度——迟到1分钟要讲1个笑话。前台小姐姐神秘兮兮地说:"上周市场部Jason讲了三个谐音梗,现在还在走廊罚站呢。"我盯着手机屏幕的9:01分,感觉今天要成为《饥饿游戏》真人版主角。

`![](http://test.com/2.png)
**第二幕:社恐の终极挑战**
当我抱着简历冲进会议室时,行政总监、HR和部门主管突然集体转身。别问,问就是三堂会审现场。更可怕的是行政总监脖子上挂着"今日段子质检员"工牌,手里还攥着评分表!此时投影仪突然发出放屁般的故障音,大老板推门而入:"听说新同事准备了特别节目?"''';
      final document = markdownToDocument(markdown);
      final nodes = document.root.children;
      expect(nodes.length, 6); // 2 images + 4 paragraphs
      expect(nodes[0].attributes['url'], 'http://test.com/1.png');
      expect(nodes[1].delta?.toPlainText(), '第一幕:奇葩公司新规');
      expect(
        nodes[2].delta?.toPlainText(),
        '入职第一天发现我们公司有个祖传制度——迟到1分钟要讲1个笑话。前台小姐姐神秘兮兮地说:"上周市场部Jason讲了三个谐音梗,现在还在走廊罚站呢。"我盯着手机屏幕的9:01分,感觉今天要成为《饥饿游戏》真人版主角。',
      );

      expect(nodes[3].attributes['url'], 'http://test.com/2.png');
      expect(nodes[4].delta?.toPlainText(), '第二幕:社恐の终极挑战');
      expect(
        nodes[5].delta?.toPlainText(),
        '当我抱着简历冲进会议室时,行政总监、HR和部门主管突然集体转身。别问,问就是三堂会审现场。更可怕的是行政总监脖子上挂着"今日段子质检员"工牌,手里还攥着评分表!此时投影仪突然发出放屁般的故障音,大老板推门而入:"听说新同事准备了特别节目?"',
      );
    });
Screenshot 2025-02-27 at 15 51 16

@LucasXu0
Copy link
Collaborator

@Linij according to the test results, it looks like your fix doesn't cover all the cases. It only generates 5 blocks instead of 6.

@Linij
Copy link
Contributor Author

Linij commented Feb 28, 2025

@Linij according to the test results, it looks like your fix doesn't cover all the cases. It only generates 5 blocks instead of 6.

Okay, I will handle it when I have time

@guoz2013
Copy link

guoz2013 commented Mar 1, 2025

@Linij I’m really looking forward to your updates! However, I’ve noticed a small issue recently where the positions of the images seem to get mixed up after an update—for example, the first image becomes the second. I’ll keep following your updates because this tool is incredibly important to me! Thank you so much for all your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants