mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-08 01:53:04 +08:00
fix(code-block): respect defaultLanguage
on code-block-lowlight add option to code-block
(#5406)
This commit is contained in:
parent
174aefe0f1
commit
4b215f794e
6
.changeset/good-schools-pretend.md
Normal file
6
.changeset/good-schools-pretend.md
Normal file
@ -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.
|
@ -7,13 +7,6 @@ export interface CodeBlockLowlightOptions extends CodeBlockOptions {
|
|||||||
* The lowlight instance.
|
* The lowlight instance.
|
||||||
*/
|
*/
|
||||||
lowlight: any,
|
lowlight: any,
|
||||||
|
|
||||||
/**
|
|
||||||
* The default language.
|
|
||||||
* @default null
|
|
||||||
* @example 'javascript'
|
|
||||||
*/
|
|
||||||
defaultLanguage: string | null | undefined,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,7 +18,6 @@ export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
|||||||
return {
|
return {
|
||||||
...this.parent?.(),
|
...this.parent?.(),
|
||||||
lowlight: {},
|
lowlight: {},
|
||||||
defaultLanguage: null,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -22,6 +22,12 @@ export interface CodeBlockOptions {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
exitOnArrowDown: boolean
|
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.
|
* Custom HTML attributes that should be added to the rendered HTML tag.
|
||||||
* @default {}
|
* @default {}
|
||||||
@ -71,6 +77,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
|
|||||||
languageClassPrefix: 'language-',
|
languageClassPrefix: 'language-',
|
||||||
exitOnTripleEnter: true,
|
exitOnTripleEnter: true,
|
||||||
exitOnArrowDown: true,
|
exitOnArrowDown: true,
|
||||||
|
defaultLanguage: null,
|
||||||
HTMLAttributes: {},
|
HTMLAttributes: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -88,7 +95,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
|
|||||||
addAttributes() {
|
addAttributes() {
|
||||||
return {
|
return {
|
||||||
language: {
|
language: {
|
||||||
default: null,
|
default: this.options.defaultLanguage,
|
||||||
parseHTML: element => {
|
parseHTML: element => {
|
||||||
const { languageClassPrefix } = this.options
|
const { languageClassPrefix } = this.options
|
||||||
const classNames = [...(element.firstElementChild?.classList || [])]
|
const classNames = [...(element.firstElementChild?.classList || [])]
|
||||||
|
Loading…
Reference in New Issue
Block a user