feat: underline markdown support (#2073)

* fix: no markdown support for underline #2072
This commit is contained in:
Regev Brody 2020-06-19 01:37:24 +03:00 committed by GitHub
parent 0e6340f51e
commit e03a80dccc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 1 deletions

View File

@ -220,6 +220,7 @@ import mdMark from 'markdown-it-mark'
import mdFootnote from 'markdown-it-footnote' import mdFootnote from 'markdown-it-footnote'
import mdImsize from 'markdown-it-imsize' import mdImsize from 'markdown-it-imsize'
import katex from 'katex' import katex from 'katex'
import underline from '../../libs/markdown-it-underline'
import 'katex/dist/contrib/mhchem' import 'katex/dist/contrib/mhchem'
import twemoji from 'twemoji' import twemoji from 'twemoji'
import plantuml from './markdown/plantuml' import plantuml from './markdown/plantuml'
@ -268,6 +269,7 @@ const md = new MarkdownIt({
.use(mdAttrs, { .use(mdAttrs, {
allowedAttributes: ['id', 'class', 'target'] allowedAttributes: ['id', 'class', 'target']
}) })
.use(underline)
.use(mdEmoji) .use(mdEmoji)
.use(mdTaskLists, {label: true, labelAfter: true}) .use(mdTaskLists, {label: true, labelAfter: true})
.use(mdExpandTabs) .use(mdExpandTabs)

View File

@ -0,0 +1,12 @@
const renderEm = (tokens, idx, opts, env, slf) => {
const token = tokens[idx];
if (token.markup === '_') {
token.tag = 'u';
}
return slf.renderToken(tokens, idx, opts);
}
module.exports = (md) => {
md.renderer.rules.em_open = renderEm;
md.renderer.rules.em_close = renderEm;
}

View File

@ -34,12 +34,19 @@ props:
hint: Enable some language-neutral replacement + quotes beautification hint: Enable some language-neutral replacement + quotes beautification
order: 4 order: 4
public: true public: true
underline:
type: Boolean
default: false
title: Underline Support
hint: Enable underline by using _underline_
order: 5
public: true
quotes: quotes:
type: String type: String
default: English default: English
title: Quotes style title: Quotes style
hint: When typographer is enabled. Double + single quotes replacement pairs. e.g. «»„“ for Russian, „“‚‘ for German, etc. hint: When typographer is enabled. Double + single quotes replacement pairs. e.g. «»„“ for Russian, „“‚‘ for German, etc.
order: 5 order: 6
enum: enum:
- Chinese - Chinese
- English - English

View File

@ -1,6 +1,7 @@
const md = require('markdown-it') const md = require('markdown-it')
const mdAttrs = require('markdown-it-attrs') const mdAttrs = require('markdown-it-attrs')
const _ = require('lodash') const _ = require('lodash')
const underline = require('./underline')
const quoteStyles = { const quoteStyles = {
Chinese: '””‘’', Chinese: '””‘’',
@ -30,6 +31,10 @@ module.exports = {
} }
}) })
if (this.config.underline) {
mkdown.use(underline)
}
mkdown.use(mdAttrs, { mkdown.use(mdAttrs, {
allowedAttributes: ['id', 'class', 'target'] allowedAttributes: ['id', 'class', 'target']
}) })

View File

@ -0,0 +1,12 @@
const renderEm = (tokens, idx, opts, env, slf) => {
const token = tokens[idx];
if (token.markup === '_') {
token.tag = 'u';
}
return slf.renderToken(tokens, idx, opts);
}
module.exports = (md) => {
md.renderer.rules.em_open = renderEm;
md.renderer.rules.em_close = renderEm;
}