Closed DavidZemon closed 7 years ago
It seems that Raw version uses highlight.js 9.6.0, and Angular version uses highlight.js 8.9.1 . Sync there version will produce the same output.
Here's Angular version with highlight.js 9.6.0 https://jsfiddle.net/arp4a21t/
Maybe it's a browser difference? Still broken for me:
I'm running Ubuntu 16.10 x64, Chrome 53.0.2785.101 (64-bit)
I find this is actually a bug of angular-highlightjs. While trying to strip new lines from the head of the code, the regex doesn't work as expected.
https://github.com/pc035860/angular-highlightjs/blob/master/src/angular-highlightjs.js#L283
// get static code
// strip the starting "new line" character
var staticHTML = tElm[0].innerHTML.replace(/^(\r\n|\r|\n)/m, ''),
staticText = tElm[0].textContent.replace(/^(\r\n|\r|\n)/m, '');
I'll get this fixed soon. Thanks for the report!
To find a new line at index 0, skip the m
modifier:
.replace(/^(\r\n|\r|\n)/, '')
Or alternatively you could just trim whitespace at start/end.
Trim start:
.replace(/^\s+/g, '')
Trim start and end:
.replace(/^\s+|\s+$/g, '')
Would love if this gets fixed =)
@n4bb1 Thanks for the advice. Just got it fixed and published a new version.
Thanks man.
I am also having the same issue with the include-directive: https://github.com/pc035860/angular-highlightjs/blob/master/src/angular-highlightjs.js#L467
Raw hljs works as expected, but you'll notice one of the blank lines in the code block is removed when using angular-highlightjs
Raw: https://jsfiddle.net/a1vh98ws/1/ Angular: https://jsfiddle.net/Lasdvo33/1/