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