Skip to content

Commit 423cd67

Browse files
committed
fix: Add bold to excludeRangeTypesFromFormatting to fix emoji duplication on web
1 parent 08e139e commit 423cd67

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

src/__tests__/splitRangesOnEmojis.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,41 @@ describe('single overlap', () => {
109109
{type: 'emoji', start: 4, length: 2},
110110
]);
111111
});
112+
113+
test('bold with emoji in the middle', () => {
114+
let markdownRanges: MarkdownRange[] = [
115+
{type: 'bold', start: 0, length: 10},
116+
{type: 'emoji', start: 3, length: 2},
117+
];
118+
119+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'bold', getRangesToExcludeFormatting(markdownRanges));
120+
sortRanges(markdownRanges);
121+
122+
expect(markdownRanges).toEqual([
123+
{type: 'bold', start: 0, length: 3},
124+
{type: 'emoji', start: 3, length: 2},
125+
{type: 'bold', start: 5, length: 5},
126+
]);
127+
});
128+
129+
test('bold with multiple emojis', () => {
130+
let markdownRanges: MarkdownRange[] = [
131+
{type: 'bold', start: 0, length: 10},
132+
{type: 'emoji', start: 2, length: 2},
133+
{type: 'emoji', start: 6, length: 2},
134+
];
135+
136+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'bold', getRangesToExcludeFormatting(markdownRanges));
137+
sortRanges(markdownRanges);
138+
139+
expect(markdownRanges).toEqual([
140+
{type: 'bold', start: 0, length: 2},
141+
{type: 'emoji', start: 2, length: 2},
142+
{type: 'bold', start: 4, length: 2},
143+
{type: 'emoji', start: 6, length: 2},
144+
{type: 'bold', start: 8, length: 2},
145+
]);
146+
});
112147
});
113148

114149
describe('multiple overlaps', () => {
@@ -160,4 +195,47 @@ describe('multiple overlaps', () => {
160195
{type: 'strikethrough', start: 22, length: 5},
161196
]);
162197
});
198+
199+
test('splitting on three types', () => {
200+
let markdownRanges: MarkdownRange[] = [
201+
{type: 'italic', start: 0, length: 20},
202+
{type: 'bold', start: 2, length: 12},
203+
{type: 'strikethrough', start: 4, length: 8},
204+
{type: 'emoji', start: 6, length: 2},
205+
];
206+
207+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'italic', getRangesToExcludeFormatting(markdownRanges));
208+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'bold', getRangesToExcludeFormatting(markdownRanges));
209+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'strikethrough', getRangesToExcludeFormatting(markdownRanges));
210+
sortRanges(markdownRanges);
211+
212+
expect(markdownRanges).toEqual([
213+
{type: 'italic', start: 0, length: 6},
214+
{type: 'bold', start: 2, length: 4},
215+
{type: 'strikethrough', start: 4, length: 2},
216+
{type: 'emoji', start: 6, length: 2},
217+
{type: 'italic', start: 8, length: 12},
218+
{type: 'bold', start: 8, length: 6},
219+
{type: 'strikethrough', start: 8, length: 4},
220+
]);
221+
});
222+
223+
test('nested ranges with emoji', () => {
224+
let markdownRanges: MarkdownRange[] = [
225+
{type: 'italic', start: 1, length: 15},
226+
{type: 'bold', start: 5, length: 7},
227+
{type: 'emoji', start: 10, length: 2},
228+
];
229+
230+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'italic', getRangesToExcludeFormatting(markdownRanges));
231+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'bold', getRangesToExcludeFormatting(markdownRanges));
232+
sortRanges(markdownRanges);
233+
234+
expect(markdownRanges).toEqual([
235+
{type: 'italic', start: 1, length: 9},
236+
{type: 'bold', start: 5, length: 5},
237+
{type: 'emoji', start: 10, length: 2},
238+
{type: 'italic', start: 12, length: 4},
239+
]);
240+
});
163241
});

src/parseExpensiMark.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,10 @@ function parseExpensiMark(markdown: string): MarkdownRange[] {
256256
}
257257
let markdownRanges = sortRanges(ranges);
258258

259-
// Prevent italic and strikethrough formatting inside emojis and inline code blocks
259+
// Prevent italic, bold and strikethrough formatting inside emojis and inline code blocks
260260
const rangesToExclude = getRangesToExcludeFormatting(markdownRanges);
261261
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'italic', rangesToExclude);
262+
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'bold', rangesToExclude);
262263
markdownRanges = excludeRangeTypesFromFormatting(markdownRanges, 'strikethrough', rangesToExclude);
263264

264265
const groupedRanges = groupRanges(markdownRanges);

0 commit comments

Comments
 (0)