Skip to content

Commit

Permalink
fix: 修复 官网markdown文档代码未正确高亮
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxiangmin committed Sep 15, 2020
1 parent 496c0c7 commit 32b7c45
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions build/md-loader/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const Config = require('markdown-it-chain')
const anchorPlugin = require('markdown-it-anchor')
const slugify = require('transliteration').slugify
const hljs = require('highlight.js')

const containers = require('./containers')
const overWriteFenceRule = require('./fence')

const config = new Config()

// 配置markdown-it常规代码高亮,相关文档:https://markdown-it.github.io/markdown-it/#MarkdownIt.new
const highlight = (str, lang) => {
if (!lang || !hljs.getLanguage(lang)) {
return '<pre><code class="hljs">' + str + '</code></pre>'
}
const html = hljs.highlight(lang, str, true, undefined).value
return `<pre><code class="hljs language-${lang}">${html}</code></pre>`
}

config.options
.html(true)
.highlight(highlight)
.end()

.plugin('anchor')
Expand Down

0 comments on commit 32b7c45

Please sign in to comment.