manually merge HTMLAttributes
This commit is contained in:
@@ -51,10 +51,7 @@ export default function getSchema(extensions: Extensions): Schema {
|
||||
if (extension.config.renderHTML) {
|
||||
schema.toDOM = node => (extension.config.renderHTML as Function)?.bind(context)({
|
||||
node,
|
||||
HTMLAttributes: mergeAttributes(
|
||||
extension.options.HTMLAttributes,
|
||||
getRenderedAttributes(node, extensionAttributes),
|
||||
),
|
||||
HTMLAttributes: getRenderedAttributes(node, extensionAttributes),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -83,10 +80,7 @@ export default function getSchema(extensions: Extensions): Schema {
|
||||
if (extension.config.renderHTML) {
|
||||
schema.toDOM = mark => (extension.config.renderHTML as Function)?.bind(context)({
|
||||
mark,
|
||||
HTMLAttributes: mergeAttributes(
|
||||
extension.options.HTMLAttributes,
|
||||
getRenderedAttributes(mark, extensionAttributes),
|
||||
),
|
||||
HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
export interface BlockquoteOptions {
|
||||
@@ -29,7 +29,7 @@ const Blockquote = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['blockquote', HTMLAttributes, 0]
|
||||
return ['blockquote', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Mark,
|
||||
markInputRule,
|
||||
markPasteRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface BoldOptions {
|
||||
@@ -40,7 +41,7 @@ const Bold = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['strong', HTMLAttributes, 0]
|
||||
return ['strong', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
export interface BulletListOptions {
|
||||
@@ -27,7 +27,7 @@ const BulletList = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['ul', HTMLAttributes, 0]
|
||||
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -69,7 +69,7 @@ const CodeBlock = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['pre', ['code', HTMLAttributes, 0]]
|
||||
return ['pre', this.options.HTMLAttributes, ['code', HTMLAttributes, 0]]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Mark,
|
||||
markInputRule,
|
||||
markPasteRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface CodeOptions {
|
||||
@@ -30,7 +31,7 @@ const Code = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['code', HTMLAttributes, 0]
|
||||
return ['code', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { Extension } from '@tiptap/core'
|
||||
import {
|
||||
redo, undo, ySyncPlugin, yUndoPlugin,
|
||||
redo,
|
||||
undo,
|
||||
ySyncPlugin,
|
||||
yUndoPlugin,
|
||||
} from 'y-prosemirror'
|
||||
|
||||
export interface CollaborationOptions {
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
||||
import { exitCode } from 'prosemirror-commands'
|
||||
|
||||
export interface HardBreakOptions {
|
||||
HTMLAttributes: {
|
||||
[key: string]: any
|
||||
},
|
||||
}
|
||||
|
||||
const HardBreak = Node.create({
|
||||
name: 'hardBreak',
|
||||
|
||||
defaultOptions: <HardBreakOptions>{
|
||||
languageClassPrefix: 'language-',
|
||||
HTMLAttributes: {},
|
||||
},
|
||||
|
||||
inline: true,
|
||||
|
||||
group: 'inline',
|
||||
@@ -17,7 +28,7 @@ const HardBreak = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['br', HTMLAttributes]
|
||||
return ['br', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
||||
import { textblockTypeInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
type Level = 1 | 2 | 3 | 4 | 5 | 6
|
||||
@@ -47,7 +47,7 @@ const Heading = Node.create({
|
||||
? node.attrs.level
|
||||
: this.options.levels[0]
|
||||
|
||||
return [`h${level}`, HTMLAttributes, 0]
|
||||
return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Mark,
|
||||
markInputRule,
|
||||
markPasteRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface HighlightOptions {
|
||||
@@ -53,7 +54,7 @@ const Highlight = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['mark', HTMLAttributes, 0]
|
||||
return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Command, Node, nodeInputRule } from '@tiptap/core'
|
||||
import {
|
||||
Command,
|
||||
Node,
|
||||
nodeInputRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface HorizontalRuleOptions {
|
||||
HTMLAttributes: {
|
||||
@@ -22,7 +27,7 @@ const HorizontalRule = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['hr', HTMLAttributes]
|
||||
return ['hr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Command, Node, nodeInputRule } from '@tiptap/core'
|
||||
import {
|
||||
Command,
|
||||
Node,
|
||||
nodeInputRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface ImageOptions {
|
||||
inline: boolean,
|
||||
@@ -50,7 +55,7 @@ const Image = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['img', HTMLAttributes]
|
||||
return ['img', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Mark,
|
||||
markInputRule,
|
||||
markPasteRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface ItalicOptions {
|
||||
@@ -39,7 +40,7 @@ const Italic = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['em', HTMLAttributes, 0]
|
||||
return ['em', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { Command, Mark, markPasteRule } from '@tiptap/core'
|
||||
import {
|
||||
Command,
|
||||
Mark,
|
||||
markPasteRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
|
||||
export interface LinkOptions {
|
||||
@@ -42,7 +47,7 @@ const Link = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['a', HTMLAttributes, 0]
|
||||
return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import { Node, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export interface ListItemOptions {
|
||||
HTMLAttributes: {
|
||||
@@ -26,7 +26,7 @@ const ListItem = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['li', HTMLAttributes, 0]
|
||||
return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
||||
import { wrappingInputRule } from 'prosemirror-inputrules'
|
||||
|
||||
export interface OrderedListOptions {
|
||||
@@ -45,8 +45,8 @@ const OrderedList = Node.create({
|
||||
const { start, ...attributesWithoutStart } = HTMLAttributes
|
||||
|
||||
return start === 1
|
||||
? ['ol', attributesWithoutStart, 0]
|
||||
: ['ol', HTMLAttributes, 0]
|
||||
? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]
|
||||
: ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, Node } from '@tiptap/core'
|
||||
import { Command, Node, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export interface ParagraphOptions {
|
||||
HTMLAttributes: {
|
||||
@@ -24,7 +24,7 @@ const Paragraph = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['p', HTMLAttributes, 0]
|
||||
return ['p', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
Mark,
|
||||
markInputRule,
|
||||
markPasteRule,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface StrikeOptions {
|
||||
@@ -39,7 +40,7 @@ const Strike = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['s', HTMLAttributes, 0]
|
||||
return ['s', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -48,7 +48,11 @@ const TaskItem = Node.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['li', mergeAttributes(HTMLAttributes, { 'data-type': 'taskItem' }), 0]
|
||||
return ['li', mergeAttributes(
|
||||
this.options.HTMLAttributes,
|
||||
HTMLAttributes,
|
||||
{ 'data-type': 'taskItem' },
|
||||
), 0]
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
import { Command, Mark, getMarkAttributes } from '@tiptap/core'
|
||||
import {
|
||||
Command,
|
||||
Mark,
|
||||
getMarkAttributes,
|
||||
mergeAttributes,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export interface TextStyleOptions {
|
||||
HTMLAttributes: {
|
||||
[key: string]: any
|
||||
},
|
||||
}
|
||||
|
||||
const TextStyle = Mark.create({
|
||||
name: 'textStyle',
|
||||
|
||||
defaultOptions: <TextStyleOptions>{
|
||||
HTMLAttributes: {},
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
@@ -21,7 +36,7 @@ const TextStyle = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['span', HTMLAttributes, 0]
|
||||
return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Command, Mark } from '@tiptap/core'
|
||||
import { Command, Mark, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export interface UnderlineOptions {
|
||||
HTMLAttributes: {
|
||||
@@ -25,7 +25,7 @@ const Underline = Mark.create({
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['u', HTMLAttributes, 0]
|
||||
return ['u', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
|
||||
Reference in New Issue
Block a user