mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
fix: parse correct language for code blocks with multiple classes (see #1845)
This commit is contained in:
parent
99ea9c87da
commit
472f2139c5
@ -47,16 +47,19 @@ export const CodeBlock = Node.create<CodeBlockOptions>({
|
||||
language: {
|
||||
default: null,
|
||||
parseHTML: element => {
|
||||
const classAttribute = element.firstElementChild?.getAttribute('class')
|
||||
const { languageClassPrefix } = this.options
|
||||
const classNames = [...element.firstElementChild?.classList || []]
|
||||
const languages = classNames
|
||||
.filter(className => className.startsWith(languageClassPrefix))
|
||||
.map(className => className.replace(languageClassPrefix, ''))
|
||||
const language = languages[0]
|
||||
|
||||
if (!classAttribute) {
|
||||
if (!language) {
|
||||
return null
|
||||
}
|
||||
|
||||
const regexLanguageClassPrefix = new RegExp(`^(${this.options.languageClassPrefix})`)
|
||||
|
||||
return {
|
||||
language: classAttribute.replace(regexLanguageClassPrefix, ''),
|
||||
language,
|
||||
}
|
||||
},
|
||||
renderHTML: attributes => {
|
||||
|
Loading…
Reference in New Issue
Block a user