diff --git a/client/components/editor/editor-markdown.vue b/client/components/editor/editor-markdown.vue index 95b99ce2..1b1c483b 100644 --- a/client/components/editor/editor-markdown.vue +++ b/client/components/editor/editor-markdown.vue @@ -220,6 +220,7 @@ import mdMark from 'markdown-it-mark' import mdFootnote from 'markdown-it-footnote' import mdImsize from 'markdown-it-imsize' import katex from 'katex' +import underline from '../../libs/markdown-it-underline' import 'katex/dist/contrib/mhchem' import twemoji from 'twemoji' import plantuml from './markdown/plantuml' @@ -268,6 +269,7 @@ const md = new MarkdownIt({ .use(mdAttrs, { allowedAttributes: ['id', 'class', 'target'] }) + .use(underline) .use(mdEmoji) .use(mdTaskLists, {label: true, labelAfter: true}) .use(mdExpandTabs) diff --git a/client/libs/markdown-it-underline/index.js b/client/libs/markdown-it-underline/index.js new file mode 100644 index 00000000..c840ea0b --- /dev/null +++ b/client/libs/markdown-it-underline/index.js @@ -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; +} diff --git a/server/modules/rendering/markdown-core/definition.yml b/server/modules/rendering/markdown-core/definition.yml index 1dd91a1d..b7ccab9a 100644 --- a/server/modules/rendering/markdown-core/definition.yml +++ b/server/modules/rendering/markdown-core/definition.yml @@ -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 diff --git a/server/modules/rendering/markdown-core/renderer.js b/server/modules/rendering/markdown-core/renderer.js index 40632026..ef8cd5f0 100644 --- a/server/modules/rendering/markdown-core/renderer.js +++ b/server/modules/rendering/markdown-core/renderer.js @@ -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'] }) diff --git a/server/modules/rendering/markdown-core/underline.js b/server/modules/rendering/markdown-core/underline.js new file mode 100644 index 00000000..c840ea0b --- /dev/null +++ b/server/modules/rendering/markdown-core/underline.js @@ -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; +}