Skip to content

Commit 5f9296f

Browse files
Copilotggazzo
authored andcommitted
fix: markdown breaking on bracketed text between hyperlinks (RocketChat#38629)
Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz>
1 parent 632a086 commit 5f9296f

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/message-parser": patch
3+
---
4+
5+
Fixes markdown breaking when text in square brackets appears between hyperlinks. This resolves issues #31418 and #31766 where typing `[text]` between links would incorrectly parse the markdown structure.

packages/message-parser/src/grammar.pegjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ References
278278
= "[" title:LinkTitle* "](" href:LinkRef ")" { return title.length ? link(href, reducePlainTexts(title)) : link(href); }
279279
/ "<" href:LinkRef "|" title:LinkTitle2 ">" { return link(href, [plain(title)]); }
280280

281-
LinkTitle = (Whitespace / Emphasis) / anyTitle:$(!("](" .) .) { return plain(anyTitle) }
281+
LinkTitle = (Whitespace / Emphasis) / anyTitle:$(!("](" .) !("] [" [^\]]* "](") .) { return plain(anyTitle) }
282282

283283
LinkTitle2 = $([\x20-\x3B\x3D\x3F-\x60\x61-\x7B\x7D-\xFF] / NonASCII)+
284284

@@ -323,7 +323,7 @@ DomainName
323323
324324
DomainNameLabel = $(DomainChar+ ("-" DomainChar+)*)
325325
326-
DomainChar = !Extra ([\__-] / !Safe) !EndOfLine !Space ![\\/|><%`] .
326+
DomainChar = !Extra ([\__-] / !Safe) !EndOfLine !Space ![\\/|><%`\[\]] .
327327

328328
/**
329329
*

packages/message-parser/tests/link.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,26 @@ Text after line break`,
385385
'[test **bold with __italic__**](https://rocket.chat)',
386386
[paragraph([link('https://rocket.chat', [plain('test '), bold([plain('bold with '), italic([plain('italic')])])])])],
387387
],
388+
// Test case for issue #31418 - text in brackets between two links should not break markdown
389+
[
390+
'[Rocket.Chat] [New release](https://www.rocket.chat/blog/new-starter-pro-plans)',
391+
[paragraph([plain('[Rocket.Chat] '), link('https://www.rocket.chat/blog/new-starter-pro-plans', [plain('New release')])])],
392+
],
393+
// Test case for issue #31766 - multiple links with bracketed text between them
394+
[
395+
'[BUG #11111](https://github.com/) - [BACK] changelog description',
396+
[paragraph([link('https://github.com/', [plain('BUG #11111')]), plain(' - [BACK] changelog description')])],
397+
],
398+
[
399+
'[BUG #11111](https://github.com/) - [BACK] [Another link](https://github.com/)',
400+
[
401+
paragraph([
402+
link('https://github.com/', [plain('BUG #11111')]),
403+
plain(' - [BACK] '),
404+
link('https://github.com/', [plain('Another link')]),
405+
]),
406+
],
407+
],
388408
])('parses %p', (input, output) => {
389409
expect(parse(input)).toMatchObject(output);
390410
});

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8583,7 +8583,7 @@ __metadata:
85838583
"@rocket.chat/css-in-js": "*"
85848584
"@rocket.chat/fuselage": "*"
85858585
"@rocket.chat/fuselage-tokens": "*"
8586-
"@rocket.chat/message-parser": 0.31.33-rc.0
8586+
"@rocket.chat/message-parser": 0.31.33
85878587
"@rocket.chat/styled": "*"
85888588
"@rocket.chat/ui-client": "workspace:^"
85898589
"@rocket.chat/ui-contexts": "workspace:^"
@@ -10435,7 +10435,7 @@ __metadata:
1043510435
peerDependencies:
1043610436
"@rocket.chat/layout": "*"
1043710437
"@rocket.chat/tools": 0.2.4
10438-
"@rocket.chat/ui-contexts": 27.0.0-rc.2
10438+
"@rocket.chat/ui-contexts": 27.0.0
1043910439
"@tanstack/react-query": "*"
1044010440
react: "*"
1044110441
react-hook-form: "*"

0 commit comments

Comments
 (0)