Просмотр исходного кода

externalize emoji and mathjax configuration

Yuki Takei 8 лет назад
Родитель
Сommit
bd38f7c027

+ 11 - 9
resource/js/util/GrowiRenderer.js

@@ -8,6 +8,9 @@ import Tsv2Table from './LangProcessor/Tsv2Table';
 import Template from './LangProcessor/Template';
 import PlantUML from './LangProcessor/PlantUML';
 
+import EmojiConfigurer from './markdown-it/emoji';
+import MathJaxConfigurer from './markdown-it/mathjax';
+
 export default class GrowiRenderer {
 
 
@@ -21,6 +24,10 @@ export default class GrowiRenderer {
     this.postProcessors = [
     ];
 
+    this.markdownItConfigurers = [
+      new EmojiConfigurer(crowi),
+      new MathJaxConfigurer(crowi),
+    ];
     this.langProcessors = {
       'tsv': new Tsv2Table(crowi),
       'tsv-h': new Tsv2Table(crowi, {header: true}),
@@ -29,6 +36,7 @@ export default class GrowiRenderer {
     };
 
     this.configure = this.configure.bind(this);
+    this.configurePlugins = this.configurePlugins.bind(this);
     this.parseMarkdown = this.parseMarkdown.bind(this);
     this.codeRenderer = this.codeRenderer.bind(this);
 
@@ -55,15 +63,9 @@ export default class GrowiRenderer {
    * @param {any} config
    */
   configurePlugins(config) {
-    this.md
-        .use(require('markdown-it-emoji'))
-        .use(require('markdown-it-mathjax')());
-
-    // integrate markdown-it-emoji and emojione
-    this.md.renderer.rules.emoji = (token, idx) => {
-      const shortname = `:${token[idx].markup}:`;
-      return emojione.shortnameToImage(shortname);
-    };
+    this.markdownItConfigurers.forEach((configurer) => {
+      configurer.configure(this.md);
+    });
   }
 
   preProcess(markdown) {

+ 17 - 0
resource/js/util/markdown-it/emoji.js

@@ -0,0 +1,17 @@
+export default class EmojiConfigurer {
+
+  constructor(crowi) {
+    this.crowi = crowi;
+  }
+
+  configure(md) {
+    md.use(require('markdown-it-emoji'));
+
+    // integrate markdown-it-emoji and emojione
+    md.renderer.rules.emoji = (token, idx) => {
+      const shortname = `:${token[idx].markup}:`;
+      return emojione.shortnameToImage(shortname);
+    };
+  }
+
+}

+ 11 - 0
resource/js/util/markdown-it/mathjax.js

@@ -0,0 +1,11 @@
+export default class MathJaxConfigurer {
+
+  constructor(crowi) {
+    this.crowi = crowi;
+  }
+
+  configure(md) {
+    md.use(require('markdown-it-mathjax')());
+  }
+
+}