Skip to content

Commit b95456e

Browse files
committed
Add unit test
1 parent 44864e7 commit b95456e

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import React from 'react';
10+
import { render } from '../../../../test/rtl';
11+
import { EuiMarkdownFormat } from '../../index';
12+
13+
describe('remarkIntrawordUnderscore', () => {
14+
it('preserves identifiers with double underscores as plain text', () => {
15+
const { container } = render(
16+
<EuiMarkdownFormat>
17+
{`ABDC__AppleBanana__c
18+
ABDC__MangoKiwi__c
19+
ABDC__PineappleCherry__c`}
20+
</EuiMarkdownFormat>
21+
);
22+
23+
expect(container.querySelector('strong')).not.toBeInTheDocument();
24+
expect(container).toHaveTextContent('ABDC__AppleBanana__c');
25+
expect(container).toHaveTextContent('ABDC__MangoKiwi__c');
26+
expect(container).toHaveTextContent('ABDC__PineappleCherry__c');
27+
});
28+
29+
it('preserves identifiers with single underscores as plain text', () => {
30+
const { container } = render(
31+
<EuiMarkdownFormat>{'some_variable_name'}</EuiMarkdownFormat>
32+
);
33+
34+
expect(container.querySelector('em')).not.toBeInTheDocument();
35+
expect(container).toHaveTextContent('some_variable_name');
36+
});
37+
38+
it('still applies bold for standalone double underscores', () => {
39+
const { container } = render(
40+
<EuiMarkdownFormat>{'__bold text__'}</EuiMarkdownFormat>
41+
);
42+
43+
expect(container.querySelector('strong')).toHaveTextContent('bold text');
44+
});
45+
46+
it('still applies emphasis for standalone single underscores', () => {
47+
const { container } = render(
48+
<EuiMarkdownFormat>{'_italic text_'}</EuiMarkdownFormat>
49+
);
50+
51+
expect(container.querySelector('em')).toHaveTextContent('italic text');
52+
});
53+
54+
it('handles multiple identifiers in a sentence', () => {
55+
const { container } = render(
56+
<EuiMarkdownFormat>
57+
{'Fields ABDC__AppleBanana__c and ABDC__MangoKiwi__c are required'}
58+
</EuiMarkdownFormat>
59+
);
60+
61+
expect(container.querySelector('strong')).not.toBeInTheDocument();
62+
expect(container).toHaveTextContent(
63+
'Fields ABDC__AppleBanana__c and ABDC__MangoKiwi__c are required'
64+
);
65+
});
66+
});

packages/eui/src/components/markdown_editor/plugins/remark/remark_intraword_underscore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// remark-parse v8 doesn't implement the CommonMark rule that underscore
1111
// emphasis delimiters flanked by alphanumerics on both sides (intraword)
1212
// cannot open or close emphasis. This causes identifiers like
13-
// `SBQQ__OrderProductBookings__c` to render with bold formatting.
13+
// `ABCD__PineappleCherry__e` to render with bold formatting.
1414
// This plugin walks the parsed AST and reverses incorrectly applied
1515
// emphasis/strong nodes when both sides are alphanumeric characters.
1616

0 commit comments

Comments
 (0)