Last active
August 29, 2015 14:23
-
-
Save perrupa/d50d11551acfffa52b3c to your computer and use it in GitHub Desktop.
Automatically generate code blocks
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
/* | |
Find all code wrapped in .exampleCode classes and generate | |
a highlighted code block to insert in the DOM after it | |
*/ | |
$(".exampleCode").each(function(){ | |
var $example = $(this), | |
code = $example.html(), | |
$preBlock = $("<pre></pre>").append( $("<code></code>").text(code) ); | |
// Insert code block *after* the example div | |
$example.after( $preBlock ); | |
// Find inserted <pre/> in the DOM.. | |
var codeBlock = $example.next().get(0); | |
// ..Highlight the code block with hljs (https://highlightjs.org/) | |
hljs.highlightBlock( codeBlock, null ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment