瀏覽代碼

feat: sub+sup+imsize markdown renderers

Nicolas Giard 6 年之前
父節點
當前提交
572393aa7b

+ 1 - 1
server/models/renderers.js

@@ -105,7 +105,7 @@ module.exports = class Renderer extends Model {
 
       // Build tree
       const rawCores = _.filter(renderers, renderer => !_.has(renderer, 'dependsOn')).map(core => {
-        core.children = _.concat([_.cloneDeep(core)], _.filter(renderers, ['dependsOn', core.key]))
+        core.children = _.filter(renderers, ['dependsOn', core.key])
         return core
       })
 

+ 8 - 0
server/modules/rendering/html-codehighlighter/definition.yml

@@ -0,0 +1,8 @@
+key: htmlCodehighlighter
+title: Code Highlighting
+description: Syntax highlighter for programming code
+author: requarks.io
+icon: palette
+enabledDefault: true
+dependsOn: htmlCore
+props: {}

+ 1 - 1
server/modules/rendering/html-mediaplayers/definition.yml

@@ -3,6 +3,6 @@ title: Media Players
 description: Embed players such as Youtube, Vimeo, Soundcloud, etc.
 author: requarks.io
 icon: subscriptions
-enabledDefault: false
+enabledDefault: true
 dependsOn: htmlCore
 props: {}

+ 2 - 2
server/modules/rendering/markdown-mermaid/definition.yml → server/modules/rendering/html-mermaid/definition.yml

@@ -1,8 +1,8 @@
-key: markdownMermaid
+key: htmlMermaid
 title: Mermaid
 description: Generate flowcharts from Mermaid syntax
 author: requarks.io
 icon: merge_type
 enabledDefault: false
-dependsOn: markdownCore
+dependsOn: htmlCore
 props: {}

+ 0 - 0
server/modules/rendering/markdown-mermaid/renderer.js → server/modules/rendering/html-mermaid/renderer.js


+ 2 - 2
server/modules/rendering/markdown-plantuml/definition.yml → server/modules/rendering/html-plantuml/definition.yml

@@ -1,8 +1,8 @@
-key: markdownPlantuml
+key: htmlPlantuml
 title: PlantUML
 description: Generate diagrams from PlantUML syntax
 author: requarks.io
 icon: multiline_chart
 enabledDefault: false
-dependsOn: markdownCore
+dependsOn: htmlCore
 props: {}

+ 0 - 0
server/modules/rendering/markdown-plantuml/renderer.js → server/modules/rendering/html-plantuml/renderer.js


+ 0 - 5
server/modules/rendering/markdown-core/definition.yml

@@ -44,8 +44,3 @@ props:
       - Russian
       - Spanish
       - Swedish
-  highlightCode:
-    type: Boolean
-    default: true
-    title: Highlight code blocks
-    hint: Add syntax coloring to code blocks.

+ 6 - 8
server/modules/rendering/markdown-core/renderer.js

@@ -1,5 +1,4 @@
 const md = require('markdown-it')
-// const hljs = require('highlight.js')
 const _ = require('lodash')
 
 const quoteStyles = {
@@ -26,17 +25,16 @@ module.exports = {
       typographer: this.config.typographer,
       quotes: _.get(quoteStyles, this.config.quotes, quoteStyles.English),
       highlight(str, lang) {
-        // if (this.config.highlightCode && lang && hljs.getLanguage(lang)) {
-        //   try {
-        //     return '<pre class="hljs"><code>' + hljs.highlight(lang, str, true).value + '</code></pre>'
-        //   } catch (err) {
-        //     return '<pre><code>' + _.escape(str) + '</code></pre>'
-        //   }
-        // }
         return '<pre><code>' + _.escape(str) + '</code></pre>'
       }
     })
 
+    for (let child of this.children) {
+      console.info(child)
+      const renderer = require(`../${_.kebabCase(child.key)}/renderer.js`)
+      renderer.init(mkdown, child.config)
+    }
+
     return mkdown.render(this.input)
   }
 }

+ 8 - 0
server/modules/rendering/markdown-imsize/definition.yml

@@ -0,0 +1,8 @@
+key: markdownImsize
+title: Image Size
+description: Adds dimensions attributes to images
+author: requarks.io
+icon: insert_photo
+enabledDefault: true
+dependsOn: markdownCore
+props: {}

+ 11 - 0
server/modules/rendering/markdown-imsize/renderer.js

@@ -0,0 +1,11 @@
+const mdImsize = require('markdown-it-imsize')
+
+// ------------------------------------
+// Markdown - Image Size
+// ------------------------------------
+
+module.exports = {
+  init (md, conf) {
+    md.use(mdImsize)
+  }
+}

+ 18 - 0
server/modules/rendering/markdown-supsub/definition.yml

@@ -0,0 +1,18 @@
+key: markdownSupsub
+title: Subscript/Superscript
+description: Parse subscript and superscript tags
+author: requarks.io
+icon: format_size
+enabledDefault: true
+dependsOn: markdownCore
+props:
+  subEnabled:
+    type: Boolean
+    title: Subscript
+    hint: Enable subscript tags
+    default: true
+  supEnabled:
+    type: Boolean
+    title: Supercript
+    hint: Enable supercript tags
+    default: true

+ 17 - 0
server/modules/rendering/markdown-supsub/renderer.js

@@ -0,0 +1,17 @@
+const mdSub = require('markdown-it-sub')
+const mdSup = require('markdown-it-sup')
+
+// ------------------------------------
+// Markdown - Subscript / Superscript
+// ------------------------------------
+
+module.exports = {
+  init (md, conf) {
+    if (conf.subEnabled) {
+      md.use(mdSub)
+    }
+    if (conf.supEnabled) {
+      md.use(mdSup)
+    }
+  }
+}