summaryrefslogtreecommitdiff
path: root/js/dingus.html
diff options
context:
space:
mode:
Diffstat (limited to 'js/dingus.html')
-rw-r--r--js/dingus.html134
1 files changed, 134 insertions, 0 deletions
diff --git a/js/dingus.html b/js/dingus.html
new file mode 100644
index 0000000..ecaeb33
--- /dev/null
+++ b/js/dingus.html
@@ -0,0 +1,134 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>commonmark.js demo</title>
+ <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
+ <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
+ <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
+ <script src="commonmark.js"></script>
+ <script type="text/javascript">
+
+var writer = new commonmark.HtmlRenderer();
+var reader = new commonmark.DocParser();
+
+function getQueryVariable(variable)
+{
+ var query = window.location.search.substring(1);
+ var vars = query.split("&");
+ for (var i=0;i<vars.length;i++) {
+ var pair = vars[i].split("=");
+ if(pair[0] == variable){return decodeURIComponent(pair[1]);}
+ }
+ return('');
+}
+
+
+$(document).ready(function() {
+ $("#text").val(getQueryVariable("text"));
+ var timer;
+ var x;
+ var parsed;
+ var render = function() {
+ if (parsed === undefined) {
+ return;
+ }
+ var startTime = new Date().getTime();
+ var result = writer.renderBlock(parsed);
+ var endTime = new Date().getTime();
+ var renderTime = endTime - startTime;
+ // $("#html").text(result);
+ $("#preview").html(result);
+ $("#html").text(result);
+ $("#ast").text(commonmark.ASTRenderer(parsed));
+ $("#rendertime").text(renderTime);
+ };
+ var parseAndRender = function () {
+ if (x) { x.abort() } // If there is an existing XHR, abort it.
+ clearTimeout(timer); // Clear the timer so we don't end up with dupes.
+ timer = setTimeout(function() { // assign timer a new timeout
+ var startTime = new Date().getTime();
+ parsed = reader.parse($("#text").val());
+ var endTime = new Date().getTime();
+ var parseTime = endTime - startTime;
+ $("#parsetime").text(parseTime);
+ $(".timing").css('visibility','visible');
+ /*
+ var warnings = parsed.warnings;
+ $("#warnings").html('');
+ for (i=0; i < warnings.length; i++) {
+ var w = warnings[i];
+ var warning = $("#warnings").append('<li></li>');
+ $("#warnings li").last().text('Line ' + w.line + ' column ' + w.column + ': ' + w.message);
+ }
+ */
+ render();
+ }, 0); // ms delay
+ };
+ $("#clear-text-box").click(function(e) {
+ $("#text").val('');
+ window.location.search = "";
+ parseAndRender();
+ });
+ $("#permalink").click(function(e) {
+ window.location.pathname = "/index.html";
+ window.location.search = "text=" + encodeURIComponent($("#text").val());
+ });
+ $("#text").bind('keyup paste cut mouseup', parseAndRender);
+ $(".option").change(render);
+});
+ </script>
+ <style type="text/css">
+ h1.title { font-family: monospace; font-size: 120%; font-weight: bold;
+ margin-top: 0.5em; margin-bottom: 0; }
+ textarea#text { height: 400px; width: 95%; font-family: monospace; font-size: 92%; }
+ pre code#html { font-size: 92%; font-family: monospace; }
+ pre#htmlpre { height: 400px; width: 95%; overflow: scroll; }
+ div#preview { height: 400px; overflow: scroll; }
+ div.row { margin-top: 1em; }
+ blockquote { font-size: 100%; }
+ footer { color: #555; text-align: center; margin: 1em; }
+ pre { display: block; padding: 0.5em; color: #333; background: #f8f8ff }
+ #warnings li { color: red; font-weight: bold; }
+ label { padding-left: 1em; padding-top: 0; padding-bottom: 0; }
+ div.timing { color: red; visibility: hidden; height: 2em; }
+ p#text-controls { height: 1em; }
+ a#permalink { margin-left: 1em; }
+ span.timing { font-weight: bold; }
+ span.timing { font-weight: bold; }
+ </style>
+</head>
+<body>
+<div class="container">
+ <div class="row">
+ <h1 class="title">commonmark.js dingus</h1>
+ </div>
+ <div class="row">
+ <div class="col-md-6">
+ <div class="timing">Parsed in <span class="timing" id="parsetime"></span>
+ ms. Rendered in <span class="timing" id="rendertime"></span> ms.</div>
+ <p id="text-controls"><a id="clear-text-box">clear</a>&nbsp;<a
+ id="permalink">permalink</a></p>
+ <textarea id="text"></textarea>
+ <ul id="warnings"></ul>
+ </div>
+ <div class="col-md-6">
+ <ul class="nav nav-tabs" role="tablist">
+ <li class="active"><a href="#preview" role="tab" data-toggle="tab">Preview</a></li>
+ <li><a href="#result" role="tab" data-toggle="tab">HTML</a></li>
+ <li><a href="#result-ast" role="tab" data-toggle="tab">AST</a></li>
+ </ul>
+ <div class="tab-content">
+ <div id="preview" class="tab-pane active">
+ </div>
+ <div id="result" class="tab-pane">
+ <pre id="htmlpre"><code id="html"></code></pre>
+ </div>
+ <div id="result-ast" class="tab-pane">
+ <pre id="astpre"><code id="ast"></code></pre>
+ </div>
+ </div>
+ </div>
+</div>
+</body>
+</html>