Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for \n in CodeMirror runmode #23

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions __tests__/codeMirror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,31 @@ describe('highlight mode', () => {
expect(node.find('.cm-linerow.cm-overlay')).toHaveLength(6);
});
});

describe('runmode', () => {
let node;
const code = `CURL *hnd = curl_easy_init();\n\nurl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");\n\ncurl_easy_setopt(hnd, CURLOPT_URL, "http://httpbin.orgpet/");`;

beforeEach(() => {
node = mount(
syntaxHighlighter(code, 'c', {
dark: true,
highlightMode: true,
tokenizeVariables: true,
ranges: [
[
{ ch: 0, line: 0 },
{ ch: 0, line: 1 },
],
],
})
);
});

it('should display the correct number of lines with multiple linebreaks', () => {
const checkLineBreaks = parseInt(node.find('.cm-linerow').last().find('.cm-lineNumber').text(), 10);
const totalLines = code.split('\n');

expect(checkLineBreaks).toStrictEqual(totalLines.length);
});
});
3 changes: 2 additions & 1 deletion src/codeMirror/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ const ReadmeCodeMirror = (code, lang, opts = { tokenizeVariables: false, highlig
}

CodeMirror.runMode(code, mode, (text, style) => {
if (style !== curStyle) {
const lineBreakRegex = /\r?\n/;
if (style !== curStyle || lineBreakRegex.test(text)) {
flush();
curStyle = style;
accum = text;
Expand Down