aboutsummaryrefslogtreecommitdiff
path: root/plugin/markdown
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2013-08-27 09:11:33 -0400
committerHakim El Hattab <hakim.elhattab@gmail.com>2013-08-27 09:11:43 -0400
commitd9c94749380e941305f8b465bb40cd5713034f94 (patch)
treea0229b909546249d3c0e2936d78074d6149e9034 /plugin/markdown
parente9b0f5b4818064f3295cf8cf2f3a0b6575302714 (diff)
downloadperl-software-in-gnu-guix-d9c94749380e941305f8b465bb40cd5713034f94.tar
perl-software-in-gnu-guix-d9c94749380e941305f8b465bb40cd5713034f94.tar.gz
markdown refactoring #507
Diffstat (limited to 'plugin/markdown')
-rwxr-xr-xplugin/markdown/markdown.js40
1 files changed, 31 insertions, 9 deletions
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js
index dabc0d4..c5c2358 100755
--- a/plugin/markdown/markdown.js
+++ b/plugin/markdown/markdown.js
@@ -3,7 +3,17 @@
* markdown inside of presentations as well as loading
* of external markdown documents.
*/
-(function(){
+(function( root, factory ) {
+ if( typeof exports === 'object' ) {
+ module.exports = factory( require( './marked' ) );
+ }
+ else {
+ // Browser globals (root is window)
+ root.returnExports = factory( root.marked );
+ root.returnExports.processSlides();
+ root.returnExports.convertSlides();
+ }
+}( this, function( marked ) {
if( typeof marked === 'undefined' ) {
throw 'The reveal.js Markdown plugin requires marked to be loaded';
@@ -91,7 +101,7 @@
* Parses a data string into multiple slides based
* on the passed in separator arguments.
*/
- function slidifyMarkdown( markdown, options ) {
+ function slidify( markdown, options ) {
options = options || {};
options.separator = options.separator || '^\n---\n$';
@@ -162,7 +172,12 @@
}
- function loadExternalMarkdown() {
+ /**
+ * Parses any current data-markdown slides, splits
+ * multi-slide markdown into separate sections and
+ * handles loading of external markdown.
+ */
+ function processSlides() {
var sections = document.querySelectorAll( '[data-markdown]'),
section;
@@ -187,7 +202,7 @@
if( xhr.readyState === 4 ) {
if ( xhr.status >= 200 && xhr.status < 300 ) {
- section.outerHTML = slidifyMarkdown( xhr.responseText, {
+ section.outerHTML = slidify( xhr.responseText, {
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-vertical' ),
notesSeparator: section.getAttribute( 'data-notes' ),
@@ -219,7 +234,7 @@
}
else if( section.getAttribute( 'data-separator' ) ) {
- section.outerHTML = slidifyMarkdown( getMarkdownFromSlide( section ), {
+ section.outerHTML = slidify( getMarkdownFromSlide( section ), {
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-vertical' ),
notesSeparator: section.getAttribute( 'data-notes' ),
@@ -231,7 +246,11 @@
}
- function convertMarkdownToHTML() {
+ /**
+ * Converts any current data-markdown slides in the
+ * DOM to HTML.
+ */
+ function convertSlides() {
var sections = document.querySelectorAll( '[data-markdown]');
@@ -254,7 +273,10 @@
}
- loadExternalMarkdown();
- convertMarkdownToHTML();
+ return {
+ processSlides: processSlides,
+ convertSlides: convertSlides,
+ slidify: slidify
+ };
-})();
+}));