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
5 changed files with 39 additions and 1 deletions

View File

@@ -34,12 +34,19 @@ props:
hint: Enable some language-neutral replacement + quotes beautification
order: 4
public: true
underline:
type: Boolean
default: false
title: Underline Support
hint: Enable underline by using _underline_
order: 5
public: true
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.
order: 5
order: 6
enum:
- Chinese
- English

View File

@@ -1,6 +1,7 @@
const md = require('markdown-it')
const mdAttrs = require('markdown-it-attrs')
const _ = require('lodash')
const underline = require('./underline')
const quoteStyles = {
Chinese: '””‘’',
@@ -30,6 +31,10 @@ module.exports = {
}
})
if (this.config.underline) {
mkdown.use(underline)
}
mkdown.use(mdAttrs, {
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;
}