File tree 3 files changed +20
-9
lines changed
3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Parser Engine:
9
9
- (enh) Added ` on:end ` callback for modes (#2261 ) [ Josh Goebel] [ ]
10
10
- (enh) Added ability to programatically ignore begin and end matches (#2261 ) [ Josh Goebel] [ ]
11
11
- (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] [ ]
12
13
13
14
Deprecations:
14
15
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ const HLJS = function(hljs) {
32
32
var SAFE_MODE = true ;
33
33
34
34
// Regular expressions used throughout the highlight.js library.
35
- var fixMarkupRe = / ( ( ^ ( < [ ^ > ] + > | \t | ) + | (?: \n ) ) ) / gm;
35
+ var fixMarkupRe = / ( ^ ( < [ ^ > ] + > | \t | ) + | \n ) / gm;
36
36
37
37
var LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?" ;
38
38
@@ -540,13 +540,13 @@ const HLJS = function(hljs) {
540
540
return value ;
541
541
}
542
542
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 ;
546
546
} else if ( options . tabReplace ) {
547
- return p1 . replace ( / \t / g, options . tabReplace ) ;
547
+ return match . replace ( / \t / g, options . tabReplace ) ;
548
548
}
549
- return '' ;
549
+ return match ;
550
550
} ) ;
551
551
}
552
552
Original file line number Diff line number Diff line change @@ -5,11 +5,21 @@ const hljs = require('../../build');
5
5
6
6
describe ( '.fixmarkup()' , ( ) => {
7
7
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
+ } ) ;
10
20
11
21
it ( 'should not add "undefined" to the beginning of the result (#1452)' , ( ) => {
12
- hljs . configure ( { useBR : true } )
22
+ hljs . configure ( { useBR : true } ) ;
13
23
const value = '{ <span class="hljs-attr">"some"</span>: \n <span class="hljs-string">"json"</span> }' ;
14
24
const result = hljs . fixMarkup ( value ) ;
15
25
You can’t perform that action at this time.
0 commit comments