mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
add HTMLAttributes to defaultoptions
This commit is contained in:
parent
c840a562de
commit
2591ffe419
@ -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',
|
||||
|
@ -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 [
|
||||
{
|
||||
|
@ -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+',
|
||||
|
@ -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*',
|
||||
|
@ -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() {
|
||||
|
@ -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: {
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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 [
|
||||
{
|
||||
|
@ -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() {
|
||||
|
@ -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,
|
||||
|
@ -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+',
|
||||
|
@ -1,9 +0,0 @@
|
||||
<template>
|
||||
<p data-component="yeah" ref="content"></p>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
|
||||
}
|
||||
</script>
|
@ -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*',
|
||||
|
@ -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 [
|
||||
{
|
||||
|
@ -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: {
|
||||
|
@ -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+',
|
||||
|
@ -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 [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user