feat: rendering pipeline logic
This commit is contained in:
8
server/modules/rendering/html-asciinema/definition.yml
Normal file
8
server/modules/rendering/html-asciinema/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: htmlAsciinema
|
||||
title: Asciinema
|
||||
description: Embed asciinema players from compatible links
|
||||
author: requarks.io
|
||||
icon: subtitles
|
||||
enabledDefault: false
|
||||
dependsOn: htmlCore
|
||||
props: {}
|
1
server/modules/rendering/html-asciinema/renderer.js
Normal file
1
server/modules/rendering/html-asciinema/renderer.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
8
server/modules/rendering/html-blockquotes/definition.yml
Normal file
8
server/modules/rendering/html-blockquotes/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: htmlBlockquotes
|
||||
title: Blockquotes
|
||||
description: Parse blockquotes box styling
|
||||
author: requarks.io
|
||||
icon: insert_comment
|
||||
enabledDefault: true
|
||||
dependsOn: htmlCore
|
||||
props: {}
|
1
server/modules/rendering/html-blockquotes/renderer.js
Normal file
1
server/modules/rendering/html-blockquotes/renderer.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
8
server/modules/rendering/html-core/definition.yml
Normal file
8
server/modules/rendering/html-core/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: htmlCore
|
||||
title: Core
|
||||
description: Basic HTML Parser
|
||||
author: requarks.io
|
||||
input: html
|
||||
output: html
|
||||
icon: crop_free
|
||||
props: {}
|
5
server/modules/rendering/html-core/renderer.js
Normal file
5
server/modules/rendering/html-core/renderer.js
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
async render() {
|
||||
return this.input
|
||||
}
|
||||
}
|
8
server/modules/rendering/html-mathjax/definition.yml
Normal file
8
server/modules/rendering/html-mathjax/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: htmlMathjax
|
||||
title: Mathjax Processor
|
||||
description: TeX/MathML Math Equations Parser
|
||||
author: requarks.io
|
||||
icon: functions
|
||||
enabledDefault: false
|
||||
dependsOn: htmlCore
|
||||
props: {}
|
86
server/modules/rendering/html-mathjax/mathjax.js
Normal file
86
server/modules/rendering/html-mathjax/mathjax.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const mathjax = require('mathjax-node')
|
||||
const _ = require('lodash')
|
||||
|
||||
// ------------------------------------
|
||||
// Mathjax
|
||||
// ------------------------------------
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
const mathRegex = [
|
||||
{
|
||||
format: 'TeX',
|
||||
regex: /\\\[([\s\S]*?)\\\]/g
|
||||
},
|
||||
{
|
||||
format: 'inline-TeX',
|
||||
regex: /\\\((.*?)\\\)/g
|
||||
},
|
||||
{
|
||||
format: 'MathML',
|
||||
regex: /<math([\s\S]*?)<\/math>/g
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
key: 'common/mathjax',
|
||||
title: 'Mathjax',
|
||||
dependsOn: [],
|
||||
props: [],
|
||||
init (conf) {
|
||||
mathjax.config({
|
||||
MathJax: {
|
||||
jax: ['input/TeX', 'input/MathML', 'output/SVG'],
|
||||
extensions: ['tex2jax.js', 'mml2jax.js'],
|
||||
TeX: {
|
||||
extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
|
||||
},
|
||||
SVG: {
|
||||
scale: 120,
|
||||
font: 'STIX-Web'
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async render (content) {
|
||||
let matchStack = []
|
||||
let replaceStack = []
|
||||
let currentMatch
|
||||
let mathjaxState = {}
|
||||
|
||||
_.forEach(mathRegex, mode => {
|
||||
do {
|
||||
currentMatch = mode.regex.exec(content)
|
||||
if (currentMatch) {
|
||||
matchStack.push(currentMatch[0])
|
||||
replaceStack.push(
|
||||
new Promise((resolve, reject) => {
|
||||
mathjax.typeset({
|
||||
math: (mode.format === 'MathML') ? currentMatch[0] : currentMatch[1],
|
||||
format: mode.format,
|
||||
speakText: false,
|
||||
svg: true,
|
||||
state: mathjaxState,
|
||||
timeout: 30 * 1000
|
||||
}, result => {
|
||||
if (!result.errors) {
|
||||
resolve(result.svg)
|
||||
} else {
|
||||
resolve(currentMatch[0])
|
||||
WIKI.logger.warn(result.errors.join(', '))
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
} while (currentMatch)
|
||||
})
|
||||
|
||||
return (matchStack.length > 0) ? Promise.all(replaceStack).then(results => {
|
||||
_.forEach(matchStack, (repMatch, idx) => {
|
||||
content = content.replace(repMatch, results[idx])
|
||||
})
|
||||
return content
|
||||
}) : Promise.resolve(content)
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
key: htmlMedia
|
||||
title: Media Players
|
||||
description: Embed players such as Youtube, Vimeo, Soundcloud, etc.
|
||||
author: requarks.io
|
||||
icon: subscriptions
|
||||
enabledDefault: false
|
||||
dependsOn: htmlCore
|
||||
props: {}
|
1
server/modules/rendering/html-mediaplayers/renderer.js
Normal file
1
server/modules/rendering/html-mediaplayers/renderer.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
18
server/modules/rendering/html-security/definition.yml
Normal file
18
server/modules/rendering/html-security/definition.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
key: htmlSecurity
|
||||
title: Security
|
||||
description: Filter and strips potentially dangerous content
|
||||
author: requarks.io
|
||||
icon: whatshot
|
||||
enabledDefault: true
|
||||
dependsOn: htmlCore
|
||||
props:
|
||||
stripJS:
|
||||
type: Boolean
|
||||
title: Strip Javascript
|
||||
default: false
|
||||
hint: Javascript code within code blocks won't be affected
|
||||
filterBadWords:
|
||||
type: Boolean
|
||||
title: Filter Bad Words
|
||||
default: false
|
||||
hint: Replace bad words with asterisks
|
1
server/modules/rendering/html-security/renderer.js
Normal file
1
server/modules/rendering/html-security/renderer.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
8
server/modules/rendering/markdown-abbr/definition.yml
Normal file
8
server/modules/rendering/markdown-abbr/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: markdownAbbr
|
||||
title: Abbreviations
|
||||
description: Parse abbreviations into abbr tags
|
||||
author: requarks.io
|
||||
icon: text_format
|
||||
enabledDefault: true
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
11
server/modules/rendering/markdown-abbr/renderer.js
Normal file
11
server/modules/rendering/markdown-abbr/renderer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mdAbbr = require('markdown-it-abbr')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Abbreviations
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
init (md, conf) {
|
||||
md.use(mdAbbr)
|
||||
}
|
||||
}
|
51
server/modules/rendering/markdown-core/definition.yml
Normal file
51
server/modules/rendering/markdown-core/definition.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
key: markdownCore
|
||||
title: Core
|
||||
description: Basic Markdown Parser
|
||||
author: requarks.io
|
||||
input: markdown
|
||||
output: html
|
||||
icon: crop_free
|
||||
props:
|
||||
allowHTML:
|
||||
type: Boolean
|
||||
default: true
|
||||
title: Allow HTML
|
||||
hint: Enable HTML tags in content
|
||||
linkify:
|
||||
type: Boolean
|
||||
default: true
|
||||
title: Automatically convert links
|
||||
hint: Links will automatically be converted to clickable links.
|
||||
linebreaks:
|
||||
type: Boolean
|
||||
default: true
|
||||
title: Automatically convert line breaks
|
||||
hint: Add linebreaks within paragraphs.
|
||||
typographer:
|
||||
type: Boolean
|
||||
default: false
|
||||
title: Typographer
|
||||
hint: Enable some language-neutral replacement + quotes beautification
|
||||
quotes:
|
||||
type: String
|
||||
default: English
|
||||
title: Quotes style
|
||||
hint: When typographer is enabled. Double + single quotes replacement pairs. e.g. «»„“ for Russian, „“‚‘ for German, etc.
|
||||
enum:
|
||||
- Chinese
|
||||
- English
|
||||
- French
|
||||
- German
|
||||
- Greek
|
||||
- Japanese
|
||||
- Hungarian
|
||||
- Polish
|
||||
- Portuguese
|
||||
- Russian
|
||||
- Spanish
|
||||
- Swedish
|
||||
highlightCode:
|
||||
type: Boolean
|
||||
default: true
|
||||
title: Highlight code blocks
|
||||
hint: Add syntax coloring to code blocks.
|
42
server/modules/rendering/markdown-core/renderer.js
Normal file
42
server/modules/rendering/markdown-core/renderer.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const md = require('markdown-it')
|
||||
// const hljs = require('highlight.js')
|
||||
const _ = require('lodash')
|
||||
|
||||
const quoteStyles = {
|
||||
Chinese: '””‘’',
|
||||
English: '“”‘’',
|
||||
French: ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'],
|
||||
German: '„“‚‘',
|
||||
Greek: '«»‘’',
|
||||
Japanese: '「」「」',
|
||||
Hungarian: '„”’’',
|
||||
Polish: '„”‚‘',
|
||||
Portuguese: '«»‘’',
|
||||
Russian: '«»„“',
|
||||
Spanish: '«»‘’',
|
||||
Swedish: '””’’'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
async render() {
|
||||
const mkdown = md({
|
||||
html: this.config.allowHTML,
|
||||
breaks: this.config.linebreaks,
|
||||
linkify: this.config.linkify,
|
||||
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>'
|
||||
}
|
||||
})
|
||||
|
||||
return mkdown.render(this.input)
|
||||
}
|
||||
}
|
8
server/modules/rendering/markdown-emoji/definition.yml
Normal file
8
server/modules/rendering/markdown-emoji/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: markdownEmoji
|
||||
title: Emoji
|
||||
description: Convert tags to emojis
|
||||
author: requarks.io
|
||||
icon: tag_faces
|
||||
enabledDefault: true
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
11
server/modules/rendering/markdown-emoji/renderer.js
Normal file
11
server/modules/rendering/markdown-emoji/renderer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mdEmoji = require('markdown-it-emoji')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Emoji
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
init (md, conf) {
|
||||
md.use(mdEmoji)
|
||||
}
|
||||
}
|
13
server/modules/rendering/markdown-expandtabs/definition.yml
Normal file
13
server/modules/rendering/markdown-expandtabs/definition.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
key: markdownExpandtabs
|
||||
title: Expand Tabs
|
||||
description: Replace tabs with spaces in code blocks
|
||||
author: requarks.io
|
||||
icon: space_bar
|
||||
enabledDefault: true
|
||||
dependsOn: markdownCore
|
||||
props:
|
||||
tabWidth:
|
||||
type: Number
|
||||
title: Tab Width
|
||||
hint: Amount of spaces for each tab
|
||||
default: 4
|
14
server/modules/rendering/markdown-expandtabs/renderer.js
Normal file
14
server/modules/rendering/markdown-expandtabs/renderer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const mdExpandTabs = require('markdown-it-expand-tabs')
|
||||
const _ = require('lodash')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Expand Tabs
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
init (md, conf) {
|
||||
md.use(mdExpandTabs, {
|
||||
tabWidth: _.toInteger(conf.tabWidth || 4)
|
||||
})
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
key: markdownFootnotes
|
||||
title: Footnotes
|
||||
description: Parse footnotes references
|
||||
author: requarks.io
|
||||
icon: low_priority
|
||||
enabledDefault: true
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
11
server/modules/rendering/markdown-footnotes/renderer.js
Normal file
11
server/modules/rendering/markdown-footnotes/renderer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mdFootnote = require('markdown-it-footnote')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Footnotes
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
init (md, conf) {
|
||||
md.use(mdFootnote)
|
||||
}
|
||||
}
|
8
server/modules/rendering/markdown-mathjax/definition.yml
Normal file
8
server/modules/rendering/markdown-mathjax/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: markdownMathjax
|
||||
title: Mathjax Pre-Processor
|
||||
description: Pre-parse TeX blocks for Mathjax
|
||||
author: requarks.io
|
||||
icon: functions
|
||||
enabledDefault: false
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
11
server/modules/rendering/markdown-mathjax/renderer.js
Normal file
11
server/modules/rendering/markdown-mathjax/renderer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mdMathjax = require('markdown-it-mathjax')()
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Mathjax Preprocessor
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
init (md, conf) {
|
||||
md.use(mdMathjax)
|
||||
}
|
||||
}
|
8
server/modules/rendering/markdown-mermaid/definition.yml
Normal file
8
server/modules/rendering/markdown-mermaid/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: markdownMermaid
|
||||
title: Mermaid
|
||||
description: Generate flowcharts from Mermaid syntax
|
||||
author: requarks.io
|
||||
icon: merge_type
|
||||
enabledDefault: false
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
1
server/modules/rendering/markdown-mermaid/renderer.js
Normal file
1
server/modules/rendering/markdown-mermaid/renderer.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
@@ -0,0 +1,8 @@
|
||||
key: markdownPlantuml
|
||||
title: PlantUML
|
||||
description: Generate diagrams from PlantUML syntax
|
||||
author: requarks.io
|
||||
icon: multiline_chart
|
||||
enabledDefault: false
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
1
server/modules/rendering/markdown-plantuml/renderer.js
Normal file
1
server/modules/rendering/markdown-plantuml/renderer.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {}
|
@@ -0,0 +1,8 @@
|
||||
key: markdownTasklists
|
||||
title: Task Lists
|
||||
description: Parse task lists to checkboxes
|
||||
author: requarks.io
|
||||
icon: list
|
||||
enabledDefault: true
|
||||
dependsOn: markdownCore
|
||||
props: {}
|
11
server/modules/rendering/markdown-tasklists/renderer.js
Normal file
11
server/modules/rendering/markdown-tasklists/renderer.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const mdTaskLists = require('markdown-it-task-lists')
|
||||
|
||||
// ------------------------------------
|
||||
// Markdown - Task Lists
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
init (md, conf) {
|
||||
md.use(mdTaskLists)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user