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