Declare lowlight as a peerDependency (#2625)
Declare lowlight as a peerDependency to delegate the control of which version of lowlight is used to the client application Co-authored-by: Enrique Alcantara <ealcantara@gitlab.com>
This commit is contained in:
committed by
GitHub
parent
fd593bb93e
commit
39f5e4c31e
@@ -21,12 +21,12 @@
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@tiptap/core": "^2.0.0-beta.1"
|
||||
"@tiptap/core": "^2.0.0-beta.1",
|
||||
"lowlight": ">=1.20.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tiptap/extension-code-block": "^2.0.0-beta.37",
|
||||
"@types/lowlight": "^0.0.3",
|
||||
"lowlight": "^1.20.0",
|
||||
"prosemirror-model": "^1.16.1",
|
||||
"prosemirror-state": "^1.3.4",
|
||||
"prosemirror-view": "^1.23.6"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import lowlight from 'lowlight/lib/core'
|
||||
import CodeBlock, { CodeBlockOptions } from '@tiptap/extension-code-block'
|
||||
import { LowlightPlugin } from './lowlight-plugin'
|
||||
|
||||
@@ -11,7 +10,7 @@ export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
||||
addOptions() {
|
||||
return {
|
||||
...this.parent?.(),
|
||||
lowlight,
|
||||
lowlight: {},
|
||||
defaultLanguage: null,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -65,7 +65,15 @@ function getDecorations({
|
||||
return DecorationSet.create(doc, decorations)
|
||||
}
|
||||
|
||||
function isFunction(param: Function) {
|
||||
return typeof param === 'function'
|
||||
}
|
||||
|
||||
export function LowlightPlugin({ name, lowlight, defaultLanguage }: { name: string, lowlight: any, defaultLanguage: string | null | undefined }) {
|
||||
if (!['highlight', 'highlightAuto', 'listLanguages'].every(api => isFunction(lowlight[api]))) {
|
||||
throw Error('You should provide an instance of lowlight to use the code-block-lowlight extension')
|
||||
}
|
||||
|
||||
return new Plugin({
|
||||
key: new PluginKey('lowlight'),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user