aboutsummaryrefslogtreecommitdiff
path: root/dingus.html
blob: 7c3a7c7f9c4efb93f7fc8fd7d27d350737cd5904 (plain)
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>commonmark.js demo</title>
  6. <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  7. <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
  8. <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  9. <script src="js/commonmark.js"></script>
  10. <script type="text/javascript">
  11. var writer = new commonmark.HtmlRenderer();
  12. var reader = new commonmark.DocParser();
  13. function getQueryVariable(variable)
  14. {
  15. var query = window.location.search.substring(1);
  16. var vars = query.split("&");
  17. for (var i=0;i<vars.length;i++) {
  18. var pair = vars[i].split("=");
  19. if(pair[0] == variable){return decodeURIComponent(pair[1]);}
  20. }
  21. return null;
  22. }
  23. $(document).ready(function() {
  24. var timer;
  25. var x;
  26. var parsed;
  27. var render = function() {
  28. if (parsed === undefined) {
  29. return;
  30. }
  31. var startTime = new Date().getTime();
  32. var result = writer.renderBlock(parsed);
  33. var endTime = new Date().getTime();
  34. var renderTime = endTime - startTime;
  35. // $("#html").text(result);
  36. $("#preview").html(result);
  37. $("#html").text(result);
  38. $("#ast").text(commonmark.ASTRenderer(parsed));
  39. $("#rendertime").text(renderTime);
  40. };
  41. var parseAndRender = function () {
  42. if (x) { x.abort() } // If there is an existing XHR, abort it.
  43. clearTimeout(timer); // Clear the timer so we don't end up with dupes.
  44. timer = setTimeout(function() { // assign timer a new timeout
  45. var startTime = new Date().getTime();
  46. parsed = reader.parse($("#text").val());
  47. var endTime = new Date().getTime();
  48. var parseTime = endTime - startTime;
  49. $("#parsetime").text(parseTime);
  50. $(".timing").css('visibility','visible');
  51. /*
  52. var warnings = parsed.warnings;
  53. $("#warnings").html('');
  54. for (i=0; i < warnings.length; i++) {
  55. var w = warnings[i];
  56. var warning = $("#warnings").append('<li></li>');
  57. $("#warnings li").last().text('Line ' + w.line + ' column ' + w.column + ': ' + w.message);
  58. }
  59. */
  60. render();
  61. }, 0); // ms delay
  62. };
  63. var initial_text = getQueryVariable("text");
  64. if (initial_text) {
  65. $("#text").val(initial_text);
  66. // show HTML tab if text is from query
  67. $('#result-tabs a[href="#result"]').tab('show');
  68. }
  69. parseAndRender();
  70. $("#clear-text-box").click(function(e) {
  71. $("#text").val('');
  72. window.location.search = "";
  73. parseAndRender();
  74. });
  75. $("#permalink").click(function(e) {
  76. window.location.pathname = "/index.html";
  77. window.location.search = "text=" + encodeURIComponent($("#text").val());
  78. });
  79. $("#text").bind('keyup paste cut mouseup', parseAndRender);
  80. $(".option").change(render);
  81. });
  82. </script>
  83. <style type="text/css">
  84. h1.title { font-family: monospace; font-size: 120%; font-weight: bold;
  85. margin-top: 0.5em; margin-bottom: 0; }
  86. textarea#text { height: 400px; width: 95%; font-family: monospace; font-size: 92%; }
  87. pre code#html { font-size: 92%; font-family: monospace; }
  88. pre#htmlpre { height: 400px; width: 95%; overflow: scroll; }
  89. div#preview { height: 400px; overflow: scroll; }
  90. div.row { margin-top: 1em; }
  91. blockquote { font-size: 100%; }
  92. footer { color: #555; text-align: center; margin: 1em; }
  93. pre { display: block; padding: 0.5em; color: #333; background: #f8f8ff }
  94. #warnings li { color: red; font-weight: bold; }
  95. label { padding-left: 1em; padding-top: 0; padding-bottom: 0; }
  96. div.timing { color: red; visibility: hidden; height: 2em; }
  97. p#text-controls { height: 1em; }
  98. a#permalink { margin-left: 1em; }
  99. span.timing { font-weight: bold; }
  100. span.timing { font-weight: bold; }
  101. </style>
  102. </head>
  103. <body>
  104. <div class="container">
  105. <div class="row">
  106. <h1 class="title">commonmark.js dingus</h1>
  107. </div>
  108. <div class="row">
  109. <div class="col-md-6">
  110. <div class="timing">Parsed in <span class="timing" id="parsetime"></span>
  111. ms. Rendered in <span class="timing" id="rendertime"></span> ms.</div>
  112. <p id="text-controls"><a id="clear-text-box">clear</a>&nbsp;<a
  113. id="permalink">permalink</a></p>
  114. <textarea id="text"></textarea>
  115. <ul id="warnings"></ul>
  116. </div>
  117. <div class="col-md-6">
  118. <ul id="result-tabs" class="nav nav-tabs" role="tablist">
  119. <li class="active"><a href="#preview" role="tab" data-toggle="tab">Preview</a></li>
  120. <li><a href="#result" role="tab" data-toggle="tab">HTML</a></li>
  121. <li><a href="#result-ast" role="tab" data-toggle="tab">AST</a></li>
  122. </ul>
  123. <div class="tab-content">
  124. <div id="preview" class="tab-pane active">
  125. </div>
  126. <div id="result" class="tab-pane">
  127. <pre id="htmlpre"><code id="html"></code></pre>
  128. </div>
  129. <div id="result-ast" class="tab-pane">
  130. <pre id="astpre"><code id="ast"></code></pre>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </body>
  136. </html>