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] 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 5df5ae473..e916cb7d4 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 ee37ebb43..e48008562 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 49b6f2923..49800640f 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 d8203b5af..42ec0825c 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 7b68e0d6c..78d893789 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 44586cceb..e9d1d8f12 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 d0babb665..e14749a6d 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 1957cddb4..1db0edb46 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 ad5a63900..3828c3cd5 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 70334a1ca..5298bc108 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 8e3c05bdb..c9bdca349 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 11da5dd67..7a3f67c53 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 7fc13d8cc..000000000 --- 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 246d1ac2c..f5fd23b5b 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 8856ba6ef..20707ce53 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 9f3eeb37e..ab98ba52a 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 862578b2e..240eb55d2 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 bd4e00818..1f270f47f 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 [ {