index.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>parsing example</title>
  6. <script src="https://unpkg.com/js-yaml@3.10.0/dist/js-yaml.js"></script>
  7. <script src="js/yamlFront.js"></script>
  8. <script src="https://unpkg.com/marked@0.3.17/marked.min.js"></script>
  9. <script src="js/handlebars.js"></script>
  10. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  11. <script>
  12. var parsed;
  13. var now = new Date().toDateString();
  14. var temp;
  15. var data;
  16. var renderedHtml;
  17. var text = "---\n"
  18. + "title: Welcome to JS YAML Front Matter\n"
  19. + "author: Derek Worthen\n"
  20. + "date: " + now + "\n"
  21. + "contact: \n"
  22. + " email: email@domain.com\n"
  23. + " phone: 012.345.6789\n"
  24. + "Co-Authors: \n"
  25. + " - me\n"
  26. + " - myself\n"
  27. + " - and I\n"
  28. + "---\n"
  29. + ['#### JS & YAML Rendering in the Browser!',
  30. 'This example uses [js-yaml-front-matter](https://github.com/dworthen/js-yaml-front-matter), ',
  31. '[marked](https://github.com/markedjs/marked) and [handlebars.js](http://handlebarsjs.com/) to render the conent above.',
  32. 'Please see the [source code](https://github.com/dworthen/js-yaml-front-matter/blob/4.0.0/docs/index.html) to see how this example works.'].join('\n\n');
  33. $(function () {
  34. $('#input').val(text);
  35. function run() {
  36. data = yamlFront.loadFront($('#input').val());
  37. data.__content = marked(data.__content);
  38. temp = Handlebars.compile($('#temp').html());
  39. renderedHtml = temp(data);
  40. $('#output').html(renderedHtml);
  41. }
  42. $('#input').on('input', run);
  43. window.run = run;
  44. run();
  45. });
  46. </script>
  47. <link rel="stylesheet" href="css/base.css">
  48. <link rel="stylesheet" href="css/layout.css">
  49. <link rel="stylesheet" href="css/skeleton.css">
  50. <style>
  51. .container {
  52. margin-top: 25px;
  53. }
  54. textarea {
  55. width: 100%;
  56. height: 300px;
  57. }
  58. #parse {
  59. width: 100%;
  60. }
  61. body {
  62. background: #eee;
  63. }
  64. #inset {
  65. margin: -20px 0 10px 0;
  66. padding: 0 0 0 15px;
  67. }
  68. span {
  69. font-size: 12px;
  70. font-weight: normal;
  71. font-style: italic;
  72. }
  73. </style>
  74. </head>
  75. <body>
  76. <div class="container">
  77. <div class="row">
  78. <div class="sixteen columns">
  79. <textarea id="input"></textarea>
  80. </div>
  81. </div>
  82. <div class="row">
  83. <div id="output" class="sixteen columns">
  84. </div>
  85. </div>
  86. <div class="row">
  87. <p>
  88. An example demonstrating
  89. <a href="https://github.com/dworthen/js-yaml-front-matter" target="_blank">js yaml front matter</a>.
  90. </p>
  91. </div>
  92. </div>
  93. <script id="temp" type="text/x-handlebars-template">
  94. <h2>{{#if title}}{{title}}{{else}}No Title{{/if}}
  95. <span>{{#if author}}{{author}},{{else}}No Author,{{/if}}
  96. {{#if Co-Authors}}
  97. {{#each Co-Authors}}
  98. {{this}},
  99. {{/each}}
  100. {{else}}
  101. No Co-Authors
  102. {{/if}}
  103. -
  104. {{#if contact}}
  105. {{#if contact.email}}{{contact.email}},{{else}}No Email,{{/if}}
  106. {{#if contact.phone}}{{contact.phone}}{{else}}No Phone{{/if}}
  107. {{else}}
  108. No Contact Information
  109. {{/if}}
  110. </span></h2>
  111. <div id="inset">
  112. <span>Date: {{#if date}}{{date}}{{else}}No Date{{/if}}</span>
  113. </div>
  114. <div id="content">
  115. {{#if __content}}
  116. {{{__content}}}
  117. {{else}}
  118. No Content
  119. {{/if}}
  120. </div>
  121. </script>
  122. </body>
  123. </html>