add highlight option for demos
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="demo__code" v-if="activeFile">
|
<div class="demo__code" v-if="activeFile">
|
||||||
<pre :class="`language-${activeFile.highlight}`"><code :class="`language-${activeFile.highlight}`" v-html="$options.filters.highlight(activeFile.content, activeFile.highlight)"></code></pre>
|
<prism :code="activeFile.content" :language="activeFile.highlight" :highlight="highlight" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -26,10 +26,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import collect from 'collect.js'
|
import collect from 'collect.js'
|
||||||
import ReactRenderer from '~/components/ReactRenderer'
|
import ReactRenderer from '~/components/ReactRenderer'
|
||||||
|
import Prism from '~/components/Prism'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
ReactRenderer,
|
ReactRenderer,
|
||||||
|
Prism,
|
||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
@@ -42,6 +44,11 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'vue',
|
default: 'vue',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
highlight: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
|||||||
53
docs/src/components/Prism/index.vue
Normal file
53
docs/src/components/Prism/index.vue
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<pre :class="`language-${language}`" :data-line="highlight"><code :class="`language-${language}`">{{ code }}</code></pre>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Prism from 'prismjs'
|
||||||
|
import 'prismjs/plugins/line-highlight/prism-line-highlight.js'
|
||||||
|
import 'prismjs/plugins/line-highlight/prism-line-highlight.css'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
language: {
|
||||||
|
default: 'js',
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
code: {
|
||||||
|
default: null,
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
|
||||||
|
highlight: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
highlight() {
|
||||||
|
this.$nextTick(this.highlightCode)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
highlightCode() {
|
||||||
|
|
||||||
|
Prism.highlightAllUnder(this.$el)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.highlightCode()
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
console.log('JOOOO')
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -7,12 +7,10 @@
|
|||||||
<script>
|
<script>
|
||||||
import { Editor } from '@tiptap/core'
|
import { Editor } from '@tiptap/core'
|
||||||
import { EditorContent, Renderer } from '@tiptap/vue'
|
import { EditorContent, Renderer } from '@tiptap/vue'
|
||||||
// <- Highlight --> //
|
|
||||||
import Document from '@tiptap/extension-document'
|
import Document from '@tiptap/extension-document'
|
||||||
import Paragraph from '@tiptap/extension-paragraph'
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
import Text from '@tiptap/extension-text'
|
import Text from '@tiptap/extension-text'
|
||||||
import Bold from '@tiptap/extension-bold'
|
import Bold from '@tiptap/extension-bold'
|
||||||
// <- /Highlight --> //
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -29,12 +27,10 @@ export default {
|
|||||||
this.editor = new Editor({
|
this.editor = new Editor({
|
||||||
content: '<p>I’m running tiptap with Vue.js. This demo is interactive, try to edit the text.</p>',
|
content: '<p>I’m running tiptap with Vue.js. This demo is interactive, try to edit the text.</p>',
|
||||||
extensions: [
|
extensions: [
|
||||||
// <- Highlight --> //
|
|
||||||
new Document(),
|
new Document(),
|
||||||
new Paragraph(),
|
new Paragraph(),
|
||||||
new Text(),
|
new Text(),
|
||||||
new Bold(),
|
new Bold(),
|
||||||
// <- /Highlight --> //
|
|
||||||
],
|
],
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<div class="editor">
|
<div class="editor">
|
||||||
<div class="menubar" v-if="editor">
|
<div class="menubar" v-if="editor">
|
||||||
|
|
||||||
<!-- Highlight -->
|
|
||||||
<button
|
<button
|
||||||
class="menubar__button"
|
class="menubar__button"
|
||||||
:class="{ 'is-active': editor.isActive('bold') }"
|
:class="{ 'is-active': editor.isActive('bold') }"
|
||||||
@@ -10,7 +9,6 @@
|
|||||||
>
|
>
|
||||||
Bold
|
Bold
|
||||||
</button>
|
</button>
|
||||||
<!-- /Highlight -->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ In its basic version tiptap comes very raw. There is no menu, no buttons, no sty
|
|||||||
|
|
||||||
Let’s start to add your first button to the editor.
|
Let’s start to add your first button to the editor.
|
||||||
|
|
||||||
<demo name="SimpleMenuBar" />
|
<demo name="SimpleMenuBar" highlight="5-11" />
|
||||||
|
|
||||||
Once initiated the editor has a powerful API. So called commands allow you to modify the text. In this example `this.editor.commands.bold` marks the selected text bold. There a ton of other commands (see the [list of available commands](/commands/)) and you can even chain them to do multiple things at once.
|
Once initiated the editor has a powerful API. So called commands allow you to modify the text. In this example `this.editor.commands.bold` marks the selected text bold. There a ton of other commands (see the [list of available commands](/commands/)) and you can even chain them to do multiple things at once.
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ You are free to choose which parts of tiptap you want to use. Tiptap has support
|
|||||||
|
|
||||||
Note that `Document`, `Paragraph` and `Text` are required. Otherwise you won’t be able to add any plain text.
|
Note that `Document`, `Paragraph` and `Text` are required. Otherwise you won’t be able to add any plain text.
|
||||||
|
|
||||||
<demo name="ExtensionConfiguration" />
|
<demo name="ExtensionConfiguration" highlight="10-13,30-33" />
|
||||||
|
|
||||||
That’s also the place where you can register custom extensions, which you or someone else built for tiptap.
|
That’s also the place where you can register custom extensions, which you or someone else built for tiptap.
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ code {
|
|||||||
padding: 0.1rem 0.3rem;
|
padding: 0.1rem 0.3rem;
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
color: rgba($colorBlack, 0.7);
|
color: rgba($colorBlack, 0.7);
|
||||||
font-size: 0.9em;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.is-active {
|
.is-active {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pre[class*="language-"] {
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
text-shadow: none;
|
text-shadow: none;
|
||||||
font-family: 'JetBrainsMono', monospace;
|
font-family: 'JetBrainsMono', monospace;
|
||||||
font-size: 0.95em;
|
font-size: 0.9rem;
|
||||||
line-height: 1.8;
|
line-height: 1.8;
|
||||||
tab-size: 2;
|
tab-size: 2;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -43,7 +43,7 @@ pre[class*="language-"] {
|
|||||||
position: relative;
|
position: relative;
|
||||||
color: $codeText;
|
color: $codeText;
|
||||||
background: $codeBackground;
|
background: $codeBackground;
|
||||||
padding: 1.2rem 1.5rem;
|
padding: 1.2rem 1.5rem !important;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,3 +202,13 @@ pre[class*="language-"].language-scss > code {
|
|||||||
.token.variable {
|
.token.variable {
|
||||||
color: $codeRed;
|
color: $codeRed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.line-highlight {
|
||||||
|
background: rgba($colorWhite, 0.1) !important;
|
||||||
|
padding: 0 0 0.3rem 0;
|
||||||
|
|
||||||
|
&::before,
|
||||||
|
&::after {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,4 @@ export default function (Vue, { router, head, isClient }) {
|
|||||||
Vue.component('Demo', Demo)
|
Vue.component('Demo', Demo)
|
||||||
Vue.component('Tab', Tab)
|
Vue.component('Tab', Tab)
|
||||||
Vue.component('ReactRenderer', ReactRenderer)
|
Vue.component('ReactRenderer', ReactRenderer)
|
||||||
Vue.filter('highlight', (code, lang = 'javascript') => {
|
|
||||||
return Prism.highlight(code, Prism.languages[lang], lang)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user