test-markdown.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Markdown</title>
  6. <link rel="stylesheet" href="../dist/reveal.css">
  7. <link rel="stylesheet" href="qunit-2.5.0.css">
  8. <script src="qunit-2.5.0.js"></script>
  9. </head>
  10. <body style="overflow: auto;">
  11. <div id="qunit"></div>
  12. <div id="qunit-fixture"></div>
  13. <div class="reveal deck1" style="display: none;">
  14. <div class="slides">
  15. <section data-markdown data-separator="^\n---\n$" data-separator-vertical="^\n--\n$">
  16. <script type="text/template">
  17. ## Slide 1.1
  18. --
  19. ## Slide 1.2
  20. ---
  21. ## Slide 2
  22. </script>
  23. </section>
  24. </div>
  25. </div>
  26. <div class="reveal deck2" style="display: none;">
  27. <div class="slides">
  28. <section data-markdown="simple.md" data-separator="^\r?\n\r?\n\r?\n" data-separator-vertical="^\r?\n\r?\n"></section>
  29. </div>
  30. </div>
  31. <div class="reveal deck3" style="display: none;">
  32. <div class="slides">
  33. <section data-markdown data-separator="^\n\n\n"
  34. data-separator-vertical="^\n\n"
  35. data-separator-notes="^Note:"
  36. data-attributes="--\s(.*?)$"
  37. data-charset="utf-8">
  38. <script type="text/template">
  39. # Test attributes in Markdown
  40. ## Slide 1
  41. ## Slide 2
  42. <!-- -- id="slide2" data-transition="zoom" data-background="#A0C66B" -->
  43. ## Slide 2.1
  44. <!-- -- data-background="#ff0000" data-transition="fade" -->
  45. ## Slide 2.2
  46. [Link to Slide2](#/slide2)
  47. ## Slide 3
  48. <!-- -- data-transition="zoom" data-background="#C6916B" -->
  49. ## Slide 4
  50. </script>
  51. </section>
  52. <section data-markdown data-separator="^\n\n\n"
  53. data-separator-vertical="^\n\n"
  54. data-separator-notes="^Note:"
  55. data-charset="utf-8">
  56. <script type="text/template">
  57. # Test attributes in Markdown with default separator
  58. ## Slide 1 Def
  59. ## Slide 2 Def
  60. <!-- .slide: id="slide2def" data-transition="concave" data-background="#A7C66B" -->
  61. ## Slide 2.1 Def
  62. <!-- .slide: data-background="#f70000" data-transition="page" -->
  63. ## Slide 2.2 Def
  64. [Link to Slide2](#/slide2def)
  65. ## Slide 3 Def
  66. <!-- .slide: data-transition="concave" data-background="#C7916B" -->
  67. ## Slide 4
  68. </script>
  69. </section>
  70. <section data-markdown>
  71. <script type="text/template">
  72. <!-- .slide: data-background="#ff0000" -->
  73. ## Hello world
  74. </script>
  75. </section>
  76. <section data-markdown>
  77. <script type="text/template">
  78. ## Hello world
  79. <!-- .slide: data-background="#ff0000" -->
  80. </script>
  81. </section>
  82. <section data-markdown>
  83. <script type="text/template">
  84. ## Hello world
  85. Test
  86. <!-- .slide: data-background="#ff0000" -->
  87. More Test
  88. </script>
  89. </section>
  90. </div>
  91. </div>
  92. <div class="reveal deck4" style="display: none;">
  93. <div class="slides">
  94. <section data-markdown>
  95. <script type="text/template">
  96. ## Testing Markdown Options
  97. This "slide" should contain 'smart' quotes.
  98. </script>
  99. </section>
  100. </div>
  101. </div>
  102. <div class="reveal deck5" style="display: none;">
  103. <div class="slides">
  104. <section data-markdown data-separator="^\n---\n$" data-separator-vertical="^\n--\n$" data-element-attributes="{_\s*?([^}]+?)}">>
  105. <script type="text/template">
  106. ## Slide 1.1
  107. <!-- {_class="fragment fade-out" data-fragment-index="1"} -->
  108. --
  109. ## Slide 1.2
  110. <!-- {_class="fragment shrink"} -->
  111. Paragraph 1
  112. <!-- {_class="fragment grow"} -->
  113. Paragraph 2
  114. <!-- {_class="fragment grow"} -->
  115. - list item 1 <!-- {_class="fragment grow"} -->
  116. - list item 2 <!-- {_class="fragment grow"} -->
  117. - list item 3 <!-- {_class="fragment grow"} -->
  118. ---
  119. ## Slide 2
  120. Paragraph 1.2
  121. multi-line <!-- {_class="fragment highlight-red"} -->
  122. Paragraph 2.2 <!-- {_class="fragment highlight-red"} -->
  123. Paragraph 2.3 <!-- {_class="fragment highlight-red"} -->
  124. Paragraph 2.4 <!-- {_class="fragment highlight-red"} -->
  125. - list item 1 <!-- {_class="fragment highlight-green"} -->
  126. - list item 2<!-- {_class="fragment highlight-green"} -->
  127. - list item 3<!-- {_class="fragment highlight-green"} -->
  128. - list item 4
  129. <!-- {_class="fragment highlight-green"} -->
  130. - list item 5<!-- {_class="fragment highlight-green"} -->
  131. Test
  132. ![Example Picture](examples/assets/image2.png) <!-- {_class="reveal stretch"} -->
  133. </script>
  134. </section>
  135. <section data-markdown data-separator="^\n\n\n"
  136. data-separator-vertical="^\n\n"
  137. data-separator-notes="^Note:"
  138. data-charset="utf-8">
  139. <script type="text/template">
  140. # Test attributes in Markdown with default separator
  141. ## Slide 1 Def <!-- .element: class="fragment highlight-red" data-fragment-index="1" -->
  142. ## Slide 2 Def
  143. <!-- .element: class="fragment highlight-red" -->
  144. </script>
  145. </section>
  146. <section data-markdown>
  147. <script type="text/template">
  148. ## Hello world
  149. A paragraph
  150. <!-- .element: class="fragment highlight-blue" -->
  151. </script>
  152. </section>
  153. <section data-markdown>
  154. <script type="text/template">
  155. ## Hello world
  156. Multiple
  157. Line
  158. <!-- .element: class="fragment highlight-blue" -->
  159. </script>
  160. </section>
  161. <section data-markdown>
  162. <script type="text/template">
  163. ## Hello world
  164. Test<!-- .element: class="fragment highlight-blue" -->
  165. More Test
  166. </script>
  167. </section>
  168. </div>
  169. </div>
  170. <script type="module">
  171. import Reveal from '../js/reveal.js'
  172. import markdown from '../plugin/markdown/markdown.js'
  173. let deck1 = new Reveal( document.querySelector( '.deck1' ), { plugins: [ markdown() ] })
  174. deck1.addEventListener( 'ready', function() {
  175. QUnit.module( 'Inline' );
  176. QUnit.test( 'Vertical separator', function( assert ) {
  177. assert.strictEqual( deck1.getRevealElement().querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' );
  178. });
  179. QUnit.test( 'Horizontal separator', function( assert ) {
  180. assert.strictEqual( deck1.getRevealElement().querySelectorAll( '.reveal .slides>section' ).length, 2, 'found two slides' );
  181. });
  182. } );
  183. let deck2 = new Reveal( document.querySelector( '.deck2' ), { plugins: [ markdown() ] })
  184. deck2.addEventListener( 'ready', function() {
  185. QUnit.module( 'External' );
  186. QUnit.test( 'Vertical separator', function( assert ) {
  187. assert.strictEqual( deck2.getRevealElement().querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' );
  188. });
  189. QUnit.test( 'Horizontal separator', function( assert ) {
  190. assert.strictEqual( deck2.getRevealElement().querySelectorAll( '.reveal .slides>section' ).length, 2, 'found two slides' );
  191. });
  192. } );
  193. let deck3 = new Reveal( document.querySelector( '.deck3' ), { plugins: [ markdown() ] })
  194. deck3.addEventListener( 'ready', function() {
  195. QUnit.module( 'Slide Attributes' );
  196. QUnit.test( 'Id on slide', function( assert ) {
  197. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section#slide2' ).length, 1, 'found one slide with id slide2' );
  198. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section a[href="#/slide2"]' ).length, 1, 'found one slide with a link to slide2' );
  199. });
  200. QUnit.test( 'data-background attributes', function( assert ) {
  201. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-background="#A0C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' );
  202. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-background="#ff0000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' );
  203. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section[data-background="#C6916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' );
  204. });
  205. QUnit.test( 'data-transition attributes', function( assert ) {
  206. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-transition="zoom"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' );
  207. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-transition="fade"]' ).length, 1, 'found one vertical slide with data-transition="fade"' );
  208. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides section [data-transition="zoom"]' ).length, 1, 'found one slide with data-transition="zoom"' );
  209. });
  210. QUnit.test( 'data-background attributes with default separator', function( assert ) {
  211. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-background="#A7C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' );
  212. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-background="#f70000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' );
  213. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section[data-background="#C7916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' );
  214. });
  215. QUnit.test( 'data-transition attributes with default separator', function( assert ) {
  216. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-transition="concave"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' );
  217. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section>section[data-transition="page"]' ).length, 1, 'found one vertical slide with data-transition="fade"' );
  218. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides section [data-transition="concave"]' ).length, 1, 'found one slide with data-transition="zoom"' );
  219. });
  220. QUnit.test( 'data-transition attributes with inline content', function( assert ) {
  221. assert.strictEqual( deck3.getRevealElement().querySelectorAll( '.reveal .slides>section[data-background="#ff0000"]' ).length, 3, 'found three horizontal slides with data-background="#ff0000"' );
  222. });
  223. } );
  224. let deck4 = new Reveal( document.querySelector( '.deck4' ), {
  225. markdown: {
  226. smartypants: true
  227. },
  228. plugins: [ markdown() ]
  229. })
  230. deck4.addEventListener( 'ready', function() {
  231. QUnit.module( 'Options' );
  232. QUnit.test( 'Options are set', function( assert ) {
  233. assert.strictEqual( deck4.getPlugin( 'markdown' ).marked.defaults.smartypants, true );
  234. });
  235. QUnit.test( 'Smart quotes are activated', function( assert ) {
  236. var text = deck4.getRevealElement().querySelector( '.reveal .slides>section>p' ).textContent;
  237. assert.strictEqual( /['"]/.test( text ), false );
  238. assert.strictEqual( /[“”‘’]/.test( text ), true );
  239. });
  240. } );
  241. let deck5 = new Reveal( document.querySelector( '.deck5' ), { plugins: [ markdown() ] })
  242. deck5.addEventListener( 'ready', function() {
  243. QUnit.module( 'Element Attributes' );
  244. QUnit.test( 'Vertical separator', function( assert ) {
  245. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides>section>section' ).length, 4, 'found four slides' );
  246. });
  247. QUnit.test( 'Attributes on element header in vertical slides', function( assert ) {
  248. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section>section h2.fragment.fade-out' ).length, 1, 'found one vertical slide with class fragment.fade-out on header' );
  249. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section>section h2.fragment.shrink' ).length, 1, 'found one vertical slide with class fragment.shrink on header' );
  250. });
  251. QUnit.test( 'Attributes on element paragraphs in vertical slides', function( assert ) {
  252. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section>section p.fragment.grow' ).length, 2, 'found a vertical slide with two paragraphs with class fragment.grow' );
  253. });
  254. QUnit.test( 'Attributes on element list items in vertical slides', function( assert ) {
  255. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section>section li.fragment.grow' ).length, 3, 'found a vertical slide with three list items with class fragment.grow' );
  256. });
  257. QUnit.test( 'Attributes on element paragraphs in horizontal slides', function( assert ) {
  258. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section p.fragment.highlight-red' ).length, 4, 'found a horizontal slide with four paragraphs with class fragment.grow' );
  259. });
  260. QUnit.test( 'Attributes on element list items in horizontal slides', function( assert ) {
  261. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section li.fragment.highlight-green' ).length, 5, 'found a horizontal slide with five list items with class fragment.roll-in' );
  262. });
  263. QUnit.test( 'Attributes on element image in horizontal slides', function( assert ) {
  264. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section img.reveal.stretch' ).length, 1, 'found a horizontal slide with stretched image, class img.reveal.stretch' );
  265. });
  266. QUnit.test( 'Attributes on elements in vertical slides with default element attribute separator', function( assert ) {
  267. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section h2.fragment.highlight-red' ).length, 2, 'found two h2 titles with fragment highlight-red in vertical slides with default element attribute separator' );
  268. });
  269. QUnit.test( 'Attributes on elements in single slides with default element attribute separator', function( assert ) {
  270. assert.strictEqual( deck5.getRevealElement().querySelectorAll( '.reveal .slides section p.fragment.highlight-blue' ).length, 3, 'found three elements with fragment highlight-blue in single slide with default element attribute separator' );
  271. });
  272. } );
  273. deck1.initialize();
  274. deck2.initialize();
  275. deck3.initialize();
  276. deck4.initialize();
  277. deck5.initialize();
  278. </script>
  279. </body>
  280. </html>