feat: code highlighting client-side
This commit is contained in:
parent
1bc98068e9
commit
d393a95495
@ -49,7 +49,7 @@
|
|||||||
.headline.grey--text.text--darken-3 {{title}}
|
.headline.grey--text.text--darken-3 {{title}}
|
||||||
.caption.grey--text.text--darken-1 {{description}}
|
.caption.grey--text.text--darken-1 {{description}}
|
||||||
v-divider
|
v-divider
|
||||||
.contents
|
.contents(ref='container')
|
||||||
slot(name='contents')
|
slot(name='contents')
|
||||||
|
|
||||||
v-flex(lg3, xl2, fill-height, v-if='$vuetify.breakpoint.lgAndUp')
|
v-flex(lg3, xl2, fill-height, v-if='$vuetify.breakpoint.lgAndUp')
|
||||||
@ -111,6 +111,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { StatusIndicator } from 'vue-status-indicator'
|
import { StatusIndicator } from 'vue-status-indicator'
|
||||||
|
import Prism from '@/libs/prism/prism.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -206,6 +207,9 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted () {
|
||||||
|
Prism.highlightAllUnder(this.$refs.container)
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleNavigation () {
|
toggleNavigation () {
|
||||||
this.navOpen = !this.navOpen
|
this.navOpen = !this.navOpen
|
||||||
|
@ -77,75 +77,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.hljs{
|
.prismjs{
|
||||||
display: block;
|
border: none;
|
||||||
overflow-x: auto;
|
border-radius: 5px;
|
||||||
padding: 1rem;
|
box-shadow: initial;
|
||||||
background: #232323;
|
background-color: mc('grey', '900');
|
||||||
color: #e6e1dc;
|
padding: 1rem 1rem 1rem 3rem;
|
||||||
margin: 1rem 24px;
|
margin: 1rem 24px;
|
||||||
border-radius: .5rem;
|
|
||||||
}
|
> code {
|
||||||
.hljs-comment,.hljs-quote{
|
box-shadow: initial;
|
||||||
color:#bc9458;
|
display: block;
|
||||||
font-style:italic
|
font-size: .85rem;
|
||||||
}
|
font-family: 'Source Code Pro', monospace;
|
||||||
.hljs-keyword,.hljs-selector-tag{
|
|
||||||
color:#c26230
|
&:after, &:before {
|
||||||
}
|
content: initial;
|
||||||
.hljs-string,.hljs-number,.hljs-regexp,.hljs-variable,.hljs-template-variable{
|
letter-spacing: initial;
|
||||||
color:#a5c261
|
}
|
||||||
}
|
}
|
||||||
.hljs-subst{
|
|
||||||
color:#519f50
|
|
||||||
}
|
|
||||||
.hljs-tag,.hljs-name{
|
|
||||||
color:#e8bf6a
|
|
||||||
}
|
|
||||||
.hljs-type{
|
|
||||||
color:#da4939
|
|
||||||
}
|
|
||||||
.hljs-symbol,.hljs-bullet,.hljs-built_in,.hljs-builtin-name,.hljs-attr,.hljs-link{
|
|
||||||
color:#6d9cbe
|
|
||||||
}
|
|
||||||
.hljs-params{
|
|
||||||
color:#d0d0ff
|
|
||||||
}
|
|
||||||
.hljs-attribute{
|
|
||||||
color:#cda869
|
|
||||||
}
|
|
||||||
.hljs-meta{
|
|
||||||
color:#9b859d
|
|
||||||
}
|
|
||||||
.hljs-title,.hljs-section{
|
|
||||||
color:#ffc66d
|
|
||||||
}
|
|
||||||
.hljs-addition{
|
|
||||||
background-color:#144212;
|
|
||||||
color:#e6e1dc;
|
|
||||||
display:inline-block;
|
|
||||||
width:100%
|
|
||||||
}
|
|
||||||
.hljs-deletion{
|
|
||||||
background-color:#600;
|
|
||||||
color:#e6e1dc;
|
|
||||||
display:inline-block;
|
|
||||||
width:100%
|
|
||||||
}
|
|
||||||
.hljs-selector-class{
|
|
||||||
color:#9b703f
|
|
||||||
}
|
|
||||||
.hljs-selector-id{
|
|
||||||
color:#8b98ab
|
|
||||||
}
|
|
||||||
.hljs-emphasis{
|
|
||||||
font-style:italic
|
|
||||||
}
|
|
||||||
.hljs-strong{
|
|
||||||
font-weight:bold
|
|
||||||
}
|
|
||||||
.hljs-link{
|
|
||||||
text-decoration:underline
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
key: htmlCodehighlighter
|
key: htmlCodehighlighter
|
||||||
title: Code Highlighting
|
title: Code Highlighting Post-Processor
|
||||||
description: Syntax highlighter for programming code
|
description: Syntax detector for programming code
|
||||||
author: requarks.io
|
author: requarks.io
|
||||||
icon: palette
|
icon: palette
|
||||||
enabledDefault: true
|
enabledDefault: true
|
||||||
|
@ -3,15 +3,12 @@ const hljs = require('highlight.js')
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
async init($, config) {
|
async init($, config) {
|
||||||
$('pre > code').each((idx, elm) => {
|
$('pre > code').each((idx, elm) => {
|
||||||
const lang = $(elm).attr('lang')
|
const codeClasses = $(elm).attr('class') || ''
|
||||||
if (lang) {
|
if (codeClasses.indexOf('language-') < 0) {
|
||||||
$(elm).html(hljs.highlight(lang, $(elm).text(), true).value)
|
|
||||||
} else {
|
|
||||||
const result = hljs.highlightAuto($(elm).text())
|
const result = hljs.highlightAuto($(elm).text())
|
||||||
$(elm).html(result.value)
|
$(elm).addClass('language-', result.language)
|
||||||
$(elm).attr('lang', result.language)
|
|
||||||
}
|
}
|
||||||
$(elm).parent().addClass('hljs')
|
$(elm).parent().addClass('prismjs line-numbers')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ module.exports = {
|
|||||||
typographer: this.config.typographer,
|
typographer: this.config.typographer,
|
||||||
quotes: _.get(quoteStyles, this.config.quotes, quoteStyles.English),
|
quotes: _.get(quoteStyles, this.config.quotes, quoteStyles.English),
|
||||||
highlight(str, lang) {
|
highlight(str, lang) {
|
||||||
return `<pre><code lang="${lang}">${_.escape(str)}</code></pre>`
|
return `<pre><code class="language-${lang}">${_.escape(str)}</code></pre>`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
key: markdownMathjax
|
key: markdownMathjax
|
||||||
title: Mathjax Pre-Processor
|
title: Mathjax Preprocessor
|
||||||
description: Pre-parse TeX blocks for Mathjax
|
description: Prepare TeX blocks for Mathjax
|
||||||
author: requarks.io
|
author: requarks.io
|
||||||
icon: functions
|
icon: functions
|
||||||
enabledDefault: false
|
enabledDefault: false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user