-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: Support Remark Line Breaks in Agent Response #6818
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb2fccd
support remark line breaks consistently
bytrangle ca9b525
remove console.log
bytrangle ce2c24a
Merge branch 'dev' into fix_newline
bytrangle a6ee23f
test line break preservation for RenderMarkdown
bytrangle 8ce4415
Merge branch 'dev' into fix_newline
bytrangle 2385803
Update web-app/src/containers/__tests__/RenderMarkdown.test.tsx
louis-jan 42e00a7
Update web-app/src/containers/__tests__/RenderMarkdown.test.tsx
louis-jan 909e441
Update web-app/src/containers/__tests__/RenderMarkdown.test.tsx
louis-jan 51200aa
Update web-app/src/containers/__tests__/RenderMarkdown.test.tsx
louis-jan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { RenderMarkdown } from '../RenderMarkdown'; | ||
|
|
||
| vi.mock('@i18n/react-i18next-compat', () => ({ | ||
| useTranslation: () => ({ | ||
| t: (key: string) => key | ||
| }) | ||
| })) | ||
|
|
||
| // Mock clipboard API | ||
| Object.assign(navigator, { | ||
| clipboard: { | ||
| writeText: vi.fn() | ||
| } | ||
| }) | ||
|
|
||
| describe('RenderMarkdown', () => { | ||
| it('preverses line breaks in model responses (when isUser == undefined)', () => { | ||
louis-jan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const modelREsponseWithNewLines = `This is line 1 | ||
| This is line 2 | ||
| This is line 3` | ||
| render ( | ||
louis-jan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <RenderMarkdown | ||
| content={modelREsponseWithNewLines} | ||
louis-jan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /> | ||
| ) | ||
| const markdownContainer = document.querySelector('.markdown') | ||
| expect(markdownContainer?.innerHTML).toContain('<br>') | ||
| // Match either <br> or <br/> | ||
| const brCount = (markdownContainer?.innerHTML.match(/<br\s*\/?>/g) || []).length | ||
| expect(brCount).toBe(2) | ||
| }) | ||
|
|
||
| it('preserves line breaks in user message (when isUser == true', () => { | ||
louis-jan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const userMessageWithNewlines = `User question line 1 | ||
| User question line 2 | ||
| User question line 3` | ||
| render( | ||
| <RenderMarkdown | ||
| content={userMessageWithNewlines} | ||
| isUser={true} | ||
| /> | ||
| ) | ||
| const markdownContainer = document.querySelector('.markdown') | ||
| expect(markdownContainer).toBeTruthy() | ||
| expect(markdownContainer?.innerHTML).toContain('<br>') | ||
| const brCount = (markdownContainer?.innerHTML.match(/<br\s*\/?>/g) || []).length | ||
| expect(brCount).toBe(2) | ||
| }) | ||
|
|
||
| it('preserves line breaks with different line ending types', () => { | ||
| const contentWithDifferentLineEndings = "Line1\nLine2\r\nLine3\rLine4" | ||
| render( | ||
| <RenderMarkdown | ||
| content={contentWithDifferentLineEndings} | ||
| /> | ||
| ) | ||
| const markdownContainer = document.querySelector('.markdown') | ||
| expect(markdownContainer?.innerHTML).toContain('<br>') | ||
| const brCount = (markdownContainer?.innerHTML.match(/<br\s*\/?>/g) || []).length | ||
| console.log({ brCount }) | ||
louis-jan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| expect(brCount).toBe(3) | ||
louis-jan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| it('handles empty lines correctly', () => { | ||
| const contentWithEmptyLines = 'Line 1\n\nLine 3 (after empty line)\n\nLine 5 (after two empty lines)' | ||
| render( | ||
| <RenderMarkdown | ||
| content={contentWithEmptyLines} | ||
| /> | ||
| ) | ||
| const markdownContainer = document.querySelector('.markdown') | ||
| const html = markdownContainer?.innerHTML || '' | ||
| // Double new lines (`\n\n`) creates paragraph breaks, not line breaks | ||
| expect(html).not.toContain('<br>') | ||
| const paragraphCount = (html.match(/<p>/g) || []).length | ||
| expect(paragraphCount).toBe(3) // Expect 3 paragraphs for 2 empty lines | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.