Skip to content

Commit 4f34ef6

Browse files
authored
fix: trailing bracket in json with highlightMode enabled (#66)
1 parent ad4072d commit 4f34ef6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

__tests__/codeMirror.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ test('should work with modes', () => {
4040
);
4141
});
4242

43+
test('should keep trailing json bracket if highlightMode is enabled', () => {
44+
expect(
45+
shallow(
46+
syntaxHighlighter('{ "a": 1 }', 'json', {
47+
highlightMode: true,
48+
})
49+
).html()
50+
).toBe(
51+
'<div class="cm-s-neo CodeEditor"><div class="CodeMirror"><div class="cm-linerow "><span class="cm-lineNumber">1</span>{ <span class="cm-property">&quot;a&quot;</span>: <span class="cm-number">1</span> }</div></div></div>'
52+
);
53+
});
54+
4355
test('should have a dark theme', () => {
4456
expect(shallow(syntaxHighlighter('{ "a": 1 }', 'json', { dark: true })).hasClass('cm-s-material-palenight')).toBe(
4557
true

src/codeMirror/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const StyledSyntaxHighlighter = ({ output, ranges }) => {
8686

8787
const enumerateMatches = (o, final) => {
8888
// Case where a single line break
89-
if (o.length === 1) {
89+
if (o.length === 1 && lineBreakRegex.test(o)) {
9090
incrementLine(true);
9191
// Case with multiple consecutive line breaks
9292
} else {

0 commit comments

Comments
 (0)