remove languages option from codeblocklowlight
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<node-view-wrapper class="code-block">
|
<node-view-wrapper class="code-block">
|
||||||
<select contenteditable="false" class="code-block-select" v-model="selectedLanguage">
|
<select contenteditable="false" v-model="selectedLanguage">
|
||||||
<option v-for="(language, index) in languages" :value="language" :key="index">
|
|
||||||
{{ language }}
|
|
||||||
</option>
|
|
||||||
<option :value="null">
|
<option :value="null">
|
||||||
auto
|
auto
|
||||||
</option>
|
</option>
|
||||||
|
<option disabled>
|
||||||
|
—
|
||||||
|
</option>
|
||||||
|
<option v-for="(language, index) in languages" :value="language" :key="index">
|
||||||
|
{{ language }}
|
||||||
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<pre><node-view-content as="code" /></pre>
|
<pre><node-view-content as="code" /></pre>
|
||||||
</node-view-wrapper>
|
</node-view-wrapper>
|
||||||
@@ -14,6 +17,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { NodeViewWrapper, NodeViewContent, nodeViewProps } from '@tiptap/vue-2'
|
import { NodeViewWrapper, NodeViewContent, nodeViewProps } from '@tiptap/vue-2'
|
||||||
|
import lowlight from 'lowlight/lib/core'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -23,6 +27,12 @@ export default {
|
|||||||
|
|
||||||
props: nodeViewProps,
|
props: nodeViewProps,
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
languages: lowlight.listLanguages(),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
selectedLanguage: {
|
selectedLanguage: {
|
||||||
get() {
|
get() {
|
||||||
@@ -30,26 +40,20 @@ export default {
|
|||||||
},
|
},
|
||||||
set(language) {
|
set(language) {
|
||||||
this.updateAttributes({ language })
|
this.updateAttributes({ language })
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
languages: ['js', 'css'],
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style lang="scss" scoped>
|
||||||
.code-block {
|
.code-block {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
|
||||||
|
|
||||||
.code-block-select {
|
select {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0.5rem;
|
top: 0.5rem;
|
||||||
right: 0.5rem;
|
right: 0.5rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -14,11 +14,10 @@ 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 CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
|
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
|
||||||
|
import CodeBlockComponent from './CodeBlockComponent'
|
||||||
|
|
||||||
import javascript from 'highlight.js/lib/languages/javascript'
|
// install all highlight.js languages
|
||||||
import css from 'highlight.js/lib/languages/css'
|
import 'lowlight'
|
||||||
|
|
||||||
import CodeBlock from './CodeBlock'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -37,16 +36,9 @@ export default {
|
|||||||
Document,
|
Document,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
Text,
|
Text,
|
||||||
CodeBlockLowlight
|
CodeBlockLowlight.extend({
|
||||||
.extend({
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
return VueNodeViewRenderer(CodeBlock)
|
return VueNodeViewRenderer(CodeBlockComponent)
|
||||||
},
|
|
||||||
})
|
|
||||||
.configure({
|
|
||||||
languages: {
|
|
||||||
javascript,
|
|
||||||
css,
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import Paragraph from '@tiptap/extension-paragraph'
|
|||||||
import Text from '@tiptap/extension-text'
|
import Text from '@tiptap/extension-text'
|
||||||
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
|
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
|
||||||
|
|
||||||
import javascript from 'highlight.js/lib/languages/javascript'
|
// install all highlight.js languages
|
||||||
import css from 'highlight.js/lib/languages/css'
|
import 'lowlight'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -35,12 +35,7 @@ export default {
|
|||||||
Document,
|
Document,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
Text,
|
Text,
|
||||||
CodeBlockLowlight.configure({
|
CodeBlockLowlight,
|
||||||
languages: {
|
|
||||||
javascript,
|
|
||||||
css,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -1,27 +1,7 @@
|
|||||||
import CodeBlock, { CodeBlockOptions } from '@tiptap/extension-code-block'
|
import CodeBlock from '@tiptap/extension-code-block'
|
||||||
import lowlight from 'lowlight/lib/core'
|
|
||||||
import { LowlightPlugin } from './lowlight-plugin'
|
import { LowlightPlugin } from './lowlight-plugin'
|
||||||
|
|
||||||
export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
export const CodeBlockLowlight = CodeBlock.extend({
|
||||||
languages: {
|
|
||||||
[key: string]: Function,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|
||||||
defaultOptions: {
|
|
||||||
...CodeBlock.config.defaultOptions,
|
|
||||||
languages: {},
|
|
||||||
},
|
|
||||||
|
|
||||||
onBeforeCreate() {
|
|
||||||
Object
|
|
||||||
.entries(this.options.languages)
|
|
||||||
.forEach(([name, mapping]) => {
|
|
||||||
lowlight.registerLanguage(name, mapping)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
return [
|
return [
|
||||||
LowlightPlugin({ name: 'codeBlock' }),
|
LowlightPlugin({ name: 'codeBlock' }),
|
||||||
|
|||||||
Reference in New Issue
Block a user