Last active
August 29, 2017 14:26
-
-
Save nielsnuebel/fecc7a7a9bf556f79d801c502a3a3932 to your computer and use it in GitHub Desktop.
with this script, it's possible to use fragment in highlight.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom reveal.js integration | |
(function(){ | |
if( typeof window.addEventListener === 'function' ) { | |
var hljs_nodes = document.querySelectorAll( 'pre code' ); | |
for( var i = 0, len = hljs_nodes.length; i < len; i++ ) { | |
var element = hljs_nodes[i]; | |
// Now escape html unless prevented by author | |
if( ! element.hasAttribute( 'data-fragment' )) { | |
var regexp = /<mark class="fragment/g; | |
while ((match = regexp.exec(element.innerHTML)) != null) { | |
var replace = '<span' + element.innerHTML.substring(match.index+8, match.index + element.innerHTML.substring(match.index).indexOf('>')) + '>'; | |
replace = replace + element.innerHTML.substring(match.index + element.innerHTML.substring(match.index).indexOf('>')+4, match.index + element.innerHTML.substring(match.index).indexOf('</mark>')) + '</span>'; | |
var search = element.innerHTML.substring(match.index, match.index + element.innerHTML.substring(match.index).indexOf('</mark>')+13); | |
element.innerHTML = element.innerHTML.replace(search, replace); | |
} | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment