appflowy-editor icon indicating copy to clipboard operation
appflowy-editor copied to clipboard

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

Open Linij opened this issue 9 months ago • 6 comments

![](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.

Linij avatar Feb 27 '25 03:02 Linij

Hi, @Linij. Please format your code.

LucasXu0 avatar Feb 27 '25 06:02 LucasXu0

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 :warning:
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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 27 '25 06:02 codecov[bot]

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 avatar Feb 27 '25 07:02 LucasXu0

@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.

LucasXu0 avatar Feb 28 '25 02:02 LucasXu0

@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

Linij avatar Feb 28 '25 06:02 Linij

@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!

guoz2013 avatar Mar 01 '25 15:03 guoz2013