Skip to content

Commit 6e18d67

Browse files
committed
changed error to graceful error
1 parent d3bd5a5 commit 6e18d67

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nartix/tiptap-inline-code-highlight",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"description": "Inline code highlight extension for Tiptap editor.",
55
"main": "src/index.js",
66
"scripts": {

src/code-inline-lowlight.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
7782
export 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

Comments
 (0)