|
|
@@ -83,12 +83,93 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
return '<script type="text/template">' + content + '</script>';
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Parses a data string into multiple slides based
|
|
|
+ * on the passed in separator arguments.
|
|
|
+ */
|
|
|
+ function slidify(markdown, options) {
|
|
|
+ options = getSlidifyOptions(options);
|
|
|
+
|
|
|
+ let separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
|
|
|
+ horizontalSeparatorRegex = new RegExp( options.separator );
|
|
|
+
|
|
|
+ let matches,
|
|
|
+ lastIndex = 0,
|
|
|
+ isHorizontal,
|
|
|
+ wasHorizontal = true,
|
|
|
+ content,
|
|
|
+ sectionStack = [];
|
|
|
+
|
|
|
+ // iterate until all blocks between separators are stacked up
|
|
|
+ while ((matches = separatorRegex.exec(markdown)) != null) {
|
|
|
+ // notes = null;
|
|
|
+
|
|
|
+ // determine direction (horizontal by default)
|
|
|
+ isHorizontal = horizontalSeparatorRegex.test( matches[0] );
|
|
|
+
|
|
|
+ if (!isHorizontal && wasHorizontal) {
|
|
|
+ // create vertical stack
|
|
|
+ sectionStack.push([]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // pluck slide content from markdown input
|
|
|
+ content = markdown.substring(lastIndex, matches.index);
|
|
|
+
|
|
|
+ if (isHorizontal && wasHorizontal) {
|
|
|
+ // add to horizontal stack
|
|
|
+ sectionStack.push(content);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // add to vertical stack
|
|
|
+ sectionStack[sectionStack.length-1].push( content );
|
|
|
+ }
|
|
|
+
|
|
|
+ lastIndex = separatorRegex.lastIndex;
|
|
|
+ wasHorizontal = isHorizontal;
|
|
|
+ }
|
|
|
+
|
|
|
+ // add the remaining slide
|
|
|
+ (wasHorizontal ? sectionStack : sectionStack[sectionStack.length-1]).push(markdown.substring(lastIndex));
|
|
|
+
|
|
|
+ let markdownSections = '';
|
|
|
+
|
|
|
+ // flatten the hierarchical stack, and insert <section data-markdown> tags
|
|
|
+ for (let i = 0, len = sectionStack.length; i < len; i++ ) {
|
|
|
+ // vertical
|
|
|
+ if (sectionStack[i] instanceof Array) {
|
|
|
+ markdownSections += '<section '+ options.attributes +'>';
|
|
|
+
|
|
|
+ sectionStack[i].forEach(function(child) {
|
|
|
+ markdownSections += '<section data-markdown>' + createMarkdownSlide(child, options) + '</section>';
|
|
|
+ } );
|
|
|
+
|
|
|
+ markdownSections += '</section>';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ markdownSections += '<section '+ options.attributes +' data-markdown>' + createMarkdownSlide(sectionStack[i], options) + '</section>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return markdownSections;
|
|
|
+ }
|
|
|
+
|
|
|
function processSlides() {
|
|
|
let sections = document.querySelectorAll('[data-markdown]');
|
|
|
let section;
|
|
|
for (let i = 0, len = sections.length; i < len; i++) {
|
|
|
section = sections[i];
|
|
|
- section.innerHTML = createMarkdownSlide(getMarkdownFromSlide(section));
|
|
|
+ if (section.getAttribute('data-separator')
|
|
|
+ || section.getAttribute('data-separator-vertical')
|
|
|
+ || section.getAttribute('data-separator-notes')) {
|
|
|
+ section.outerHTML = slidify(getMarkdownFromSlide(section), {
|
|
|
+ separator: section.getAttribute('data-separator'),
|
|
|
+ verticalSeparator: section.getAttribute('data-separator-vertical'),
|
|
|
+ notesSeparator: section.getAttribute('data-separator-notes')
|
|
|
+ // attributes: getForwardedAttributes(section)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ section.innerHTML = createMarkdownSlide(getMarkdownFromSlide(section));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|