@@ -126,7 +126,10 @@ const CodeBlockContent = createStronglyTypedTiptapNode({
126
126
return null ;
127
127
}
128
128
129
- return getLanguageId ( options . editor . settings . codeBlock , language ) ;
129
+ return (
130
+ getLanguageId ( options . editor . settings . codeBlock , language ) ??
131
+ language
132
+ ) ;
130
133
} ,
131
134
renderHTML : ( attributes ) => {
132
135
return attributes . language
@@ -251,7 +254,7 @@ const CodeBlockContent = createStronglyTypedTiptapNode({
251
254
if ( process . env . NODE_ENV === "development" && ! hasWarned ) {
252
255
// eslint-disable-next-line no-console
253
256
console . log (
254
- "For syntax highlighting of code blocks, you must provide a highlighter function"
257
+ "For syntax highlighting of code blocks, you must provide a `codeBlock.createHighlighter` function"
255
258
) ;
256
259
hasWarned = true ;
257
260
}
@@ -268,15 +271,22 @@ const CodeBlockContent = createStronglyTypedTiptapNode({
268
271
}
269
272
) ;
270
273
}
271
-
272
- const language = parserOptions . language ;
274
+ const language = getLanguageId (
275
+ options . editor . settings . codeBlock ,
276
+ parserOptions . language !
277
+ ) ;
273
278
274
279
if (
275
- language &&
276
- language !== "text" &&
277
- ! highlighter . getLoadedLanguages ( ) . includes ( language ) &&
278
- language in options . editor . settings . codeBlock . supportedLanguages
280
+ ! language ||
281
+ language === "text" ||
282
+ language === "none" ||
283
+ language === "plaintext" ||
284
+ language === "txt"
279
285
) {
286
+ return [ ] ;
287
+ }
288
+
289
+ if ( ! highlighter . getLoadedLanguages ( ) . includes ( language ) ) {
280
290
return highlighter . loadLanguage ( language ) ;
281
291
}
282
292
@@ -308,10 +318,9 @@ const CodeBlockContent = createStronglyTypedTiptapNode({
308
318
const $start = state . doc . resolve ( range . from ) ;
309
319
const languageName = match [ 1 ] . trim ( ) ;
310
320
const attributes = {
311
- language : getLanguageId (
312
- options . editor . settings . codeBlock ,
313
- languageName
314
- ) ,
321
+ language :
322
+ getLanguageId ( options . editor . settings . codeBlock , languageName ) ??
323
+ languageName ,
315
324
} ;
316
325
317
326
if (
@@ -422,10 +431,13 @@ export const CodeBlock = createBlockSpecFromStronglyTypedTiptapNode(
422
431
defaultCodeBlockPropSchema
423
432
) ;
424
433
425
- function getLanguageId ( options : CodeBlockOptions , languageName : string ) {
426
- return (
427
- Object . entries ( options . supportedLanguages ) . find ( ( [ id , { aliases } ] ) => {
434
+ function getLanguageId (
435
+ options : CodeBlockOptions ,
436
+ languageName : string
437
+ ) : string | undefined {
438
+ return Object . entries ( options . supportedLanguages ) . find (
439
+ ( [ id , { aliases } ] ) => {
428
440
return aliases ?. includes ( languageName ) || id === languageName ;
429
- } ) ?. [ 0 ] || languageName
430
- ) ;
441
+ }
442
+ ) ?. [ 0 ] ;
431
443
}
0 commit comments