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