2018-09-02 21:13:57 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<editor class="editor" :extensions="extensions">
|
|
|
|
|
|
|
|
<div class="editor__content" slot="content" slot-scope="props">
|
|
|
|
<h2>
|
|
|
|
Code Highlighting
|
|
|
|
</h2>
|
|
|
|
<p>
|
|
|
|
These are code blocks with <strong>automatic syntax highlighting</strong> based on highlight.js.
|
|
|
|
</p>
|
2018-10-14 00:43:59 +08:00
|
|
|
<pre><code v-html="JavaScriptExample"></code></pre>
|
|
|
|
<pre><code v-html="CSSExample"></code></pre>
|
2018-10-13 22:22:33 +08:00
|
|
|
|
|
|
|
<p>
|
|
|
|
Note: tiptap doesn't import syntax highlighting language definitions from highlight.js. You
|
|
|
|
<strong>must</strong> import them and initialize the extension with all languages you want to support:
|
|
|
|
</p>
|
2018-10-14 00:43:59 +08:00
|
|
|
<pre><code v-html="ExplicitImportExample"></code></pre>
|
2018-09-02 21:13:57 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</editor>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-10-13 22:22:33 +08:00
|
|
|
import javascript from 'highlight.js/lib/languages/javascript'
|
|
|
|
import css from 'highlight.js/lib/languages/css'
|
|
|
|
|
2018-09-02 21:13:57 +08:00
|
|
|
import { Editor } from 'tiptap'
|
|
|
|
import {
|
|
|
|
CodeBlockHighlightNode,
|
|
|
|
HardBreakNode,
|
|
|
|
HeadingNode,
|
|
|
|
BoldMark,
|
|
|
|
CodeMark,
|
|
|
|
ItalicMark,
|
|
|
|
} from 'tiptap-extensions'
|
|
|
|
|
2018-09-07 05:18:30 +08:00
|
|
|
import {
|
2018-10-14 00:43:59 +08:00
|
|
|
JavaScriptExample,
|
|
|
|
CSSExample,
|
|
|
|
ExplicitImportExample,
|
2018-09-07 05:18:30 +08:00
|
|
|
} from './examples'
|
2018-09-02 21:13:57 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Editor,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
extensions: [
|
2018-10-13 22:22:33 +08:00
|
|
|
new CodeBlockHighlightNode({
|
|
|
|
languages: {
|
|
|
|
javascript,
|
2018-10-14 00:43:59 +08:00
|
|
|
css,
|
|
|
|
},
|
2018-10-13 22:22:33 +08:00
|
|
|
}),
|
2018-09-02 21:13:57 +08:00
|
|
|
new HardBreakNode(),
|
|
|
|
new HeadingNode({ maxLevel: 3 }),
|
|
|
|
new BoldMark(),
|
|
|
|
new CodeMark(),
|
|
|
|
new ItalicMark(),
|
|
|
|
],
|
2018-10-14 00:43:59 +08:00
|
|
|
JavaScriptExample,
|
|
|
|
CSSExample,
|
|
|
|
ExplicitImportExample,
|
2018-09-02 21:13:57 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2018-09-03 19:55:45 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
|
|
pre {
|
|
|
|
&::before {
|
|
|
|
content: attr(data-language);
|
|
|
|
text-transform: uppercase;
|
|
|
|
display: block;
|
|
|
|
text-align: right;
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: 0.6rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
code {
|
|
|
|
|
|
|
|
.hljs-comment,
|
|
|
|
.hljs-quote {
|
|
|
|
color: #999999;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-variable,
|
|
|
|
.hljs-template-variable,
|
|
|
|
.hljs-attribute,
|
|
|
|
.hljs-tag,
|
|
|
|
.hljs-name,
|
|
|
|
.hljs-regexp,
|
|
|
|
.hljs-link,
|
|
|
|
.hljs-name,
|
|
|
|
.hljs-selector-id,
|
|
|
|
.hljs-selector-class {
|
|
|
|
color: #f2777a;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-number,
|
|
|
|
.hljs-meta,
|
|
|
|
.hljs-built_in,
|
|
|
|
.hljs-builtin-name,
|
|
|
|
.hljs-literal,
|
|
|
|
.hljs-type,
|
|
|
|
.hljs-params {
|
|
|
|
color: #f99157;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-string,
|
|
|
|
.hljs-symbol,
|
|
|
|
.hljs-bullet {
|
|
|
|
color: #99cc99;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-title,
|
|
|
|
.hljs-section {
|
|
|
|
color: #ffcc66;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-keyword,
|
|
|
|
.hljs-selector-tag {
|
|
|
|
color: #6699cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-emphasis {
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hljs-strong {
|
|
|
|
font-weight: 700;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|