Last active
September 28, 2016 07:19
-
-
Save denisorehovsky/e6d096544fd3da78f9f4bd927a6ddcb3 to your computer and use it in GitHub Desktop.
Markdown and syntax highlighting
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
/* | |
jquery.min.js, showdown.min.js, prism.js and prism.css must be loaded | |
The container that will hold markdown should be have the class | |
'content-markdown'. | |
Place code in between: | |
1. $$name_of_language$$ code_goes_here $$end$$ (inline-code) | |
2. $name_of_language$ code_goes_here $end$ (block-code) | |
E.g. | |
<section class='content-markdown'> | |
$python$ | |
import firebasin | |
my_firebase = firebasin.Firebase("https://my_firebase_name.firebaseio.com") | |
$end$ | |
</section> | |
*/ | |
$(document).ready(function(){ | |
var converter = new Showdown.converter(); | |
$(".content-markdown").each(function () { | |
var markdown = $(this).text().trim(), | |
html; | |
markdown = markdown.replace(/(\s+)\$\$end\$\$(\s+)/g, "$1</code>$2"); | |
markdown = markdown.replace(/(\s+)\$\$([^\$]+)\$\$(\n?)(\s+)/g, "$1<code class='language-$2'>$3"); | |
markdown = markdown.replace(/(\s+)\$end\$(\s+)/g, "$1</code></pre>$2"); | |
markdown = markdown.replace(/(\s+)\$([^\$]+)\$(\n?)(\s+)/g, "$1<pre><code class='language-$2'>$3"); | |
html = converter.makeHtml(markdown); | |
$(this).empty().append(html); | |
}); | |
Prism.highlightAll(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment