aboutsummaryrefslogtreecommitdiff
path: root/js/index.html
blob: 01afef296b891e2da33a9cec9fa6e66467a80d1c (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="commonmark.js"></script>
  10. <script type="text/javascript">
  11. var writer = new commonmark.HtmlRenderer();
  12. var reader = new commonmark.DocParser();
  13. $(document).ready(function() {
  14. $(".timing").hide();
  15. var timer;
  16. var x;
  17. var parsed;
  18. var render = function() {
  19. if (parsed === undefined) {
  20. return;
  21. }
  22. var startTime = new Date().getTime();
  23. var result = writer.renderBlock(parsed);
  24. var endTime = new Date().getTime();
  25. var renderTime = endTime - startTime;
  26. // $("#html").text(result);
  27. $("#preview").html(result);
  28. $("#html").text(result);
  29. $("#ast").text(commonmark.ASTRenderer(parsed));
  30. $("#rendertime").text(renderTime);
  31. };
  32. var parseAndRender = function () {
  33. if (x) { x.abort() } // If there is an existing XHR, abort it.
  34. clearTimeout(timer); // Clear the timer so we don't end up with dupes.
  35. timer = setTimeout(function() { // assign timer a new timeout
  36. var startTime = new Date().getTime();
  37. parsed = reader.parse($("#text").val());
  38. var endTime = new Date().getTime();
  39. var parseTime = endTime - startTime;
  40. $("#parsetime").text(parseTime);
  41. $(".timing").show();
  42. /*
  43. var warnings = parsed.warnings;
  44. $("#warnings").html('');
  45. for (i=0; i < warnings.length; i++) {
  46. var w = warnings[i];
  47. var warning = $("#warnings").append('<li></li>');
  48. $("#warnings li").last().text('Line ' + w.line + ' column ' + w.column + ': ' + w.message);
  49. }
  50. */
  51. render();
  52. }, 0); // ms delay
  53. };
  54. $("#text").bind('keyup paste cut mouseup', parseAndRender);
  55. $(".option").change(render);
  56. });
  57. </script>
  58. <style type="text/css">
  59. textarea#text { height: 400px; width: 95%; font-family: monospace; font-size: 92%; }
  60. pre code#html { font-size: 92%; font-family: monospace; }
  61. pre#htmlpre { height: 400px; width: 95%; overflow: scroll; }
  62. div#preview { height: 400px; overflow: scroll; }
  63. div.row { margin-top: 1em; }
  64. blockquote { font-size: 100%; }
  65. footer { color: #555; text-align: center; margin: 1em; }
  66. pre { display: block; padding: 0.5em; color: #333; background: #f8f8ff }
  67. #warnings li { color: red; font-weight: bold; }
  68. label { padding-left: 1em; padding-top: 0; padding-bottom: 0; }
  69. p.timing { color: red; }
  70. span.timing { font-weight: bold; }
  71. span.timing { font-weight: bold; }
  72. </style>
  73. </head>
  74. <body>
  75. <div class="container">
  76. <div class="row">
  77. <div class="col-md-6">
  78. <h1>commonmark.js dingus</h1>
  79. </div>
  80. <div class="col-md-4">
  81. <ul class="nav nav-tabs" role="tablist">
  82. <li class="active"><a href="#preview" role="tab" data-toggle="tab">Preview</a></li>
  83. <li><a href="#result" role="tab" data-toggle="tab">HTML</a></li>
  84. <li><a href="#result-ast" role="tab" data-toggle="tab">AST</a></li>
  85. </ul>
  86. </div>
  87. <div class="col-md-2">
  88. <p class="timing">Parsed in <span class="timing" id="parsetime"></span> ms.<br>
  89. Rendered in <span class="timing" id="rendertime"></span> ms.</p>
  90. </div>
  91. </div>
  92. <div class="row">
  93. <div class="col-md-6">
  94. <textarea id="text"></textarea>
  95. <ul id="warnings"></ul>
  96. </div>
  97. <div class="col-md-6">
  98. <div class="tab-content">
  99. <div id="preview" class="tab-pane active">
  100. </div>
  101. <div id="result" class="tab-pane">
  102. <pre id="htmlpre"><code id="html"></code></pre>
  103. </div>
  104. <div id="result-ast" class="tab-pane">
  105. <pre id="astpre"><code id="ast"></code></pre>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. </body>
  112. </html>