File tree Expand file tree Collapse file tree 3 files changed +20
-9
lines changed
Expand file tree Collapse file tree 3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Parser Engine:
99- (enh) Added ` on:end ` callback for modes (#2261 ) [ Josh Goebel] [ ]
1010- (enh) Added ability to programatically ignore begin and end matches (#2261 ) [ Josh Goebel] [ ]
1111- (enh) Added ` END_SAME_AS_BEGIN ` mode to replace ` endSameAsBegin ` parser attribute (#2261 ) [ Josh Goebel] [ ]
12+ - (fix) ` fixMarkup ` would rarely destroy markup when ` useBR ` was enabled (#2532 ) [ Josh Goebel] [ ]
1213
1314Deprecations:
1415
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ const HLJS = function(hljs) {
3232 var SAFE_MODE = true ;
3333
3434 // Regular expressions used throughout the highlight.js library.
35- var fixMarkupRe = / ( ( ^ ( < [ ^ > ] + > | \t | ) + | (?: \n ) ) ) / gm;
35+ var fixMarkupRe = / ( ^ ( < [ ^ > ] + > | \t | ) + | \n ) / gm;
3636
3737 var LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?" ;
3838
@@ -540,13 +540,13 @@ const HLJS = function(hljs) {
540540 return value ;
541541 }
542542
543- return value . replace ( fixMarkupRe , function ( match , p1 ) {
544- if ( options . useBR && match === '\n' ) {
545- return '<br>' ;
543+ return value . replace ( fixMarkupRe , match => {
544+ if ( match === '\n' ) {
545+ return options . useBR ? '<br>' : match ;
546546 } else if ( options . tabReplace ) {
547- return p1 . replace ( / \t / g, options . tabReplace ) ;
547+ return match . replace ( / \t / g, options . tabReplace ) ;
548548 }
549- return '' ;
549+ return match ;
550550 } ) ;
551551 }
552552
Original file line number Diff line number Diff line change @@ -5,11 +5,21 @@ const hljs = require('../../build');
55
66describe ( '.fixmarkup()' , ( ) => {
77 after ( ( ) => {
8- hljs . configure ( { useBR : false } )
9- } )
8+ hljs . configure ( { useBR : false } ) ;
9+ } ) ;
10+
11+ it ( 'should not strip HTML from beginning of strings' , ( ) => {
12+ hljs . configure ( { useBR : true } ) ;
13+ const value = '<span class="hljs-attr">"some"</span>: \n <span class="hljs-string">"json"</span>' ;
14+ const result = hljs . fixMarkup ( value ) ;
15+
16+ result . should . equal (
17+ '<span class="hljs-attr">"some"</span>: <br> <span class="hljs-string">"json"</span>'
18+ ) ;
19+ } ) ;
1020
1121 it ( 'should not add "undefined" to the beginning of the result (#1452)' , ( ) => {
12- hljs . configure ( { useBR : true } )
22+ hljs . configure ( { useBR : true } ) ;
1323 const value = '{ <span class="hljs-attr">"some"</span>: \n <span class="hljs-string">"json"</span> }' ;
1424 const result = hljs . fixMarkup ( value ) ;
1525
You can’t perform that action at this time.
0 commit comments