Skip to content

Instantly share code, notes, and snippets.

@GochoMugo
Last active April 19, 2019 00:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GochoMugo/ed1299bdd8e0d664faec to your computer and use it in GitHub Desktop.
Save GochoMugo/ed1299bdd8e0d664faec to your computer and use it in GitHub Desktop.
Prism-Markdown
/*
* 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();
@GochoMugo
Copy link
Author

I'm using this code in here. Feel free to share this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment