add HTMLAttributes to defaultoptions

This commit is contained in:
Philipp Kühn 2020-11-13 16:44:22 +01:00
parent c840a562de
commit 2591ffe419
18 changed files with 173 additions and 26 deletions

View File

@ -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: <BlockquoteOptions>{
HTMLAttributes: {},
},
content: 'block*',
group: 'block',

View File

@ -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: <BoldOptions>{
HTMLAttributes: {},
},
parseHTML() {
return [
{

View File

@ -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: <BulletListOptions>{
HTMLAttributes: {},
},
group: 'block list',
content: 'listItem+',

View File

@ -3,6 +3,9 @@ import { textblockTypeInputRule } from 'prosemirror-inputrules'
export interface CodeBlockOptions {
languageClassPrefix: string,
HTMLAttributes: {
[key: string]: any
},
}
export const backtickInputRegex = /^```(?<language>[a-z]*)? $/
@ -13,6 +16,7 @@ const CodeBlock = createNode({
defaultOptions: <CodeBlockOptions>{
languageClassPrefix: 'language-',
HTMLAttributes: {},
},
content: 'text*',

View File

@ -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: <CodeOptions>{
HTMLAttributes: {},
},
excludes: '_',
parseHTML() {

View File

@ -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: <HighlightOptions>{
HTMLAttributes: {},
},
addAttributes() {
return {
color: {

View File

@ -1,8 +1,18 @@
import { Command, createNode, nodeInputRule } from '@tiptap/core'
export interface HorizontalRuleOptions {
HTMLAttributes: {
[key: string]: any
},
}
const HorizontalRule = createNode({
name: 'horizontalRule',
defaultOptions: <HorizontalRuleOptions>{
HTMLAttributes: {},
},
group: 'block',
parseHTML() {

View File

@ -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: <ImageOptions>{
inline: false,
HTMLAttributes: {},
},
inline() {

View File

@ -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: <ItalicOptions>{
HTMLAttributes: {},
},
parseHTML() {
return [
{

View File

@ -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,9 +22,11 @@ const Link = createMark({
defaultOptions: <LinkOptions>{
openOnClick: true,
HTMLAttributes: {
target: '_blank',
rel: 'noopener noreferrer nofollow',
},
},
addAttributes() {
return {
@ -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() {

View File

@ -1,8 +1,18 @@
import { createNode } from '@tiptap/core'
export interface ListItemOptions {
HTMLAttributes: {
[key: string]: any
},
}
const ListItem = createNode({
name: 'listItem',
defaultOptions: <ListItemOptions>{
HTMLAttributes: {},
},
content: '(paragraph|list?)+',
defining: true,

View File

@ -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: <OrderedListOptions>{
HTMLAttributes: {},
},
group: 'block list',
content: 'listItem+',

View File

@ -1,9 +0,0 @@
<template>
<p data-component="yeah" ref="content"></p>
</template>
<script>
export default {
}
</script>

View File

@ -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: <ParagraphOptions>{
// HTMLAttributes: {},
// },
group: 'block',
content: 'inline*',

View File

@ -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: <StrikeOptions>{
HTMLAttributes: {},
},
parseHTML() {
return [
{

View File

@ -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: <TaskItemOptions>{
nested: false,
HTMLAttributes: {},
},
content() {
return this.options.nested ? '(paragraph|taskList)+' : 'paragraph+'
},
defining: true,
defaultOptions: <TaskItemOptions>{
nested: false,
},
addAttributes() {
return {
checked: {

View File

@ -1,8 +1,18 @@
import { Command, createNode, mergeAttributes } from '@tiptap/core'
export interface TaskListOptions {
HTMLAttributes: {
[key: string]: any
},
}
const TaskList = createNode({
name: 'taskList',
defaultOptions: <TaskListOptions>{
HTMLAttributes: {},
},
group: 'block list',
content: 'taskItem+',

View File

@ -1,8 +1,18 @@
import { Command, createMark } from '@tiptap/core'
export interface UnderlineOptions {
HTMLAttributes: {
[key: string]: any
},
}
const Underline = createMark({
name: 'underline',
defaultOptions: <UnderlineOptions>{
HTMLAttributes: {},
},
parseHTML() {
return [
{