Last active
April 19, 2019 00:11
-
-
Save GochoMugo/ed1299bdd8e0d664faec to your computer and use it in GitHub Desktop.
Prism-Markdown
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 piece of code uses jQuery | |
* | |
* I'm also using Showdown to convert my markdown to html. | |
* You can get a copy from | |
* http://softwaremaniacs.org/playground/showdown-highlight/showdown.js | |
* | |
* I'm also using Prism.js from http://prismjs.com/ | |
* to syntax-highlight my code. | |
* | |
* It goes without saying that the jQuery, Showdown and Prism should be | |
* loaded before this code | |
* | |
* The container that will hold your markdown should be have the class | |
* '.markdown'. | |
* Place your 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='markdown-prism'> | |
* | |
* $python$ | |
* import firebasin | |
* my_firebase = firebasin.Firebase("https://my_firebase_name.firebaseio.com") | |
* $end$ | |
* | |
* </section> | |
*/ | |
var converter = new Showdown.converter(); | |
$(".markdown-prism").each(function () { | |
var markdown = $(this).html(), | |
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
I'm using this code in here. Feel free to share this.