feat: rendering pipeline logic

This commit is contained in:
Nicolas Giard
2018-09-09 20:33:10 -04:00
parent 0b93544677
commit 09d1f580d9
39 changed files with 210 additions and 86 deletions

View 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: {}

View File

@@ -0,0 +1 @@
module.exports = {}

View 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: {}

View File

@@ -0,0 +1 @@
module.exports = {}

View File

@@ -0,0 +1,8 @@
key: htmlCore
title: Core
description: Basic HTML Parser
author: requarks.io
input: html
output: html
icon: crop_free
props: {}

View File

@@ -0,0 +1,5 @@
module.exports = {
async render() {
return this.input
}
}

View 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: {}

View 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)
}
}

View File

@@ -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: {}

View File

@@ -0,0 +1 @@
module.exports = {}

View 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

View File

@@ -0,0 +1 @@
module.exports = {}

View 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: {}

View File

@@ -0,0 +1,11 @@
const mdAbbr = require('markdown-it-abbr')
// ------------------------------------
// Markdown - Abbreviations
// ------------------------------------
module.exports = {
init (md, conf) {
md.use(mdAbbr)
}
}

View 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.

View 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)
}
}

View 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: {}

View File

@@ -0,0 +1,11 @@
const mdEmoji = require('markdown-it-emoji')
// ------------------------------------
// Markdown - Emoji
// ------------------------------------
module.exports = {
init (md, conf) {
md.use(mdEmoji)
}
}

View 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

View 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)
})
}
}

View File

@@ -0,0 +1,8 @@
key: markdownFootnotes
title: Footnotes
description: Parse footnotes references
author: requarks.io
icon: low_priority
enabledDefault: true
dependsOn: markdownCore
props: {}

View File

@@ -0,0 +1,11 @@
const mdFootnote = require('markdown-it-footnote')
// ------------------------------------
// Markdown - Footnotes
// ------------------------------------
module.exports = {
init (md, conf) {
md.use(mdFootnote)
}
}

View 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: {}

View File

@@ -0,0 +1,11 @@
const mdMathjax = require('markdown-it-mathjax')()
// ------------------------------------
// Markdown - Mathjax Preprocessor
// ------------------------------------
module.exports = {
init (md, conf) {
md.use(mdMathjax)
}
}

View 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: {}

View File

@@ -0,0 +1 @@
module.exports = {}

View File

@@ -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: {}

View File

@@ -0,0 +1 @@
module.exports = {}

View File

@@ -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: {}

View File

@@ -0,0 +1,11 @@
const mdTaskLists = require('markdown-it-task-lists')
// ------------------------------------
// Markdown - Task Lists
// ------------------------------------
module.exports = {
init (md, conf) {
md.use(mdTaskLists)
}
}