Skip to content

Commit

Permalink
fix($markdown): Highlight kotlin code on snippets import (close: #1831)(
Browse files Browse the repository at this point in the history
  • Loading branch information
kefranabg authored and ulivz committed Sep 22, 2019
1 parent e0ef407 commit f913fea
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions packages/@vuepress/markdown/lib/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,31 @@ function wrap (code, lang) {
return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
}

function getLangCodeFromExtension (extension) {
const extensionMap = {
vue: 'markup',
html: 'markup',
md: 'markdown',
rb: 'ruby',
ts: 'typescript',
py: 'python',
sh: 'bash',
yml: 'yaml',
styl: 'stylus',
kt: 'kotlin'
}

return extensionMap[extension] || extension
}

module.exports = (str, lang) => {
if (!lang) {
return wrap(str, 'text')
}
lang = lang.toLowerCase()
const rawLang = lang
if (lang === 'vue' || lang === 'html') {
lang = 'markup'
}
if (lang === 'md') {
lang = 'markdown'
}
if (lang === 'rb') {
lang = 'ruby'
}
if (lang === 'ts') {
lang = 'typescript'
}
if (lang === 'py') {
lang = 'python'
}
if (lang === 'sh') {
lang = 'bash'
}
if (lang === 'yml') {
lang = 'yaml'
}
if (lang === 'styl') {
lang = 'stylus'
}

lang = getLangCodeFromExtension(lang)

if (!prism.languages[lang]) {
try {
Expand Down

0 comments on commit f913fea

Please sign in to comment.