add basic lowlight extension

This commit is contained in:
Philipp Kühn
2021-04-02 00:07:40 +02:00
parent 4d882af5d7
commit 7adf1853d7
16 changed files with 476 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import CodeBlock from '@tiptap/extension-code-block'
import low from 'lowlight/lib/core'
import { LowlightPlugin } from './lowlight-plugin'
export interface CodeBlockLowlightOptions {
languageClassPrefix: string,
HTMLAttributes: {
[key: string]: any
},
languages: {
[key: string]: Function
},
}
export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
name: 'codeBlockLowlight',
defaultOptions: {
languageClassPrefix: 'language-',
HTMLAttributes: {},
languages: {},
},
onBeforeCreate() {
Object.entries(this.options.languages).forEach(([name, mapping]) => {
low.registerLanguage(name, mapping)
})
},
addProseMirrorPlugins() {
return [
LowlightPlugin({ name: 'codeBlockLowlight' }),
]
},
})