Last active
December 22, 2015 04:39
-
-
Save Sleepingwell/6418936 to your computer and use it in GitHub Desktop.
An example of using showdown to parse markdown in a web page + 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
<html> | |
<!-- based example found at: http://blog.harakys.com/blog/2012/02/21/embed-markdown-into-your-html/ --> | |
<header> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> | |
<script src="https://google-code-prettify.googlecode.com/svn/loader/prettify.js"></script> | |
<script src="http://www.showdown.im/showdown/example/showdown.js"> </script> | |
<script type="text/javascript"> | |
var generateHTML = function() { | |
// replace markdown text | |
$('script[type="text/markdown"]').after(function(index){ | |
converter = new Showdown.converter(); | |
return converter.makeHtml(this.textContent); | |
}); | |
}; | |
var updateMarkdown = function() { | |
generateHTML(); | |
prettyPrint(); | |
}; | |
</script> | |
</header> | |
<body> | |
<article> | |
<script type="text/markdown"> | |
The nice title here | |
= | |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus diam sem. | |
then a little list | |
- item 1 | |
- item2 | |
And some code... | |
<pre class="prettyprint lang-c"> | |
class Silly { | |
Silly(int val) | |
: val_(val) { | |
} | |
int getVal(void) const { | |
return val_; | |
} | |
private: | |
int | |
val_; | |
}; | |
</pre> | |
</script> | |
</article> | |
<script> | |
//generateHTML(); | |
</script> | |
<input type="button" onclick="updateMarkdown()" /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment