Skip to content

Instantly share code, notes, and snippets.

@jackmaney
Created September 12, 2013 10:26
Show Gist options
  • Save jackmaney/6535481 to your computer and use it in GitHub Desktop.
Save jackmaney/6535481 to your computer and use it in GitHub Desktop.
Converting markdown in a textarea to HTML. Also uses the Tabby jQuery extension to allow tabs in textareas.
<!doctype html>
<html>
<head>
<title>Marked test</title>
<script type="text/javascript" src="js/marked.js"></script> <!-- https://github.com/chjj/marked -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="js/jquery.textarea.js"></script> <!-- https://github.com/alanhogan/Tabby -->
<script type="text/javascript">
$(document).ready(function(){
$("#blah").tabby();
$("#btn").click(function(evt){
evt.preventDefault();
$(".output").html(marked($("#blah").val()));
});
});
</script>
<style type="text/css">.output{border:1px solid red;margin-top: 20px;}</style>
</head>
<body>
<textarea id="blah" cols = "150" rows = "30"></textarea>
<button id="btn">Markdown -> HTML</button>
<div class="output"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment