From 625831b9930c50114ab96dd635813a36655e7614 Mon Sep 17 00:00:00 2001 From: Liu Zhanhong Date: Mon, 19 Oct 2015 19:50:43 +0800 Subject: format note content when creating slide In html content, marked allow `Inline-Level Grammar` but not `Block-Level Grammar`, so when I write following: ``` note: * a * b * c ``` it become: ```html

a b

``` unbelievable!--- plugin/markdown/markdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/markdown/markdown.js') diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index f4035e2..031160c 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -117,7 +117,7 @@ var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) ); if( notesMatch.length === 2 ) { - content = notesMatch[0] + ''; + content = notesMatch[0] + ''; } // prevent script end tags in the content from interfering -- cgit v1.2.3 From 43f0d081550e5a4a3bc86e478ecc145990ad9a40 Mon Sep 17 00:00:00 2001 From: teawithfruit Date: Mon, 2 Nov 2015 10:37:16 +0100 Subject: fixed loading --- plugin/markdown/markdown.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'plugin/markdown/markdown.js') diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index f4035e2..f40e2b6 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -4,7 +4,11 @@ * of external markdown documents. */ (function( root, factory ) { - if( typeof exports === 'object' ) { + if (typeof define === 'function' && define.amd) { + root.marked = require( './marked' ); + root.RevealMarkdown = factory( root.marked ); + root.RevealMarkdown.initialize(); + } else if( typeof exports === 'object' ) { module.exports = factory( require( './marked' ) ); } else { -- cgit v1.2.3 From 16ebf2a783724527faac2036bc2f971df8dea0a5 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Wed, 11 Nov 2015 07:37:08 +0000 Subject: * [bug] the markdown plugin can not render highlight codes for marked.setOptions(highlight) --- plugin/markdown/markdown.js | 4 ++-- test/simple.md | 10 ++++++++++ test/test-markdown-external.html | 36 ++++++++++++++++++++++++++++++++++++ test/test-markdown-external.js | 19 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 test/simple.md create mode 100644 test/test-markdown-external.html create mode 100644 test/test-markdown-external.js (limited to 'plugin/markdown/markdown.js') diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index f4035e2..5544599 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -20,8 +20,8 @@ if( typeof hljs !== 'undefined' ) { marked.setOptions({ - highlight: function( lang, code ) { - return hljs.highlightAuto( lang, code ).value; + highlight: function( code, lang ) { + return hljs.highlightAuto( code, [lang] ).value; } }); } diff --git a/test/simple.md b/test/simple.md new file mode 100644 index 0000000..cd57d70 --- /dev/null +++ b/test/simple.md @@ -0,0 +1,10 @@ +## Slide 1.1 + +```js +var a = 1; +``` + +## Slide 1.2 + + +## Slide 2 diff --git a/test/test-markdown-external.html b/test/test-markdown-external.html new file mode 100644 index 0000000..859d0a1 --- /dev/null +++ b/test/test-markdown-external.html @@ -0,0 +1,36 @@ + + + + + + + reveal.js - Test Markdown + + + + + + + +
+
+ + + + + + + + + + + + + + diff --git a/test/test-markdown-external.js b/test/test-markdown-external.js new file mode 100644 index 0000000..a9ea034 --- /dev/null +++ b/test/test-markdown-external.js @@ -0,0 +1,19 @@ + + +Reveal.addEventListener( 'ready', function() { + + QUnit.module( 'Markdown' ); + + test( 'Vertical separator', function() { + strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' ); + }); + test( 'language highlighter', function() { + strictEqual( document.querySelectorAll( '.hljs-keyword' ).length, 1, 'got rendered highlight tag.' ); + strictEqual( document.querySelector( '.hljs-keyword' ).innerHTML, 'var', 'the same keyword: var.' ); + }); + + +} ); + +Reveal.initialize(); + -- cgit v1.2.3 From c0ea2cd98010d16ea90123e26578e19656d6c2dc Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Fri, 8 Jan 2016 14:02:16 +0100 Subject: same code format --- plugin/markdown/markdown.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'plugin/markdown/markdown.js') diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index f40e2b6..ab8f2e9 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -10,8 +10,7 @@ root.RevealMarkdown.initialize(); } else if( typeof exports === 'object' ) { module.exports = factory( require( './marked' ) ); - } - else { + } else { // Browser globals (root is window) root.RevealMarkdown = factory( root.marked ); root.RevealMarkdown.initialize(); -- cgit v1.2.3 From 90b301d0a03b8b23ce755c31ec6dac15cf69dc49 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Thu, 8 Dec 2016 17:41:55 +0800 Subject: Enable passing options for parsing Markdown. Closes #1163, #1495. --- README.md | 12 ++++++++++++ plugin/markdown/markdown.js | 32 +++++++++++++++++++------------- test/test-markdown-options.html | 41 +++++++++++++++++++++++++++++++++++++++++ test/test-markdown-options.js | 26 ++++++++++++++++++++++++++ test/test-markdown.html | 2 +- 5 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 test/test-markdown-options.html create mode 100644 test/test-markdown-options.js (limited to 'plugin/markdown/markdown.js') diff --git a/README.md b/README.md index b0257cc..1c55623 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,18 @@ Special syntax (in html comment) is available for adding attributes to the slide ``` +#### Configuring `marked` + +We use [marked](https://github.com/chjj/marked) to parse Markdown. To customise marked's rendering, you can pass in options when [configuring Reveal](#configuration): + +```javascript +Reveal.initialize({ + // Options which are passed into marked + // See https://github.com/chjj/marked#options-1 + markdown: { + smartypants: true + } +}); ### Configuration diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 124aa75..29aabf5 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -17,18 +17,6 @@ } }( this, function( marked ) { - if( typeof marked === 'undefined' ) { - throw 'The reveal.js Markdown plugin requires marked to be loaded'; - } - - if( typeof hljs !== 'undefined' ) { - marked.setOptions({ - highlight: function( code, lang ) { - return hljs.highlightAuto( code, [lang] ).value; - } - }); - } - var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$', DEFAULT_NOTES_SEPARATOR = 'note:', DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$', @@ -189,7 +177,7 @@ markdownSections += '
'; sectionStack[i].forEach( function( child ) { - markdownSections += '
' + createMarkdownSlide( child, options ) + '
'; + markdownSections += '
' + createMarkdownSlide( child, options ) + '
'; } ); markdownSections += '
'; @@ -391,6 +379,24 @@ return { initialize: function() { + if( typeof marked === 'undefined' ) { + throw 'The reveal.js Markdown plugin requires marked to be loaded'; + } + + if( typeof hljs !== 'undefined' ) { + marked.setOptions({ + highlight: function( code, lang ) { + return hljs.highlightAuto( code, [lang] ).value; + } + }); + } + + var options = Reveal.getConfig().markdown; + + if ( options ) { + marked.setOptions( options ); + } + processSlides(); convertSlides(); }, diff --git a/test/test-markdown-options.html b/test/test-markdown-options.html new file mode 100644 index 0000000..5b3be97 --- /dev/null +++ b/test/test-markdown-options.html @@ -0,0 +1,41 @@ + + + + + + + reveal.js - Test Markdown Options + + + + + + + +
+
+ + + + + + + + + + + diff --git a/test/test-markdown-options.js b/test/test-markdown-options.js new file mode 100644 index 0000000..3ae1350 --- /dev/null +++ b/test/test-markdown-options.js @@ -0,0 +1,26 @@ +Reveal.addEventListener( 'ready', function() { + + QUnit.module( 'Markdown' ); + + test( 'Options are set', function() { + strictEqual( marked.defaults.smartypants, true ); + }); + + test( 'Smart quotes are activated', function() { + var text = document.querySelector( '.reveal .slides>section>p' ).textContent; + + strictEqual( /['"]/.test( text ), false ); + strictEqual( /[“”‘’]/.test( text ), true ); + }); + +} ); + +Reveal.initialize({ + dependencies: [ + { src: '../plugin/markdown/marked.js' }, + { src: '../plugin/markdown/markdown.js' }, + ], + markdown: { + smartypants: true + } +}); diff --git a/test/test-markdown.html b/test/test-markdown.html index 7ff0efe..52b39ff 100644 --- a/test/test-markdown.html +++ b/test/test-markdown.html @@ -13,7 +13,7 @@
-
+