diff --git a/__tests__/codeMirror.test.js b/__tests__/codeMirror.test.js index 2760375..505bfbd 100644 --- a/__tests__/codeMirror.test.js +++ b/__tests__/codeMirror.test.js @@ -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); + }); +}); diff --git a/src/codeMirror/index.jsx b/src/codeMirror/index.jsx index b53d73d..cf67a65 100644 --- a/src/codeMirror/index.jsx +++ b/src/codeMirror/index.jsx @@ -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;