Skip to content

Commit

Permalink
fix(code-block): respect defaultLanguage on code-block-lowlight add…
Browse files Browse the repository at this point in the history
… option to `code-block` (#5406)
  • Loading branch information
nperez0111 authored Aug 6, 2024
1 parent 174aefe commit 4b215f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/good-schools-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tiptap/extension-code-block": minor
"@tiptap/extension-code-block-lowlight": patch
---

`defaultLanguage` on Code Block Lowlight was not being respected properly, to address this we added `defaultLanguage` as an option to the code-block extension.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ export interface CodeBlockLowlightOptions extends CodeBlockOptions {
* The lowlight instance.
*/
lowlight: any,

/**
* The default language.
* @default null
* @example 'javascript'
*/
defaultLanguage: string | null | undefined,
}

/**
Expand All @@ -25,7 +18,6 @@ export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
return {
...this.parent?.(),
lowlight: {},
defaultLanguage: null,
}
},

Expand Down
9 changes: 8 additions & 1 deletion packages/extension-code-block/src/code-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export interface CodeBlockOptions {
* @default true
*/
exitOnArrowDown: boolean
/**
* The default language.
* @default null
* @example 'js'
*/
defaultLanguage: string | null | undefined
/**
* Custom HTML attributes that should be added to the rendered HTML tag.
* @default {}
Expand Down Expand Up @@ -71,6 +77,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
languageClassPrefix: 'language-',
exitOnTripleEnter: true,
exitOnArrowDown: true,
defaultLanguage: null,
HTMLAttributes: {},
}
},
Expand All @@ -88,7 +95,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
addAttributes() {
return {
language: {
default: null,
default: this.options.defaultLanguage,
parseHTML: element => {
const { languageClassPrefix } = this.options
const classNames = [...(element.firstElementChild?.classList || [])]
Expand Down

0 comments on commit 4b215f7

Please sign in to comment.