|
@@ -13,53 +13,8 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
let growiRendererPlugin = factory(growiRenderer);
|
|
let growiRendererPlugin = factory(growiRenderer);
|
|
|
growiRendererPlugin.initialize();
|
|
growiRendererPlugin.initialize();
|
|
|
}(this, function(growiRenderer) {
|
|
}(this, function(growiRenderer) {
|
|
|
- const DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$';
|
|
|
|
|
- const DEFAULT_NOTES_SEPARATOR = 'notes?:';
|
|
|
|
|
const SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
|
|
const SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Retrieves the markdown contents of a slide section
|
|
|
|
|
- * element. Normalizes leading tabs/whitespace.
|
|
|
|
|
- * Referred from The reveal.js markdown plugin.
|
|
|
|
|
- * https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
|
|
|
- */
|
|
|
|
|
- function getMarkdownFromSlide(section) {
|
|
|
|
|
- // look for a <script> or <textarea data-template> wrapper
|
|
|
|
|
- let template = section.querySelector('[data-template]') || section.querySelector('script');
|
|
|
|
|
-
|
|
|
|
|
- // strip leading whitespace so it isn't evaluated as code
|
|
|
|
|
- let text = (template || section).textContent;
|
|
|
|
|
-
|
|
|
|
|
- // restore script end tags
|
|
|
|
|
- text = text.replace(new RegExp(SCRIPT_END_PLACEHOLDER, 'g'), '</script>');
|
|
|
|
|
-
|
|
|
|
|
- let leadingWs = text.match(/^\n?(\s*)/)[1].length;
|
|
|
|
|
- let leadingTabs = text.match(/^\n?(\t*)/)[1].length;
|
|
|
|
|
-
|
|
|
|
|
- if (leadingTabs > 0) {
|
|
|
|
|
- text = text.replace(new RegExp('\\n?\\t{' + leadingTabs + '}', 'g'), '\n');
|
|
|
|
|
- }
|
|
|
|
|
- else if (leadingWs > 1) {
|
|
|
|
|
- text = text.replace(new RegExp('\\n? {' + leadingWs + '}', 'g'), '\n');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return text;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Inspects the given options and fills out default
|
|
|
|
|
- * values for what's not defined.
|
|
|
|
|
- * Referred from The reveal.js markdown plugin.
|
|
|
|
|
- * https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
|
|
|
- */
|
|
|
|
|
- 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;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ let marked;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Helper function for constructing a markdown slide.
|
|
* Helper function for constructing a markdown slide.
|
|
@@ -67,7 +22,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
* https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
* https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
|
*/
|
|
*/
|
|
|
function createMarkdownSlide(content, options) {
|
|
function createMarkdownSlide(content, options) {
|
|
|
- options = getSlidifyOptions(options);
|
|
|
|
|
|
|
+ options = marked.getSlidifyOptions(options);
|
|
|
|
|
|
|
|
let notesMatch = content.split(new RegExp(options.notesSeparator, 'mgi'));
|
|
let notesMatch = content.split(new RegExp(options.notesSeparator, 'mgi'));
|
|
|
|
|
|
|
@@ -89,7 +44,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
* https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
* https://github.com/hakimel/reveal.js/blob/master/plugin/markdown/markdown.js
|
|
|
*/
|
|
*/
|
|
|
function slidify(markdown, options) {
|
|
function slidify(markdown, options) {
|
|
|
- options = getSlidifyOptions(options);
|
|
|
|
|
|
|
+ options = marked.getSlidifyOptions(options);
|
|
|
|
|
|
|
|
let separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
|
|
let separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
|
|
|
horizontalSeparatorRegex = new RegExp( options.separator );
|
|
horizontalSeparatorRegex = new RegExp( options.separator );
|
|
@@ -176,7 +131,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
for (let i = 0, len = sections.length; i < len; i++) {
|
|
for (let i = 0, len = sections.length; i < len; i++) {
|
|
|
section = sections[i];
|
|
section = sections[i];
|
|
|
// add data separator '\n\n\n' to markdown.
|
|
// add data separator '\n\n\n' to markdown.
|
|
|
- markdown = divideSlides(getMarkdownFromSlide(section));
|
|
|
|
|
|
|
+ markdown = divideSlides(marked.getMarkdownFromSlide(section));
|
|
|
|
|
|
|
|
if (section.getAttribute('data-separator')
|
|
if (section.getAttribute('data-separator')
|
|
|
|| section.getAttribute('data-separator-vertical')
|
|
|| section.getAttribute('data-separator-vertical')
|
|
@@ -208,7 +163,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
// Only parse the same slide once
|
|
// Only parse the same slide once
|
|
|
if (!section.getAttribute('data-markdown-parsed')) {
|
|
if (!section.getAttribute('data-markdown-parsed')) {
|
|
|
section.setAttribute('data-markdown-parsed', 'true');
|
|
section.setAttribute('data-markdown-parsed', 'true');
|
|
|
- markdown = getMarkdownFromSlide(section);
|
|
|
|
|
|
|
+ markdown = marked.getMarkdownFromSlide(section);
|
|
|
let context = { markdown };
|
|
let context = { markdown };
|
|
|
|
|
|
|
|
interceptorManager.process('preRender', context)
|
|
interceptorManager.process('preRender', context)
|
|
@@ -237,6 +192,7 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
// API
|
|
// API
|
|
|
return {
|
|
return {
|
|
|
initialize: function() {
|
|
initialize: function() {
|
|
|
|
|
+ marked = require('./markdown').default(growiRenderer.process);
|
|
|
growiRenderer.setup();
|
|
growiRenderer.setup();
|
|
|
processSlides();
|
|
processSlides();
|
|
|
convertSlides();
|
|
convertSlides();
|