aboutsummaryrefslogtreecommitdiff
path: root/dingus.html
blob: 8c35fe5d5be9a29b3ef17fdd4c31f4c56ab0863c (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('');
  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. $("#text").val(getQueryVariable("text"));
  64. parseAndRender();
  65. $("#clear-text-box").click(function(e) {
  66. $("#text").val('');
  67. window.location.search = "";
  68. parseAndRender();
  69. });
  70. $("#permalink").click(function(e) {
  71. window.location.pathname = "/index.html";
  72. window.location.search = "text=" + encodeURIComponent($("#text").val());
  73. });
  74. $("#text").bind('keyup paste cut mouseup', parseAndRender);
  75. $(".option").change(render);
  76. });
  77. </script>
  78. <style type="text/css">
  79. h1.title { font-family: monospace; font-size: 120%; font-weight: bold;
  80. margin-top: 0.5em; margin-bottom: 0; }
  81. textarea#text { height: 400px; width: 95%; font-family: monospace; font-size: 92%; }
  82. pre code#html { font-size: 92%; font-family: monospace; }
  83. pre#htmlpre { height: 400px; width: 95%; overflow: scroll; }
  84. div#preview { height: 400px; overflow: scroll; }
  85. div.row { margin-top: 1em; }
  86. blockquote { font-size: 100%; }
  87. footer { color: #555; text-align: center; margin: 1em; }
  88. pre { display: block; padding: 0.5em; color: #333; background: #f8f8ff }
  89. #warnings li { color: red; font-weight: bold; }
  90. label { padding-left: 1em; padding-top: 0; padding-bottom: 0; }
  91. div.timing { color: red; visibility: hidden; height: 2em; }
  92. p#text-controls { height: 1em; }
  93. a#permalink { margin-left: 1em; }
  94. span.timing { font-weight: bold; }
  95. span.timing { font-weight: bold; }
  96. </style>
  97. </head>
  98. <body>
  99. <div class="container">
  100. <div class="row">
  101. <h1 class="title">commonmark.js dingus</h1>
  102. </div>
  103. <div class="row">
  104. <div class="col-md-6">
  105. <div class="timing">Parsed in <span class="timing" id="parsetime"></span>
  106. ms. Rendered in <span class="timing" id="rendertime"></span> ms.</div>
  107. <p id="text-controls"><a id="clear-text-box">clear</a>&nbsp;<a
  108. id="permalink">permalink</a></p>
  109. <textarea id="text"></textarea>
  110. <ul id="warnings"></ul>
  111. </div>
  112. <div class="col-md-6">
  113. <ul class="nav nav-tabs" role="tablist">
  114. <li class="active"><a href="#preview" role="tab" data-toggle="tab">Preview</a></li>
  115. <li><a href="#result" role="tab" data-toggle="tab">HTML</a></li>
  116. <li><a href="#result-ast" role="tab" data-toggle="tab">AST</a></li>
  117. </ul>
  118. <div class="tab-content">
  119. <div id="preview" class="tab-pane active">
  120. </div>
  121. <div id="result" class="tab-pane">
  122. <pre id="htmlpre"><code id="html"></code></pre>
  123. </div>
  124. <div id="result-ast" class="tab-pane">
  125. <pre id="astpre"><code id="ast"></code></pre>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. </body>
  131. </html>