@@ -18,12 +18,15 @@ function highlightUtil(str, options) {
1818 var tab = options . tab ;
1919
2020 hljs . configure ( { classPrefix : useHljs ? 'hljs-' : '' } ) ;
21- // If modern hljs support is enabled and there's no gutter, don't wrap the code block.
22- if ( useHljs && ! gutter ) wrap = false ;
2321
2422 var data = highlight ( str , options ) ;
2523
26- if ( ! wrap ) return data . value ;
24+ if ( useHljs && ! gutter ) wrap = false ;
25+
26+ var before = useHljs ? '<pre><code class="hljs ' + options . lang + '">' : '<pre>' ;
27+ var after = useHljs ? '</code></pre>' : '</pre>' ;
28+
29+ if ( ! wrap ) return useHljs ? before + data . value + after : data . value ;
2730
2831 var lines = data . value . split ( '\n' ) ;
2932 var numbers = '' ;
@@ -50,7 +53,7 @@ function highlightUtil(str, options) {
5053 result += '<td class="gutter"><pre>' + numbers + '</pre></td>' ;
5154 }
5255
53- result += '<td class="code"><pre> ' + content + '</pre> </td>';
56+ result += '<td class="code">' + before + content + after + ' </td>';
5457 result += '</tr></table></figure>' ;
5558
5659 return result ;
@@ -130,17 +133,13 @@ function highlight(str, options) {
130133 return result ;
131134 }
132135
133- if ( options . hljs ) {
134- var res = hljs . highlight ( lang , str ) ;
135- res . value = [ '<pre><code class="hljs ' + lang + '">' , res . value , '</code></pre>' ] . join ( '\n' ) ;
136- return res ;
137- }
138-
139136 if ( ! tryLanguage ( result . language ) ) {
140137 result . language = 'plain' ;
141138 return result ;
142139 }
143140
141+ if ( options . hljs ) return hljs . highlight ( lang , str ) ;
142+
144143 return tryHighlight ( str , result . language ) || result ;
145144}
146145
0 commit comments