markdown-live-preview/js/main.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2011-05-17 18:50:41 +04:00
var example = [
"# hello, This is Markdown Live Previewer",
"",
"----",
"## what is Markdown?",
"see [Wikipedia](http://en.wikipedia.org/wiki/Markdown)",
"",
"> Markdown is a lightweight markup language, originally created by John Gruber and Aaron Swartz allowing people \"to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML)\".",
"",
"----",
"## usage",
"1. write markdown text in above textarea",
"2. render automatically to the output area",
"",
"----",
"## thanks",
"* [markdown-js](https://github.com/evilstreak/markdown-js)"
].join("\n");
2011-05-18 19:10:58 +04:00
2011-05-16 20:26:21 +04:00
$(function() {
2011-05-17 18:50:41 +04:00
$("#markdown").val(example);
$("#output").html(markdown.toHTML(example));
$("#output").html(markdown.toHTML(example));
2011-05-16 20:26:21 +04:00
$("#markdown").bind("keyup", function() {
$("#output").html(markdown.toHTML($("#markdown").val()));
});
2011-05-18 19:10:58 +04:00
//reference
$("table#reference tr td:odd").each(function(index, element) {
var self = $(element);
if (self.html() === "") {
self.html(markdown.toHTML(self.siblings().html()));
}
});
2011-05-16 20:26:21 +04:00
});