Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 34 additions & 38 deletions lib/highlight.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const escapeHtml = require('escape-html')
// import escapeHtml from 'escape-html'
// const prism = require('prismjs')
// const loadLanguages = require('prismjs/components/index')
// const { logger, chalk, escapeHtml } = require('@vuepress/shared-utils')
import escapeHtml from 'escape-html'
import prism from 'prismjs'
// import loadLanguages from 'prismjs/components/index.js'

// required to make embedded highlighting work...
// loadLanguages(['markup', 'css', 'javascript'])
Expand All @@ -14,36 +12,34 @@ function wrap (code, lang) {
return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
}

module.exports = wrap

// function highlightCode (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 === 'ts') {
// lang = 'typescript'
// }
// if (lang === 'py') {
// lang = 'python'
// }
// if (!prism.languages[lang]) {
// try {
// // loadLanguages([lang])
// } catch (e) {
// console.warn(`[vuepress] Syntax highlight for language "${lang}" is not supported.`)
// }
// }
// if (prism.languages[lang]) {
// const code = prism.highlight(str, prism.languages[lang], lang)
// return wrap(code, rawLang)
// }
// return wrap(str, 'text')
// }
export default function highlightCode (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 === 'ts') {
lang = 'typescript'
}
if (lang === 'py') {
lang = 'python'
}
if (!prism.languages[lang]) {
try {
// loadLanguages([lang])
} catch (e) {
console.warn(`[vuepress] Syntax highlight for language "${lang}" is not supported.`)
}
}
if (prism.languages[lang]) {
const code = prism.highlight(str, prism.languages[lang], lang)
return wrap(code, rawLang)
}
return wrap(str, 'text')
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"vue": "^2.5.17",
"vue-jest": "^3.0.0",
"vue-template-compiler": "^2.5.17",
"vuepress": "^1.0.0-alpha.13"
"vuepress": "^1.0.0-alpha.16"
},
"repository": {
"type": "git",
Expand Down