|
|
@@ -5,17 +5,20 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
*/
|
|
|
(function(root, factory) {
|
|
|
// parent window DOM (crowi.js) of presentation window.
|
|
|
- let parentWindow = window.parent;
|
|
|
+ const parentWindow = window.parent;
|
|
|
|
|
|
// create GrowiRenderer instance and setup.
|
|
|
- let growiRenderer = new GrowiRenderer(parentWindow.crowi, parentWindow.crowiRenderer, {mode: 'editor'});
|
|
|
+ const growiRenderer = new GrowiRenderer(parentWindow.crowi, parentWindow.crowiRenderer, { mode: 'editor' });
|
|
|
|
|
|
- let growiRendererPlugin = factory(growiRenderer);
|
|
|
+ const growiRendererPlugin = factory(growiRenderer);
|
|
|
growiRendererPlugin.initialize();
|
|
|
-}(this, function(growiRenderer) {
|
|
|
- const DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$',
|
|
|
- DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$',
|
|
|
- DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$';
|
|
|
+}(this, (growiRenderer) => {
|
|
|
+ /* eslint-disable no-useless-escape */
|
|
|
+ const DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$';
|
|
|
+ const DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$';
|
|
|
+ const DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$';
|
|
|
+ /* eslint-enable no-useless-escape */
|
|
|
+
|
|
|
let marked;
|
|
|
|
|
|
/**
|
|
|
@@ -23,16 +26,16 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
* starting with '#' to markdown.
|
|
|
*/
|
|
|
function divideSlides() {
|
|
|
- let sections = document.querySelectorAll('[data-markdown]');
|
|
|
+ const sections = document.querySelectorAll('[data-markdown]');
|
|
|
for (let i = 0, len = sections.length; i < len; i++) {
|
|
|
- let section = sections[i];
|
|
|
- let markdown = marked.getMarkdownFromSlide(section);
|
|
|
- let context = {markdown};
|
|
|
+ const section = sections[i];
|
|
|
+ const markdown = marked.getMarkdownFromSlide(section);
|
|
|
+ const context = { markdown };
|
|
|
const interceptorManager = growiRenderer.crowi.interceptorManager;
|
|
|
- let dataSeparator = section.getAttribute( 'data-separator' ) || DEFAULT_SLIDE_SEPARATOR;
|
|
|
+ let dataSeparator = section.getAttribute('data-separator') || DEFAULT_SLIDE_SEPARATOR;
|
|
|
// replace string '\n' to LF code.
|
|
|
dataSeparator = dataSeparator.replace(/\\n/g, '\n');
|
|
|
- const replaceValue = dataSeparator + '#';
|
|
|
+ const replaceValue = `${dataSeparator}#`;
|
|
|
// detach code block.
|
|
|
interceptorManager.process('prePreProcess', context);
|
|
|
// if there is only '\n' in the first line, replace it.
|
|
|
@@ -49,50 +52,50 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
* Converts data-markdown slides to HTML slides by GrowiRenderer.
|
|
|
*/
|
|
|
function convertSlides() {
|
|
|
- let sections = document.querySelectorAll('[data-markdown]');
|
|
|
+ const sections = document.querySelectorAll('[data-markdown]');
|
|
|
let markdown;
|
|
|
const interceptorManager = growiRenderer.crowi.interceptorManager;
|
|
|
|
|
|
for (let i = 0, len = sections.length; i < len; i++) {
|
|
|
- let section = sections[i];
|
|
|
+ const section = sections[i];
|
|
|
|
|
|
// Only parse the same slide once
|
|
|
if (!section.getAttribute('data-markdown-parsed')) {
|
|
|
section.setAttribute('data-markdown-parsed', 'true');
|
|
|
- let notes = section.querySelector( 'aside.notes' );
|
|
|
+ const notes = section.querySelector('aside.notes');
|
|
|
markdown = marked.getMarkdownFromSlide(section);
|
|
|
- let context = { markdown };
|
|
|
+ const context = { markdown };
|
|
|
|
|
|
interceptorManager.process('preRender', context)
|
|
|
- .then(() => interceptorManager.process('prePreProcess', context))
|
|
|
+ .then(() => { return interceptorManager.process('prePreProcess', context) })
|
|
|
.then(() => {
|
|
|
context.markdown = growiRenderer.preProcess(context.markdown);
|
|
|
})
|
|
|
- .then(() => interceptorManager.process('postPreProcess', context))
|
|
|
+ .then(() => { return interceptorManager.process('postPreProcess', context) })
|
|
|
.then(() => {
|
|
|
- context['parsedHTML'] = growiRenderer.process(context.markdown);
|
|
|
+ context.parsedHTML = growiRenderer.process(context.markdown);
|
|
|
})
|
|
|
- .then(() => interceptorManager.process('prePostProcess', context))
|
|
|
+ .then(() => { return interceptorManager.process('prePostProcess', context) })
|
|
|
.then(() => {
|
|
|
context.parsedHTML = growiRenderer.postProcess(context.parsedHTML);
|
|
|
})
|
|
|
- .then(() => interceptorManager.process('postPostProcess', context))
|
|
|
- .then(() => interceptorManager.process('preRenderHtml', context))
|
|
|
- .then(() => interceptorManager.process('postRenderHtml', context))
|
|
|
+ .then(() => { return interceptorManager.process('postPostProcess', context) })
|
|
|
+ .then(() => { return interceptorManager.process('preRenderHtml', context) })
|
|
|
+ .then(() => { return interceptorManager.process('postRenderHtml', context) })
|
|
|
.then(() => {
|
|
|
section.innerHTML = context.parsedHTML;
|
|
|
});
|
|
|
- marked.addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) ||
|
|
|
- section.parentNode.getAttribute( 'data-element-attributes' ) ||
|
|
|
- DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR,
|
|
|
- section.getAttribute( 'data-attributes' ) ||
|
|
|
- section.parentNode.getAttribute( 'data-attributes' ) ||
|
|
|
- DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR);
|
|
|
+ marked.addAttributes(section, section, null, section.getAttribute('data-element-attributes')
|
|
|
+ || section.parentNode.getAttribute('data-element-attributes')
|
|
|
+ || DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR,
|
|
|
+ section.getAttribute('data-attributes')
|
|
|
+ || section.parentNode.getAttribute('data-attributes')
|
|
|
+ || DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR);
|
|
|
|
|
|
// If there were notes, we need to re-add them after
|
|
|
// having overwritten the section's HTML
|
|
|
- if ( notes ) {
|
|
|
- section.appendChild( notes );
|
|
|
+ if (notes) {
|
|
|
+ section.appendChild(notes);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -100,12 +103,12 @@ import GrowiRenderer from '../../GrowiRenderer';
|
|
|
|
|
|
// API
|
|
|
return {
|
|
|
- initialize: async function() {
|
|
|
+ async initialize() {
|
|
|
growiRenderer.setup();
|
|
|
marked = require('./markdown').default(growiRenderer.process);
|
|
|
divideSlides();
|
|
|
marked.processSlides();
|
|
|
convertSlides();
|
|
|
- }
|
|
|
+ },
|
|
|
};
|
|
|
}));
|