|
|
@@ -13,101 +13,8 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
let growiRendererPlugin = factory(growiRenderer);
|
|
|
growiRendererPlugin.initialize();
|
|
|
}(this, function(growiRenderer) {
|
|
|
- const SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
|
|
|
let marked;
|
|
|
|
|
|
- /**
|
|
|
- * Helper function for constructing a markdown slide.
|
|
|
- * Referred from The reveal.js markdown plugin.
|
|
|
- * https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
|
- */
|
|
|
- function createMarkdownSlide(content, options) {
|
|
|
- options = marked.getSlidifyOptions(options);
|
|
|
-
|
|
|
- let notesMatch = content.split(new RegExp(options.notesSeparator, 'mgi'));
|
|
|
-
|
|
|
- if (notesMatch.length === 2) {
|
|
|
- content = notesMatch[0] + '<aside class="notes">' + growiRenderer.process(notesMatch[1].trim()) + '</aside>';
|
|
|
- }
|
|
|
-
|
|
|
- // prevent script end tags in the content from interfering
|
|
|
- // with parsing
|
|
|
- content = content.replace(/<\/script>/g, SCRIPT_END_PLACEHOLDER);
|
|
|
-
|
|
|
- return '<script type="text/template">' + content + '</script>';
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Parses a data string into multiple slides based
|
|
|
- * on the passed in separator arguments.
|
|
|
- * Referred from The reveal.js markdown plugin.
|
|
|
- * https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
|
- */
|
|
|
- function slidify(markdown, options) {
|
|
|
- options = marked.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;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Add data separator before lines
|
|
|
* starting with '#' to markdown.
|
|
|
@@ -136,7 +43,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
if (section.getAttribute('data-separator')
|
|
|
|| section.getAttribute('data-separator-vertical')
|
|
|
|| section.getAttribute('data-separator-notes')) {
|
|
|
- section.outerHTML = slidify(markdown, {
|
|
|
+ section.outerHTML = marked.slidify(markdown, {
|
|
|
separator: section.getAttribute('data-separator'),
|
|
|
verticalSeparator: section.getAttribute('data-separator-vertical'),
|
|
|
notesSeparator: section.getAttribute('data-separator-notes')
|
|
|
@@ -144,7 +51,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
});
|
|
|
}
|
|
|
else {
|
|
|
- section.innerHTML = createMarkdownSlide(markdown);
|
|
|
+ section.innerHTML = marked.createMarkdownSlide(markdown);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -192,8 +99,8 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
// API
|
|
|
return {
|
|
|
initialize: function() {
|
|
|
- marked = require('./markdown').default(growiRenderer.process);
|
|
|
growiRenderer.setup();
|
|
|
+ marked = require('./markdown').default(growiRenderer.process);
|
|
|
processSlides();
|
|
|
convertSlides();
|
|
|
}
|