Skip to content

Commit 55bf071

Browse files
Copilotggazzo
andauthored
fix: MarkdownText variant document ignoring \n (#38983)
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
1 parent b77fe13 commit 55bf071

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

.changeset/fix-webhook-newline.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes incoming webhook messages ignoring literal `\n` escape sequences, and fixes the `MarkdownText` `document` variant not rendering newlines as line breaks.

apps/meteor/client/components/MarkdownText.spec.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,38 @@ describe('code handling', () => {
434434
});
435435
});
436436

437+
describe('line breaks handling', () => {
438+
it('should convert newlines to <br> in document variant', () => {
439+
const content = 'First Line\nSecond Line\nThird Line';
440+
const { container } = render(<MarkdownText content={content} variant='document' />, {
441+
wrapper: mockAppRoot().build(),
442+
});
443+
444+
const html = container.innerHTML;
445+
expect(html).toContain('First Line<br>Second Line<br>Third Line');
446+
});
447+
448+
it('should convert newlines to <br> in inline variant', () => {
449+
const content = 'First Line\nSecond Line\nThird Line';
450+
const { container } = render(<MarkdownText content={content} variant='inline' />, {
451+
wrapper: mockAppRoot().build(),
452+
});
453+
454+
const html = container.innerHTML;
455+
expect(html).not.toContain('<br>');
456+
});
457+
458+
it('should not convert newlines to <br> in inlineWithoutBreaks variant', () => {
459+
const content = 'First Line\nSecond Line\nThird Line';
460+
const { container } = render(<MarkdownText content={content} variant='inlineWithoutBreaks' />, {
461+
wrapper: mockAppRoot().build(),
462+
});
463+
464+
const html = container.innerHTML;
465+
expect(html).not.toContain('<br>');
466+
});
467+
});
468+
437469
describe('DOMPurify hook registration', () => {
438470
it('should register hook only once at module level', () => {
439471
// Import the module to trigger hook registration

apps/meteor/client/components/MarkdownText.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const defaultOptions = {
7878

7979
const options = {
8080
...defaultOptions,
81+
breaks: true,
8182
renderer: documentRenderer,
8283
};
8384

0 commit comments

Comments
 (0)