forked from asciidoctor/asciidoctor-reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves asciidoctor#21 load highlight.js from a CDN
- Loading branch information
1 parent
7e53bd9
commit 470fc6d
Showing
4 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* DO NOT MANUALLY EDIT THIS FILE */ | ||
/* this file was copied-pasted from https://github.com/hakimel/reveal.js/blob/3.7.0/plugin/highlight/highlight.js */ | ||
/* please note that the bundled highlight.js code was removed so we can use a more recent version */ | ||
(function() { | ||
// Function to perform a better "data-trim" on code snippets | ||
// Will slice an indentation amount on each line of the snippet (amount based on the line having the lowest indentation length) | ||
function betterTrim(snippetEl) { | ||
// Helper functions | ||
function trimLeft(val) { | ||
// Adapted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill | ||
return val.replace(/^[\s\uFEFF\xA0]+/g, ''); | ||
} | ||
function trimLineBreaks(input) { | ||
var lines = input.split('\n'); | ||
|
||
// Trim line-breaks from the beginning | ||
for (var i = 0; i < lines.length; i++) { | ||
if (lines[i].trim() === '') { | ||
lines.splice(i--, 1); | ||
} else break; | ||
} | ||
|
||
// Trim line-breaks from the end | ||
for (var i = lines.length-1; i >= 0; i--) { | ||
if (lines[i].trim() === '') { | ||
lines.splice(i, 1); | ||
} else break; | ||
} | ||
|
||
return lines.join('\n'); | ||
} | ||
|
||
// Main function for betterTrim() | ||
return (function(snippetEl) { | ||
var content = trimLineBreaks(snippetEl.innerHTML); | ||
var lines = content.split('\n'); | ||
// Calculate the minimum amount to remove on each line start of the snippet (can be 0) | ||
var pad = lines.reduce(function(acc, line) { | ||
if (line.length > 0 && trimLeft(line).length > 0 && acc > line.length - trimLeft(line).length) { | ||
return line.length - trimLeft(line).length; | ||
} | ||
return acc; | ||
}, Number.POSITIVE_INFINITY); | ||
// Slice each line with this amount | ||
return lines.map(function(line, index) { | ||
return line.slice(pad); | ||
}) | ||
.join('\n'); | ||
})(snippetEl); | ||
} | ||
|
||
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]; | ||
|
||
// trim whitespace if data-trim attribute is present | ||
if( element.hasAttribute( 'data-trim' ) && typeof element.innerHTML.trim === 'function' ) { | ||
element.innerHTML = betterTrim(element); | ||
} | ||
|
||
// Now escape html unless prevented by author | ||
if( ! element.hasAttribute( 'data-noescape' )) { | ||
element.innerHTML = element.innerHTML.replace(/</g,"<").replace(/>/g,">"); | ||
} | ||
|
||
// re-highlight when focus is lost (for edited code) | ||
element.addEventListener( 'focusout', function( event ) { | ||
hljs.highlightBlock( event.currentTarget ); | ||
}, false ); | ||
} | ||
} | ||
})(); | ||
|
||
hljs.initHighlightingOnLoad(); |
This file contains 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
This file contains 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