From c840a562defc5aad039a524fa81adfa25cfc7e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 13 Nov 2020 16:07:20 +0100 Subject: [PATCH 01/16] rename attributes to HTMLAttributes --- packages/core/src/ExtensionManager.ts | 4 ++-- packages/core/src/MarkExtension.ts | 2 +- packages/core/src/NodeExtension.ts | 2 +- packages/core/src/types.ts | 2 +- packages/core/src/utils/getSchema.ts | 4 ++-- packages/extension-blockquote/src/index.ts | 4 ++-- packages/extension-bold/src/index.ts | 4 ++-- packages/extension-bullet-list/src/index.ts | 4 ++-- packages/extension-code-block/src/index.ts | 4 ++-- packages/extension-code/src/index.ts | 4 ++-- packages/extension-hard-break/src/index.ts | 4 ++-- packages/extension-heading/src/index.ts | 8 ++++++-- packages/extension-highlight/src/index.ts | 4 ++-- packages/extension-horizontal-rule/src/index.ts | 4 ++-- packages/extension-image/src/index.ts | 4 ++-- packages/extension-italic/src/index.ts | 4 ++-- packages/extension-link/src/index.ts | 4 ++-- packages/extension-list-item/src/index.ts | 4 ++-- packages/extension-ordered-list/src/index.ts | 6 +++--- packages/extension-paragraph/src/index.ts | 4 ++-- packages/extension-strike/src/index.ts | 4 ++-- packages/extension-task-item/src/index.ts | 10 +++++----- packages/extension-task-list/src/index.ts | 4 ++-- packages/extension-text-style/src/index.ts | 4 ++-- packages/extension-underline/src/index.ts | 4 ++-- 25 files changed, 55 insertions(+), 51 deletions(-) diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 80ec7e71..5c6ea347 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -122,14 +122,14 @@ export default class ExtensionManager { getPos: (() => number) | boolean, decorations: Decoration[], ) => { - const attributes = getRenderedAttributes(node, extensionAttributes) + const HTMLAttributes = getRenderedAttributes(node, extensionAttributes) return renderer({ editor, node, getPos, decorations, - attributes, + HTMLAttributes, }) } diff --git a/packages/core/src/MarkExtension.ts b/packages/core/src/MarkExtension.ts index da1d1f41..36c46bfa 100644 --- a/packages/core/src/MarkExtension.ts +++ b/packages/core/src/MarkExtension.ts @@ -45,7 +45,7 @@ export interface MarkExtensionSpec extends Overwrit }, props: { mark: Mark, - attributes: { [key: string]: any }, + HTMLAttributes: { [key: string]: any }, } ) => DOMOutputSpec) | null, diff --git a/packages/core/src/NodeExtension.ts b/packages/core/src/NodeExtension.ts index d7401cd1..73c1d90a 100644 --- a/packages/core/src/NodeExtension.ts +++ b/packages/core/src/NodeExtension.ts @@ -80,7 +80,7 @@ export interface NodeExtensionSpec extends Overwrit }, props: { node: Node, - attributes: { [key: string]: any }, + HTMLAttributes: { [key: string]: any }, } ) => DOMOutputSpec) | null, diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index ff8fcea2..fd0065f0 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -49,7 +49,7 @@ export type NodeViewRendererProps = { node: Node, getPos: (() => number) | boolean, decorations: Decoration[], - attributes: AnyObject, + HTMLAttributes: { [key: string]: any }, } export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView diff --git a/packages/core/src/utils/getSchema.ts b/packages/core/src/utils/getSchema.ts index 1a191f50..72d3db62 100644 --- a/packages/core/src/utils/getSchema.ts +++ b/packages/core/src/utils/getSchema.ts @@ -50,7 +50,7 @@ export default function getSchema(extensions: Extensions): Schema { if (extension.renderHTML) { schema.toDOM = node => (extension.renderHTML as Function)?.bind(context)({ node, - attributes: getRenderedAttributes(node, extensionAttributes), + HTMLAttributes: getRenderedAttributes(node, extensionAttributes), }) } @@ -79,7 +79,7 @@ export default function getSchema(extensions: Extensions): Schema { if (extension.renderHTML) { schema.toDOM = mark => (extension.renderHTML as Function)?.bind(context)({ mark, - attributes: getRenderedAttributes(mark, extensionAttributes), + HTMLAttributes: getRenderedAttributes(mark, extensionAttributes), }) } diff --git a/packages/extension-blockquote/src/index.ts b/packages/extension-blockquote/src/index.ts index f4995c35..5df5ae47 100644 --- a/packages/extension-blockquote/src/index.ts +++ b/packages/extension-blockquote/src/index.ts @@ -18,8 +18,8 @@ const Blockquote = createNode({ ] }, - renderHTML({ attributes }) { - return ['blockquote', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['blockquote', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-bold/src/index.ts b/packages/extension-bold/src/index.ts index 4b649d4d..ee37ebb4 100644 --- a/packages/extension-bold/src/index.ts +++ b/packages/extension-bold/src/index.ts @@ -26,8 +26,8 @@ const Bold = createMark({ ] }, - renderHTML({ attributes }) { - return ['strong', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['strong', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-bullet-list/src/index.ts b/packages/extension-bullet-list/src/index.ts index cc1c1990..49b6f292 100644 --- a/packages/extension-bullet-list/src/index.ts +++ b/packages/extension-bullet-list/src/index.ts @@ -16,8 +16,8 @@ const BulletList = createNode({ ] }, - renderHTML({ attributes }) { - return ['ul', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['ul', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-code-block/src/index.ts b/packages/extension-code-block/src/index.ts index 5fa068ec..d8203b5a 100644 --- a/packages/extension-code-block/src/index.ts +++ b/packages/extension-code-block/src/index.ts @@ -64,8 +64,8 @@ const CodeBlock = createNode({ ] }, - renderHTML({ attributes }) { - return ['pre', ['code', attributes, 0]] + renderHTML({ HTMLAttributes }) { + return ['pre', ['code', HTMLAttributes, 0]] }, addCommands() { diff --git a/packages/extension-code/src/index.ts b/packages/extension-code/src/index.ts index 30679ee1..7b68e0d6 100644 --- a/packages/extension-code/src/index.ts +++ b/packages/extension-code/src/index.ts @@ -16,8 +16,8 @@ const Code = createMark({ ] }, - renderHTML({ attributes }) { - return ['code', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['code', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-hard-break/src/index.ts b/packages/extension-hard-break/src/index.ts index 95b92ca6..be300ba9 100644 --- a/packages/extension-hard-break/src/index.ts +++ b/packages/extension-hard-break/src/index.ts @@ -16,8 +16,8 @@ const HardBreak = createNode({ ] }, - renderHTML({ attributes }) { - return ['br', attributes] + renderHTML({ HTMLAttributes }) { + return ['br', HTMLAttributes] }, addCommands() { diff --git a/packages/extension-heading/src/index.ts b/packages/extension-heading/src/index.ts index d5053f7c..2cef9f7c 100644 --- a/packages/extension-heading/src/index.ts +++ b/packages/extension-heading/src/index.ts @@ -5,6 +5,9 @@ type Level = 1 | 2 | 3 | 4 | 5 | 6 export interface HeadingOptions { levels: Level[], + HTMLAttributes: { + [key: string]: any + }, } const Heading = createNode({ @@ -12,6 +15,7 @@ const Heading = createNode({ defaultOptions: { levels: [1, 2, 3, 4, 5, 6], + HTMLAttributes: {}, }, content: 'inline*', @@ -37,13 +41,13 @@ const Heading = createNode({ })) }, - renderHTML({ node, attributes }) { + renderHTML({ node, HTMLAttributes }) { const hasLevel = this.options.levels.includes(node.attrs.level) const level = hasLevel ? node.attrs.level : this.options.levels[0] - return [`h${level}`, attributes, 0] + return [`h${level}`, HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-highlight/src/index.ts b/packages/extension-highlight/src/index.ts index fac55d1f..44586cce 100644 --- a/packages/extension-highlight/src/index.ts +++ b/packages/extension-highlight/src/index.ts @@ -42,8 +42,8 @@ const Highlight = createMark({ ] }, - renderHTML({ attributes }) { - return ['mark', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['mark', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-horizontal-rule/src/index.ts b/packages/extension-horizontal-rule/src/index.ts index a4dd2ca1..d0babb66 100644 --- a/packages/extension-horizontal-rule/src/index.ts +++ b/packages/extension-horizontal-rule/src/index.ts @@ -11,8 +11,8 @@ const HorizontalRule = createNode({ ] }, - renderHTML({ attributes }) { - return ['hr', attributes] + renderHTML({ HTMLAttributes }) { + return ['hr', HTMLAttributes] }, addCommands() { diff --git a/packages/extension-image/src/index.ts b/packages/extension-image/src/index.ts index 09ee1318..1957cddb 100644 --- a/packages/extension-image/src/index.ts +++ b/packages/extension-image/src/index.ts @@ -45,8 +45,8 @@ const Image = createNode({ ] }, - renderHTML({ attributes }) { - return ['img', attributes] + renderHTML({ HTMLAttributes }) { + return ['img', HTMLAttributes] }, addCommands() { diff --git a/packages/extension-italic/src/index.ts b/packages/extension-italic/src/index.ts index 772a5cba..ad5a6390 100644 --- a/packages/extension-italic/src/index.ts +++ b/packages/extension-italic/src/index.ts @@ -25,8 +25,8 @@ const Italic = createMark({ ] }, - renderHTML({ attributes }) { - return ['em', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['em', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-link/src/index.ts b/packages/extension-link/src/index.ts index 16c81d95..70334a1c 100644 --- a/packages/extension-link/src/index.ts +++ b/packages/extension-link/src/index.ts @@ -39,8 +39,8 @@ const Link = createMark({ ] }, - renderHTML({ attributes }) { - return ['a', mergeAttributes(attributes, { rel: this.options.rel }), 0] + renderHTML({ HTMLAttributes }) { + return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.rel }), 0] }, addCommands() { diff --git a/packages/extension-list-item/src/index.ts b/packages/extension-list-item/src/index.ts index f75f5d80..8e3c05bd 100644 --- a/packages/extension-list-item/src/index.ts +++ b/packages/extension-list-item/src/index.ts @@ -15,8 +15,8 @@ const ListItem = createNode({ ] }, - renderHTML({ attributes }) { - return ['li', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['li', HTMLAttributes, 0] }, addKeyboardShortcuts() { diff --git a/packages/extension-ordered-list/src/index.ts b/packages/extension-ordered-list/src/index.ts index 10ccfd59..11da5dd6 100644 --- a/packages/extension-ordered-list/src/index.ts +++ b/packages/extension-ordered-list/src/index.ts @@ -31,12 +31,12 @@ const OrderedList = createNode({ ] }, - renderHTML({ attributes }) { - const { start, ...attributesWithoutStart } = attributes + renderHTML({ HTMLAttributes }) { + const { start, ...attributesWithoutStart } = HTMLAttributes return start === 1 ? ['ol', attributesWithoutStart, 0] - : ['ol', attributes, 0] + : ['ol', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-paragraph/src/index.ts b/packages/extension-paragraph/src/index.ts index 6f7c24d8..246d1ac2 100644 --- a/packages/extension-paragraph/src/index.ts +++ b/packages/extension-paragraph/src/index.ts @@ -14,8 +14,8 @@ const Paragraph = createNode({ ] }, - renderHTML({ attributes }) { - return ['p', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['p', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-strike/src/index.ts b/packages/extension-strike/src/index.ts index 1775b457..8856ba6e 100644 --- a/packages/extension-strike/src/index.ts +++ b/packages/extension-strike/src/index.ts @@ -25,8 +25,8 @@ const Strike = createMark({ ] }, - renderHTML({ attributes }) { - return ['s', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['s', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-task-item/src/index.ts b/packages/extension-task-item/src/index.ts index a30c25ea..9f3eeb37 100644 --- a/packages/extension-task-item/src/index.ts +++ b/packages/extension-task-item/src/index.ts @@ -43,8 +43,8 @@ const TaskItem = createNode({ ] }, - renderHTML({ attributes }) { - return ['li', mergeAttributes(attributes, { 'data-type': 'taskItem' }), 0] + renderHTML({ HTMLAttributes }) { + return ['li', mergeAttributes(HTMLAttributes, { 'data-type': 'taskItem' }), 0] }, addKeyboardShortcuts() { @@ -64,7 +64,7 @@ const TaskItem = createNode({ }, addNodeView() { - return ({ attributes, getPos, editor }) => { + return ({ HTMLAttributes, getPos, editor }) => { const { view } = editor const listItem = document.createElement('li') const checkbox = document.createElement('input') @@ -82,13 +82,13 @@ const TaskItem = createNode({ } }) - if (attributes['data-checked'] === true) { + if (HTMLAttributes['data-checked'] === true) { checkbox.setAttribute('checked', 'checked') } listItem.append(checkbox, content) - Object.entries(attributes).forEach(([key, value]) => { + Object.entries(HTMLAttributes).forEach(([key, value]) => { listItem.setAttribute(key, value) }) diff --git a/packages/extension-task-list/src/index.ts b/packages/extension-task-list/src/index.ts index 7f3173d3..862578b2 100644 --- a/packages/extension-task-list/src/index.ts +++ b/packages/extension-task-list/src/index.ts @@ -16,8 +16,8 @@ const TaskList = createNode({ ] }, - renderHTML({ attributes }) { - return ['ul', mergeAttributes(attributes, { 'data-type': 'taskList' }), 0] + renderHTML({ HTMLAttributes }) { + return ['ul', mergeAttributes(HTMLAttributes, { 'data-type': 'taskList' }), 0] }, addCommands() { diff --git a/packages/extension-text-style/src/index.ts b/packages/extension-text-style/src/index.ts index 73f35981..1eead702 100644 --- a/packages/extension-text-style/src/index.ts +++ b/packages/extension-text-style/src/index.ts @@ -20,8 +20,8 @@ const TextStyle = createMark({ ] }, - renderHTML({ attributes }) { - return ['span', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['span', HTMLAttributes, 0] }, addCommands() { diff --git a/packages/extension-underline/src/index.ts b/packages/extension-underline/src/index.ts index 39628b7f..bd4e0081 100644 --- a/packages/extension-underline/src/index.ts +++ b/packages/extension-underline/src/index.ts @@ -14,8 +14,8 @@ const Underline = createMark({ ] }, - renderHTML({ attributes }) { - return ['u', attributes, 0] + renderHTML({ HTMLAttributes }) { + return ['u', HTMLAttributes, 0] }, addCommands() { From 2591ffe41916dc0ec92202898b58cb331172b6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 13 Nov 2020 16:44:22 +0100 Subject: [PATCH 02/16] add HTMLAttributes to defaultoptions --- packages/extension-blockquote/src/index.ts | 10 ++++++++++ packages/extension-bold/src/index.ts | 10 ++++++++++ packages/extension-bullet-list/src/index.ts | 10 ++++++++++ packages/extension-code-block/src/index.ts | 4 ++++ packages/extension-code/src/index.ts | 15 +++++++++++++- packages/extension-highlight/src/index.ts | 10 ++++++++++ .../extension-horizontal-rule/src/index.ts | 10 ++++++++++ packages/extension-image/src/index.ts | 4 ++++ packages/extension-italic/src/index.ts | 15 +++++++++++++- packages/extension-link/src/index.ts | 20 ++++++++++++------- packages/extension-list-item/src/index.ts | 10 ++++++++++ packages/extension-ordered-list/src/index.ts | 10 ++++++++++ packages/extension-paragraph/paragraph.vue | 9 --------- packages/extension-paragraph/src/index.ts | 11 +++++++++- packages/extension-strike/src/index.ts | 15 +++++++++++++- packages/extension-task-item/src/index.ts | 16 +++++++++------ packages/extension-task-list/src/index.ts | 10 ++++++++++ packages/extension-underline/src/index.ts | 10 ++++++++++ 18 files changed, 173 insertions(+), 26 deletions(-) delete mode 100644 packages/extension-paragraph/paragraph.vue diff --git a/packages/extension-blockquote/src/index.ts b/packages/extension-blockquote/src/index.ts index 5df5ae47..e916cb7d 100644 --- a/packages/extension-blockquote/src/index.ts +++ b/packages/extension-blockquote/src/index.ts @@ -1,11 +1,21 @@ import { Command, createNode } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' +export interface BlockquoteOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const inputRegex = /^\s*>\s$/gm const Blockquote = createNode({ name: 'blockquote', + defaultOptions: { + HTMLAttributes: {}, + }, + content: 'block*', group: 'block', diff --git a/packages/extension-bold/src/index.ts b/packages/extension-bold/src/index.ts index ee37ebb4..e4800856 100644 --- a/packages/extension-bold/src/index.ts +++ b/packages/extension-bold/src/index.ts @@ -2,6 +2,12 @@ import { Command, createMark, markInputRule, markPasteRule, } from '@tiptap/core' +export interface BoldOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const starInputRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/gm export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/gm export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm @@ -10,6 +16,10 @@ export const underscorePasteRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))/gm const Bold = createMark({ name: 'bold', + defaultOptions: { + HTMLAttributes: {}, + }, + parseHTML() { return [ { diff --git a/packages/extension-bullet-list/src/index.ts b/packages/extension-bullet-list/src/index.ts index 49b6f292..49800640 100644 --- a/packages/extension-bullet-list/src/index.ts +++ b/packages/extension-bullet-list/src/index.ts @@ -1,11 +1,21 @@ import { Command, createNode } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' +export interface BulletListOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const inputRegex = /^\s*([-+*])\s$/ const BulletList = createNode({ name: 'bulletList', + defaultOptions: { + HTMLAttributes: {}, + }, + group: 'block list', content: 'listItem+', diff --git a/packages/extension-code-block/src/index.ts b/packages/extension-code-block/src/index.ts index d8203b5a..42ec0825 100644 --- a/packages/extension-code-block/src/index.ts +++ b/packages/extension-code-block/src/index.ts @@ -3,6 +3,9 @@ import { textblockTypeInputRule } from 'prosemirror-inputrules' export interface CodeBlockOptions { languageClassPrefix: string, + HTMLAttributes: { + [key: string]: any + }, } export const backtickInputRegex = /^```(?[a-z]*)? $/ @@ -13,6 +16,7 @@ const CodeBlock = createNode({ defaultOptions: { languageClassPrefix: 'language-', + HTMLAttributes: {}, }, content: 'text*', diff --git a/packages/extension-code/src/index.ts b/packages/extension-code/src/index.ts index 7b68e0d6..78d89378 100644 --- a/packages/extension-code/src/index.ts +++ b/packages/extension-code/src/index.ts @@ -1,13 +1,26 @@ import { - Command, createMark, markInputRule, markPasteRule, + Command, + createMark, + markInputRule, + markPasteRule, } from '@tiptap/core' +export interface CodeOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm const Code = createMark({ name: 'code', + defaultOptions: { + HTMLAttributes: {}, + }, + excludes: '_', parseHTML() { diff --git a/packages/extension-highlight/src/index.ts b/packages/extension-highlight/src/index.ts index 44586cce..e9d1d8f1 100644 --- a/packages/extension-highlight/src/index.ts +++ b/packages/extension-highlight/src/index.ts @@ -5,12 +5,22 @@ import { markPasteRule, } from '@tiptap/core' +export interface HighlightOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm const Highlight = createMark({ name: 'highlight', + defaultOptions: { + HTMLAttributes: {}, + }, + addAttributes() { return { color: { diff --git a/packages/extension-horizontal-rule/src/index.ts b/packages/extension-horizontal-rule/src/index.ts index d0babb66..e14749a6 100644 --- a/packages/extension-horizontal-rule/src/index.ts +++ b/packages/extension-horizontal-rule/src/index.ts @@ -1,8 +1,18 @@ import { Command, createNode, nodeInputRule } from '@tiptap/core' +export interface HorizontalRuleOptions { + HTMLAttributes: { + [key: string]: any + }, +} + const HorizontalRule = createNode({ name: 'horizontalRule', + defaultOptions: { + HTMLAttributes: {}, + }, + group: 'block', parseHTML() { diff --git a/packages/extension-image/src/index.ts b/packages/extension-image/src/index.ts index 1957cddb..1db0edb4 100644 --- a/packages/extension-image/src/index.ts +++ b/packages/extension-image/src/index.ts @@ -2,6 +2,9 @@ import { Command, createNode, nodeInputRule } from '@tiptap/core' export interface ImageOptions { inline: boolean, + HTMLAttributes: { + [key: string]: any + }, } export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/ @@ -11,6 +14,7 @@ const Image = createNode({ defaultOptions: { inline: false, + HTMLAttributes: {}, }, inline() { diff --git a/packages/extension-italic/src/index.ts b/packages/extension-italic/src/index.ts index ad5a6390..3828c3cd 100644 --- a/packages/extension-italic/src/index.ts +++ b/packages/extension-italic/src/index.ts @@ -1,7 +1,16 @@ import { - Command, createMark, markInputRule, markPasteRule, + Command, + createMark, + markInputRule, + markPasteRule, } from '@tiptap/core' +export interface ItalicOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm @@ -10,6 +19,10 @@ export const underscorePasteRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/gm const Italic = createMark({ name: 'italic', + defaultOptions: { + HTMLAttributes: {}, + }, + parseHTML() { return [ { diff --git a/packages/extension-link/src/index.ts b/packages/extension-link/src/index.ts index 70334a1c..5298bc10 100644 --- a/packages/extension-link/src/index.ts +++ b/packages/extension-link/src/index.ts @@ -1,12 +1,16 @@ import { - Command, createMark, markPasteRule, mergeAttributes, + Command, + createMark, + markPasteRule, + mergeAttributes, } from '@tiptap/core' import { Plugin, PluginKey } from 'prosemirror-state' export interface LinkOptions { openOnClick: boolean, - target: string, - rel: string, + HTMLAttributes: { + [key: string]: any + }, } export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)/gi @@ -18,8 +22,10 @@ const Link = createMark({ defaultOptions: { openOnClick: true, - target: '_blank', - rel: 'noopener noreferrer nofollow', + HTMLAttributes: { + target: '_blank', + rel: 'noopener noreferrer nofollow', + }, }, addAttributes() { @@ -28,7 +34,7 @@ const Link = createMark({ default: null, }, target: { - default: this.options.target, + default: this.options.HTMLAttributes.target, }, } }, @@ -40,7 +46,7 @@ const Link = createMark({ }, renderHTML({ HTMLAttributes }) { - return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.rel }), 0] + return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.HTMLAttributes.rel }), 0] }, addCommands() { diff --git a/packages/extension-list-item/src/index.ts b/packages/extension-list-item/src/index.ts index 8e3c05bd..c9bdca34 100644 --- a/packages/extension-list-item/src/index.ts +++ b/packages/extension-list-item/src/index.ts @@ -1,8 +1,18 @@ import { createNode } from '@tiptap/core' +export interface ListItemOptions { + HTMLAttributes: { + [key: string]: any + }, +} + const ListItem = createNode({ name: 'listItem', + defaultOptions: { + HTMLAttributes: {}, + }, + content: '(paragraph|list?)+', defining: true, diff --git a/packages/extension-ordered-list/src/index.ts b/packages/extension-ordered-list/src/index.ts index 11da5dd6..7a3f67c5 100644 --- a/packages/extension-ordered-list/src/index.ts +++ b/packages/extension-ordered-list/src/index.ts @@ -1,11 +1,21 @@ import { Command, createNode } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' +export interface OrderedListOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const inputRegex = /^(\d+)\.\s$/ const OrderedList = createNode({ name: 'orderedList', + defaultOptions: { + HTMLAttributes: {}, + }, + group: 'block list', content: 'listItem+', diff --git a/packages/extension-paragraph/paragraph.vue b/packages/extension-paragraph/paragraph.vue deleted file mode 100644 index 7fc13d8c..00000000 --- a/packages/extension-paragraph/paragraph.vue +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/packages/extension-paragraph/src/index.ts b/packages/extension-paragraph/src/index.ts index 246d1ac2..f5fd23b5 100644 --- a/packages/extension-paragraph/src/index.ts +++ b/packages/extension-paragraph/src/index.ts @@ -1,9 +1,18 @@ import { Command, createNode } from '@tiptap/core' -// import ParagraphComponent from './paragraph.vue' + +export interface ParagraphOptions { + HTMLAttributes: { + [key: string]: any + }, +} const Paragraph = createNode({ name: 'paragraph', + // defaultOptions: { + // HTMLAttributes: {}, + // }, + group: 'block', content: 'inline*', diff --git a/packages/extension-strike/src/index.ts b/packages/extension-strike/src/index.ts index 8856ba6e..20707ce5 100644 --- a/packages/extension-strike/src/index.ts +++ b/packages/extension-strike/src/index.ts @@ -1,13 +1,26 @@ import { - Command, createMark, markInputRule, markPasteRule, + Command, + createMark, + markInputRule, + markPasteRule, } from '@tiptap/core' +export interface StrikeOptions { + HTMLAttributes: { + [key: string]: any + }, +} + export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm const Strike = createMark({ name: 'strike', + defaultOptions: { + HTMLAttributes: {}, + }, + parseHTML() { return [ { diff --git a/packages/extension-task-item/src/index.ts b/packages/extension-task-item/src/index.ts index 9f3eeb37..ab98ba52 100644 --- a/packages/extension-task-item/src/index.ts +++ b/packages/extension-task-item/src/index.ts @@ -1,25 +1,29 @@ import { createNode, mergeAttributes } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' -export const inputRegex = /^\s*(\[([ |x])\])\s$/ - export interface TaskItemOptions { nested: boolean, + HTMLAttributes: { + [key: string]: any + }, } +export const inputRegex = /^\s*(\[([ |x])\])\s$/ + const TaskItem = createNode({ name: 'taskItem', + defaultOptions: { + nested: false, + HTMLAttributes: {}, + }, + content() { return this.options.nested ? '(paragraph|taskList)+' : 'paragraph+' }, defining: true, - defaultOptions: { - nested: false, - }, - addAttributes() { return { checked: { diff --git a/packages/extension-task-list/src/index.ts b/packages/extension-task-list/src/index.ts index 862578b2..240eb55d 100644 --- a/packages/extension-task-list/src/index.ts +++ b/packages/extension-task-list/src/index.ts @@ -1,8 +1,18 @@ import { Command, createNode, mergeAttributes } from '@tiptap/core' +export interface TaskListOptions { + HTMLAttributes: { + [key: string]: any + }, +} + const TaskList = createNode({ name: 'taskList', + defaultOptions: { + HTMLAttributes: {}, + }, + group: 'block list', content: 'taskItem+', diff --git a/packages/extension-underline/src/index.ts b/packages/extension-underline/src/index.ts index bd4e0081..1f270f47 100644 --- a/packages/extension-underline/src/index.ts +++ b/packages/extension-underline/src/index.ts @@ -1,8 +1,18 @@ import { Command, createMark } from '@tiptap/core' +export interface UnderlineOptions { + HTMLAttributes: { + [key: string]: any + }, +} + const Underline = createMark({ name: 'underline', + defaultOptions: { + HTMLAttributes: {}, + }, + parseHTML() { return [ { From 41ce8c0743ccda7b831f72d1a64ee62993bda298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 13 Nov 2020 16:46:12 +0100 Subject: [PATCH 03/16] fix lint --- docs/src/components/PageNavigation/index.vue | 7 ++++++- docs/src/demos/Examples/MarkdownShortcuts/index.vue | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/src/components/PageNavigation/index.vue b/docs/src/components/PageNavigation/index.vue index 6f2073a2..c12e25e3 100644 --- a/docs/src/components/PageNavigation/index.vue +++ b/docs/src/components/PageNavigation/index.vue @@ -41,7 +41,12 @@ export default { flattenedItems() { const flattenedItems = [] - this.items.forEach(({ title, link, redirect, items }) => { + this.items.forEach(({ + title, + link, + redirect, + items, + }) => { flattenedItems.push({ title, link, diff --git a/docs/src/demos/Examples/MarkdownShortcuts/index.vue b/docs/src/demos/Examples/MarkdownShortcuts/index.vue index d2176b57..5bd851c1 100644 --- a/docs/src/demos/Examples/MarkdownShortcuts/index.vue +++ b/docs/src/demos/Examples/MarkdownShortcuts/index.vue @@ -6,7 +6,6 @@