Skip to content

Commit

Permalink
Merge pull request #209 from tangxiangmin/bugfix/208
Browse files Browse the repository at this point in the history
fix: 修复官网markdown文档代码未正确高亮
  • Loading branch information
蜗牛老湿 authored Sep 16, 2020
2 parents 496c0c7 + 32b7c45 commit 98b0702
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

1 comment on commit 98b0702

@vercel
Copy link

@vercel vercel bot commented on 98b0702 Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.