Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/x-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"dompurify": "^3.2.6",
"html-react-parser": "^5.2.13",
"katex": "^0.16.22",
"marked": "^15.0.12"
"marked": "^16.2.1"
},
"devDependencies": {
"@playwright/experimental-ct-react": "^1.56.1",
Expand Down
18 changes: 18 additions & 0 deletions packages/x-markdown/src/XMarkdown/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,22 @@ describe('streaming', () => {
const tailElement = container.querySelector('.xmd-tail');
expect(tailElement).not.toBeInTheDocument();
});

it('should render tail on the last visible text when content ends with reference definition', () => {
// marked v16.2.0+ emits a standalone `def` token for reference definitions
// (e.g. `[foo]: https://x.com`). The tail should still be attached to the
// previous visible text token, not swallowed by the trailing `def` token.
const { container } = render(
<XMarkdown
content={'Visible paragraph.\n\n[foo]: https://x.com "foo"'}
streaming={{ hasNextChunk: true, tail: true }}
/>,
);

const paragraphs = container.querySelectorAll('p');
expect(paragraphs.length).toBeGreaterThan(0);
const lastParagraph = paragraphs[paragraphs.length - 1];
const tailElement = lastParagraph?.querySelector('.xmd-tail');
expect(tailElement).toBeInTheDocument();
Comment on lines +774 to +778

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

在测试中,如果 paragraphs 为空,paragraphs[paragraphs.length - 1] 将会是 undefined,这会导致 lastParagraph.querySelector 抛出 TypeError 异常,从而掩盖了实际的测试断言失败。建议先断言 paragraphs 存在且长度大于 0,或者使用可选链(optional chaining)来提高测试的健壮性,使测试失败时的错误信息更加清晰。

    const paragraphs = container.querySelectorAll('p');
    expect(paragraphs.length).toBeGreaterThan(0);
    const lastParagraph = paragraphs[paragraphs.length - 1];
    const tailElement = lastParagraph?.querySelector('.xmd-tail');
    expect(tailElement).toBeInTheDocument();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
});
1 change: 1 addition & 0 deletions packages/x/.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const compileModules = [
'is-alphanumerical',
'is-alphabetical',
'decode-named-character-reference',
'marked',
];

const resolve = (p) => require.resolve(`@ant-design/tools/lib/jest/${p}`);
Expand Down
Loading