From 571fb67864c41e52352a5d3246be1b5f4cb2d3ae Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Sat, 24 Aug 2013 16:13:24 -0400
Subject: fix bug where markdown notes in last slide would not parse #574
---
plugin/markdown/markdown.js | 41 +++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)
(limited to 'plugin/markdown/markdown.js')
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js
index 31d22f1..dabc0d4 100755
--- a/plugin/markdown/markdown.js
+++ b/plugin/markdown/markdown.js
@@ -75,12 +75,12 @@
/**
* Helper function for constructing a markdown slide.
*/
- function createMarkdownSlide( data ) {
+ function createMarkdownSlide( content, options ) {
- var content = data.content || data;
+ var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) );
- if( data.notes ) {
- content += '';
+ if( notesMatch.length === 2 ) {
+ content = notesMatch[0] + '';
}
return '';
@@ -99,17 +99,13 @@
options.attributes = options.attributes || '';
var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
- horizontalSeparatorRegex = new RegExp( options.separator ),
- notesSeparatorRegex = new RegExp( options.notesSeparator, 'mgi' );
+ horizontalSeparatorRegex = new RegExp( options.separator );
var matches,
- noteMatch,
lastIndex = 0,
isHorizontal,
wasHorizontal = true,
content,
- notes,
- slide,
sectionStack = [];
// iterate until all blocks between separators are stacked up
@@ -126,25 +122,14 @@
// pluck slide content from markdown input
content = markdown.substring( lastIndex, matches.index );
- noteMatch = content.split( notesSeparatorRegex );
-
- if( noteMatch.length === 2 ) {
- content = noteMatch[0];
- notes = noteMatch[1].trim();
- }
-
- slide = {
- content: content,
- notes: notes || ''
- };
if( isHorizontal && wasHorizontal ) {
// add to horizontal stack
- sectionStack.push( slide );
+ sectionStack.push( content );
}
else {
// add to vertical stack
- sectionStack[sectionStack.length-1].push( slide );
+ sectionStack[sectionStack.length-1].push( content );
}
lastIndex = separatorRegex.lastIndex;
@@ -160,12 +145,16 @@
for( var i = 0, len = sectionStack.length; i < len; i++ ) {
// vertical
if( sectionStack[i].propertyIsEnumerable( length ) && typeof sectionStack[i].splice === 'function' ) {
- markdownSections += '' +
- '' + sectionStack[i].map( createMarkdownSlide ).join( '' +
- '';
+ markdownSections += '';
+
+ sectionStack[i].forEach( function( child ) {
+ markdownSections += '' + createMarkdownSlide( child, options ) + '';
+ } );
+
+ markdownSections += '';
}
else {
- markdownSections += '' + createMarkdownSlide( sectionStack[i] ) + '';
+ markdownSections += '' + createMarkdownSlide( sectionStack[i], options ) + '';
}
}
--
cgit v1.2.3
From d9c94749380e941305f8b465bb40cd5713034f94 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Tue, 27 Aug 2013 09:11:33 -0400
Subject: markdown refactoring #507
---
plugin/markdown/markdown.js | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
(limited to 'plugin/markdown/markdown.js')
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
+ };
-})();
+}));
--
cgit v1.2.3
From ef9168c7c481805f57feb78853dfdd3dd1409705 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Fri, 6 Sep 2013 08:24:03 -0400
Subject: fix issue with notes on last slide of external markdown #589
---
plugin/markdown/markdown.js | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
(limited to 'plugin/markdown/markdown.js')
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js
index c5c2358..739cc91 100755
--- a/plugin/markdown/markdown.js
+++ b/plugin/markdown/markdown.js
@@ -27,6 +27,10 @@
});
}
+ var DEFAULT_SLIDE_SEPARATOR = '^\n---\n$',
+ DEFAULT_NOTES_SEPARATOR = 'note:';
+
+
/**
* Retrieves the markdown contents of a slide section
* element. Normalizes leading tabs/whitespace.
@@ -82,11 +86,28 @@
}
+ /**
+ * Inspects the given options and fills out default
+ * values for what's not defined.
+ */
+ function getSlidifyOptions( options ) {
+
+ options = options || {};
+ options.separator = options.separator || DEFAULT_SLIDE_SEPARATOR;
+ options.notesSeparator = options.notesSeparator || DEFAULT_NOTES_SEPARATOR;
+ options.attributes = options.attributes || '';
+
+ return options;
+
+ }
+
/**
* Helper function for constructing a markdown slide.
*/
function createMarkdownSlide( content, options ) {
+ options = getSlidifyOptions( options );
+
var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) );
if( notesMatch.length === 2 ) {
@@ -103,10 +124,7 @@
*/
function slidify( markdown, options ) {
- options = options || {};
- options.separator = options.separator || '^\n---\n$';
- options.notesSeparator = options.notesSeparator || 'note:';
- options.attributes = options.attributes || '';
+ options = getSlidifyOptions( options );
var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
horizontalSeparatorRegex = new RegExp( options.separator );
@@ -232,7 +250,7 @@
}
}
- else if( section.getAttribute( 'data-separator' ) ) {
+ else if( section.getAttribute( 'data-separator' ) || section.getAttribute( 'data-vertical' ) || section.getAttribute( 'data-notes' ) ) {
section.outerHTML = slidify( getMarkdownFromSlide( section ), {
separator: section.getAttribute( 'data-separator' ),
@@ -242,6 +260,11 @@
});
}
+ else {
+
+ section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) );
+
+ }
}
}
--
cgit v1.2.3
From c453bc4770bfa0a84881822b27c79d046e718ffb Mon Sep 17 00:00:00 2001
From: Hakim El Hattab
Date: Fri, 6 Sep 2013 08:40:43 -0400
Subject: markdown plugin can now process slides that are added at runtime
---
plugin/markdown/markdown.js | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
(limited to 'plugin/markdown/markdown.js')
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js
index 739cc91..42c847f 100755
--- a/plugin/markdown/markdown.js
+++ b/plugin/markdown/markdown.js
@@ -9,9 +9,8 @@
}
else {
// Browser globals (root is window)
- root.returnExports = factory( root.marked );
- root.returnExports.processSlides();
- root.returnExports.convertSlides();
+ root.RevealMarkdown = factory( root.marked );
+ root.RevealMarkdown.initialize();
}
}( this, function( marked ) {
@@ -281,25 +280,41 @@
var section = sections[i];
- var notes = section.querySelector( 'aside.notes' );
- var markdown = getMarkdownFromSlide( section );
+ // Only parse the same slide once
+ if( !section.getAttribute( 'data-markdown-parsed' ) ) {
- section.innerHTML = marked( markdown );
+ section.setAttribute( 'data-markdown-parsed', true )
+
+ var notes = section.querySelector( 'aside.notes' );
+ var markdown = getMarkdownFromSlide( section );
+
+ section.innerHTML = marked( markdown );
+
+ // If there were notes, we need to re-add them after
+ // having overwritten the section's HTML
+ if( notes ) {
+ section.appendChild( notes );
+ }
- // If there were notes, we need to re-add them after
- // having overwritten the section's HTML
- if( notes ) {
- section.appendChild( notes );
}
}
}
+ // API
return {
+
+ initialize: function() {
+ processSlides();
+ convertSlides();
+ },
+
+ // TODO: Do these belong in the API?
processSlides: processSlides,
convertSlides: convertSlides,
slidify: slidify
+
};
}));
--
cgit v1.2.3