@@ -74,6 +74,11 @@ function isFunction(param) {
7474 return typeof param === 'function' ;
7575}
7676
77+ function validateLowlight ( lowlight ) {
78+ const requiredMethods = [ 'highlight' , 'highlightAuto' , 'listLanguages' ] ;
79+ return requiredMethods . every ( ( api ) => isFunction ( lowlight [ api ] ) ) ;
80+ }
81+
7782export const CodeInlineLowlight = Extension . create ( {
7883 name : 'codeInlineLowlight' ,
7984
@@ -84,20 +89,18 @@ export const CodeInlineLowlight = Extension.create({
8489 } ,
8590
8691 addProseMirrorPlugins ( ) {
87- if ( ! [ 'highlight' , 'highlightAuto' , 'listLanguages' ] . every ( ( api ) => isFunction ( this . options . lowlight [ api ] ) ) ) {
88- throw Error ( 'You should provide an instance of lowlight to use the @nartix/tiptap-code-inline-highlight extension' ) ;
92+ if ( ! validateLowlight ( this . options . lowlight ) ) {
93+ console . warn (
94+ 'You should provide an instance of lowlight to use the @nartix/tiptap-code-inline-highlight extension. No syntax highlighting is applied.'
95+ ) ;
96+ return [ ] ;
8997 }
9098 const pluginKey = new PluginKey ( this . name ) ;
9199 return [
92100 new Plugin ( {
93101 key : pluginKey ,
94102 state : {
95- init : ( _ , { doc } ) =>
96- getDecorations ( {
97- doc : doc ,
98- name : CODE_MARK_TYPE ,
99- lowlight : this . options . lowlight ,
100- } ) ,
103+ init : ( _ , { doc } ) => getDecorations ( { doc, name : CODE_MARK_TYPE , lowlight : this . options . lowlight } ) ,
101104 apply : ( tr , set , oldState , newState ) => {
102105 const oldMarks = findInlineCode ( oldState . doc , CODE_MARK_TYPE ) ;
103106 const newMarks = findInlineCode ( newState . doc , CODE_MARK_TYPE ) ;
@@ -115,11 +118,7 @@ export const CodeInlineLowlight = Extension.create({
115118 ) ;
116119 } ) )
117120 ) {
118- return getDecorations ( {
119- doc : tr . doc ,
120- name : CODE_MARK_TYPE ,
121- lowlight : this . options . lowlight ,
122- } ) ;
121+ return getDecorations ( { doc : tr . doc , name : CODE_MARK_TYPE , lowlight : this . options . lowlight } ) ;
123122 }
124123 return set . map ( tr . mapping , tr . doc ) ;
125124 } ,
0 commit comments