Skip to content

Commit

Permalink
fix(highlight): no need to disable 'wrap' when 'hljs' is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Nov 19, 2019
1 parent ad3541e commit ef769c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/highlight.js
Expand Up @@ -24,7 +24,6 @@ function highlightUtil(str, options = {}) {
const lang = options.lang || data.language || '';
const classNames = (useHljs ? 'hljs' : 'highlight') + (lang ? ` ${lang}` : '');

if (useHljs && !gutter) wrap = false;
if (gutter && !wrap) wrap = true; // arbitrate conflict ("gutter:true" takes priority over "wrap:false")

const before = useHljs ? `<pre><code class="${classNames}">` : '<pre>';
Expand Down
18 changes: 17 additions & 1 deletion test/highlight.spec.js
Expand Up @@ -295,11 +295,27 @@ describe('highlight', () => {
' return false;',
'}'
].join('\n');
const result = highlight(str, {hljs: true, gutter: false, lang: 'javascript'});
const result = highlight(str, {hljs: true, gutter: false, wrap: false, lang: 'javascript'});
result.should.not.include(gutterStart);
result.should.not.include(codeStart);
result.should.include('code class="hljs javascript"');
result.should.include('class="hljs-function"');
validateHtmlAsync(result, done);
});

it('hljs compatibility - wrap is true', done => {
const str = [
'function (a) {',
' if (a > 3)',
' return true;',
' return false;',
'}'
].join('\n');
const result = highlight(str, {hljs: true, gutter: false, wrap: true, lang: 'javascript'});
result.should.not.include(gutterStart);
result.should.include(codeStart);
result.should.include('code class="hljs javascript"');
result.should.include('class="hljs-function"');
validateHtmlAsync(result, done);
});
});

0 comments on commit ef769c2

Please sign in to comment.