Skip to content

Commit 329c2d3

Browse files
fix(message-parser): parse emojis and inline elements inside headings
1 parent 3c30636 commit 329c2d3

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
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+
Fix nested emojis and inline markdown elements failing to parse correctly inside of heading blocks.

packages/message-parser/src/grammar.pegjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ CodeChunk = text:$(!EndOfLine !"```" .)+ { return plain(text); }
144144
* #### Heading 4
145145
*
146146
*/
147-
Heading = count:HeadingStart [ \t]+ text:HeadingChunk { return heading([text], count); }
147+
Heading = count:HeadingStart [ \t]+ text:HeadingChunk { return heading(text.map(v => Array.isArray(v) ? v[1] : v), count); }
148148

149149
HeadingStart = value:"#" |1..4| { return value.length; }
150150

151-
HeadingChunk = text:$(!EndOfLine .)+ { return plain(text); }
151+
HeadingChunk = text:(!EndOfLine Inline)+ { return text; }
152+
152153

153154
/**
154155
*

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse } from '../src';
2-
import { heading, lineBreak, mentionChannel, paragraph, plain } from './helpers';
2+
import { emoji, heading, lineBreak, mentionChannel, paragraph, plain } from './helpers';
33

44
test.each([
55
['# h1', [heading([plain('h1')], 1)]],
@@ -44,6 +44,10 @@ test.each([
4444
['He####llo', [paragraph([plain('He####llo')])]],
4545
['# Hello\n', [heading([plain('Hello')], 1), lineBreak()]],
4646
['# # Hello\n', [heading([plain('# Hello')], 1), lineBreak()]],
47+
['# :newspaper: Headline', [heading([emoji('newspaper'), plain(' Headline')], 1)]],
48+
['## Hello :smile:', [heading([plain('Hello '), emoji('smile')], 2)]],
49+
['### :smile: text :newspaper:', [heading([emoji('smile'), plain(' text '), emoji('newspaper')], 3)]],
50+
4751
])('parses %p', (input, output) => {
4852
expect(parse(input)).toMatchObject(output);
4953
});

0 commit comments

Comments
 (0)