mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +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.
|
||||
*/
|
||||
lowlight: any,
|
||||
|
||||
/**
|
||||
* The default language.
|
||||
* @default null
|
||||
* @example 'javascript'
|
||||
*/
|
||||
defaultLanguage: string | null | undefined,
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,7 +18,6 @@ export const CodeBlockLowlight = CodeBlock.extend<CodeBlockLowlightOptions>({
|
||||
return {
|
||||
...this.parent?.(),
|
||||
lowlight: {},
|
||||
defaultLanguage: null,
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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 {}
|
||||
@ -71,6 +77,7 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
|
||||
languageClassPrefix: 'language-',
|
||||
exitOnTripleEnter: true,
|
||||
exitOnArrowDown: true,
|
||||
defaultLanguage: null,
|
||||
HTMLAttributes: {},
|
||||
}
|
||||
},
|
||||
@ -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 || [])]
|
||||
|
Loading…
Reference in New Issue
Block a user