@tiptap/extension-highlight 2.0.0-beta.21 → 2.0.0-beta.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +91 -0
- package/dist/{packages/extension-highlight/src/highlight.d.ts → index.d.ts} +33 -30
- package/dist/index.js +91 -0
- package/package.json +30 -7
- package/src/highlight.ts +19 -11
- package/LICENSE.md +0 -21
- package/dist/packages/extension-highlight/src/index.d.ts +0 -3
- package/dist/tiptap-extension-highlight.cjs.js +0 -79
- package/dist/tiptap-extension-highlight.cjs.js.map +0 -1
- package/dist/tiptap-extension-highlight.esm.js +0 -72
- package/dist/tiptap-extension-highlight.esm.js.map +0 -1
- package/dist/tiptap-extension-highlight.umd.js +0 -83
- package/dist/tiptap-extension-highlight.umd.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/highlight.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _core = require('@tiptap/core');
|
|
8
|
+
var inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
9
|
+
var pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
10
|
+
var Highlight = _core.Mark.create({
|
|
11
|
+
name: "highlight",
|
|
12
|
+
addOptions() {
|
|
13
|
+
return {
|
|
14
|
+
multicolor: false,
|
|
15
|
+
HTMLAttributes: {}
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
addAttributes() {
|
|
19
|
+
if (!this.options.multicolor) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
color: {
|
|
24
|
+
default: null,
|
|
25
|
+
parseHTML: (element) => element.getAttribute("data-color") || element.style.backgroundColor,
|
|
26
|
+
renderHTML: (attributes) => {
|
|
27
|
+
if (!attributes.color) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
"data-color": attributes.color,
|
|
32
|
+
style: `background-color: ${attributes.color}; color: inherit`
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
parseHTML() {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
tag: "mark"
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
renderHTML({ HTMLAttributes }) {
|
|
46
|
+
return ["mark", _core.mergeAttributes.call(void 0, this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
47
|
+
},
|
|
48
|
+
addCommands() {
|
|
49
|
+
return {
|
|
50
|
+
setHighlight: (attributes) => ({ commands }) => {
|
|
51
|
+
return commands.setMark(this.name, attributes);
|
|
52
|
+
},
|
|
53
|
+
toggleHighlight: (attributes) => ({ commands }) => {
|
|
54
|
+
return commands.toggleMark(this.name, attributes);
|
|
55
|
+
},
|
|
56
|
+
unsetHighlight: () => ({ commands }) => {
|
|
57
|
+
return commands.unsetMark(this.name);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
addKeyboardShortcuts() {
|
|
62
|
+
return {
|
|
63
|
+
"Mod-Shift-h": () => this.editor.commands.toggleHighlight()
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
addInputRules() {
|
|
67
|
+
return [
|
|
68
|
+
_core.markInputRule.call(void 0, {
|
|
69
|
+
find: inputRegex,
|
|
70
|
+
type: this.type
|
|
71
|
+
})
|
|
72
|
+
];
|
|
73
|
+
},
|
|
74
|
+
addPasteRules() {
|
|
75
|
+
return [
|
|
76
|
+
_core.markPasteRule.call(void 0, {
|
|
77
|
+
find: pasteRegex,
|
|
78
|
+
type: this.type
|
|
79
|
+
})
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// src/index.ts
|
|
85
|
+
var src_default = Highlight;
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
exports.Highlight = Highlight; exports.default = src_default; exports.inputRegex = inputRegex; exports.pasteRegex = pasteRegex;
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { Mark } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface HighlightOptions {
|
|
4
|
+
multicolor: boolean;
|
|
5
|
+
HTMLAttributes: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
declare module '@tiptap/core' {
|
|
8
|
+
interface Commands<ReturnType> {
|
|
9
|
+
highlight: {
|
|
10
|
+
/**
|
|
11
|
+
* Set a highlight mark
|
|
12
|
+
*/
|
|
13
|
+
setHighlight: (attributes?: {
|
|
14
|
+
color: string;
|
|
15
|
+
}) => ReturnType;
|
|
16
|
+
/**
|
|
17
|
+
* Toggle a highlight mark
|
|
18
|
+
*/
|
|
19
|
+
toggleHighlight: (attributes?: {
|
|
20
|
+
color: string;
|
|
21
|
+
}) => ReturnType;
|
|
22
|
+
/**
|
|
23
|
+
* Unset a highlight mark
|
|
24
|
+
*/
|
|
25
|
+
unsetHighlight: () => ReturnType;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
declare const inputRegex: RegExp;
|
|
30
|
+
declare const pasteRegex: RegExp;
|
|
31
|
+
declare const Highlight: Mark<HighlightOptions, any>;
|
|
32
|
+
|
|
33
|
+
export { Highlight, HighlightOptions, Highlight as default, inputRegex, pasteRegex };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/highlight.ts
|
|
2
|
+
import {
|
|
3
|
+
Mark,
|
|
4
|
+
markInputRule,
|
|
5
|
+
markPasteRule,
|
|
6
|
+
mergeAttributes
|
|
7
|
+
} from "@tiptap/core";
|
|
8
|
+
var inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
9
|
+
var pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
10
|
+
var Highlight = Mark.create({
|
|
11
|
+
name: "highlight",
|
|
12
|
+
addOptions() {
|
|
13
|
+
return {
|
|
14
|
+
multicolor: false,
|
|
15
|
+
HTMLAttributes: {}
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
addAttributes() {
|
|
19
|
+
if (!this.options.multicolor) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
color: {
|
|
24
|
+
default: null,
|
|
25
|
+
parseHTML: (element) => element.getAttribute("data-color") || element.style.backgroundColor,
|
|
26
|
+
renderHTML: (attributes) => {
|
|
27
|
+
if (!attributes.color) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
"data-color": attributes.color,
|
|
32
|
+
style: `background-color: ${attributes.color}; color: inherit`
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
parseHTML() {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
tag: "mark"
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
renderHTML({ HTMLAttributes }) {
|
|
46
|
+
return ["mark", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
47
|
+
},
|
|
48
|
+
addCommands() {
|
|
49
|
+
return {
|
|
50
|
+
setHighlight: (attributes) => ({ commands }) => {
|
|
51
|
+
return commands.setMark(this.name, attributes);
|
|
52
|
+
},
|
|
53
|
+
toggleHighlight: (attributes) => ({ commands }) => {
|
|
54
|
+
return commands.toggleMark(this.name, attributes);
|
|
55
|
+
},
|
|
56
|
+
unsetHighlight: () => ({ commands }) => {
|
|
57
|
+
return commands.unsetMark(this.name);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
addKeyboardShortcuts() {
|
|
62
|
+
return {
|
|
63
|
+
"Mod-Shift-h": () => this.editor.commands.toggleHighlight()
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
addInputRules() {
|
|
67
|
+
return [
|
|
68
|
+
markInputRule({
|
|
69
|
+
find: inputRegex,
|
|
70
|
+
type: this.type
|
|
71
|
+
})
|
|
72
|
+
];
|
|
73
|
+
},
|
|
74
|
+
addPasteRules() {
|
|
75
|
+
return [
|
|
76
|
+
markPasteRule({
|
|
77
|
+
find: pasteRegex,
|
|
78
|
+
type: this.type
|
|
79
|
+
})
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// src/index.ts
|
|
85
|
+
var src_default = Highlight;
|
|
86
|
+
export {
|
|
87
|
+
Highlight,
|
|
88
|
+
src_default as default,
|
|
89
|
+
inputRegex,
|
|
90
|
+
pasteRegex
|
|
91
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-highlight",
|
|
3
3
|
"description": "highlight extension for tiptap",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.211",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -12,21 +12,44 @@
|
|
|
12
12
|
"type": "github",
|
|
13
13
|
"url": "https://github.com/sponsors/ueberdosis"
|
|
14
14
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "dist/index.cjs",
|
|
24
|
+
"module": "dist/index.js",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
19
26
|
"files": [
|
|
20
27
|
"src",
|
|
21
28
|
"dist"
|
|
22
29
|
],
|
|
23
30
|
"peerDependencies": {
|
|
24
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
31
|
+
"@tiptap/core": "^2.0.0-beta.209"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@tiptap/core": "^2.0.0-beta.211"
|
|
25
35
|
},
|
|
26
36
|
"repository": {
|
|
27
37
|
"type": "git",
|
|
28
38
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
29
39
|
"directory": "packages/extension-highlight"
|
|
30
40
|
},
|
|
31
|
-
"
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup"
|
|
43
|
+
},
|
|
44
|
+
"tsup": {
|
|
45
|
+
"entry": [
|
|
46
|
+
"src/index.ts"
|
|
47
|
+
],
|
|
48
|
+
"dts": true,
|
|
49
|
+
"splitting": true,
|
|
50
|
+
"format": [
|
|
51
|
+
"esm",
|
|
52
|
+
"cjs"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
32
55
|
}
|
package/src/highlight.ts
CHANGED
|
@@ -29,15 +29,17 @@ declare module '@tiptap/core' {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export const inputRegex = /(?:^|\s)((?:==)((?:[
|
|
33
|
-
export const pasteRegex = /(?:^|\s)((?:==)((?:[
|
|
32
|
+
export const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/
|
|
33
|
+
export const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g
|
|
34
34
|
|
|
35
35
|
export const Highlight = Mark.create<HighlightOptions>({
|
|
36
36
|
name: 'highlight',
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
addOptions() {
|
|
39
|
+
return {
|
|
40
|
+
multicolor: false,
|
|
41
|
+
HTMLAttributes: {},
|
|
42
|
+
}
|
|
41
43
|
},
|
|
42
44
|
|
|
43
45
|
addAttributes() {
|
|
@@ -56,7 +58,7 @@ export const Highlight = Mark.create<HighlightOptions>({
|
|
|
56
58
|
|
|
57
59
|
return {
|
|
58
60
|
'data-color': attributes.color,
|
|
59
|
-
style: `background-color: ${attributes.color}`,
|
|
61
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
60
62
|
}
|
|
61
63
|
},
|
|
62
64
|
},
|
|
@@ -78,13 +80,13 @@ export const Highlight = Mark.create<HighlightOptions>({
|
|
|
78
80
|
addCommands() {
|
|
79
81
|
return {
|
|
80
82
|
setHighlight: attributes => ({ commands }) => {
|
|
81
|
-
return commands.setMark(
|
|
83
|
+
return commands.setMark(this.name, attributes)
|
|
82
84
|
},
|
|
83
85
|
toggleHighlight: attributes => ({ commands }) => {
|
|
84
|
-
return commands.toggleMark(
|
|
86
|
+
return commands.toggleMark(this.name, attributes)
|
|
85
87
|
},
|
|
86
88
|
unsetHighlight: () => ({ commands }) => {
|
|
87
|
-
return commands.unsetMark(
|
|
89
|
+
return commands.unsetMark(this.name)
|
|
88
90
|
},
|
|
89
91
|
}
|
|
90
92
|
},
|
|
@@ -97,13 +99,19 @@ export const Highlight = Mark.create<HighlightOptions>({
|
|
|
97
99
|
|
|
98
100
|
addInputRules() {
|
|
99
101
|
return [
|
|
100
|
-
markInputRule(
|
|
102
|
+
markInputRule({
|
|
103
|
+
find: inputRegex,
|
|
104
|
+
type: this.type,
|
|
105
|
+
}),
|
|
101
106
|
]
|
|
102
107
|
},
|
|
103
108
|
|
|
104
109
|
addPasteRules() {
|
|
105
110
|
return [
|
|
106
|
-
markPasteRule(
|
|
111
|
+
markPasteRule({
|
|
112
|
+
find: pasteRegex,
|
|
113
|
+
type: this.type,
|
|
114
|
+
}),
|
|
107
115
|
]
|
|
108
116
|
},
|
|
109
117
|
})
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021, überdosis GbR
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var core = require('@tiptap/core');
|
|
6
|
-
|
|
7
|
-
const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm;
|
|
8
|
-
const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm;
|
|
9
|
-
const Highlight = core.Mark.create({
|
|
10
|
-
name: 'highlight',
|
|
11
|
-
defaultOptions: {
|
|
12
|
-
multicolor: false,
|
|
13
|
-
HTMLAttributes: {},
|
|
14
|
-
},
|
|
15
|
-
addAttributes() {
|
|
16
|
-
if (!this.options.multicolor) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
color: {
|
|
21
|
-
default: null,
|
|
22
|
-
parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
|
|
23
|
-
renderHTML: attributes => {
|
|
24
|
-
if (!attributes.color) {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
'data-color': attributes.color,
|
|
29
|
-
style: `background-color: ${attributes.color}`,
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
parseHTML() {
|
|
36
|
-
return [
|
|
37
|
-
{
|
|
38
|
-
tag: 'mark',
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
},
|
|
42
|
-
renderHTML({ HTMLAttributes }) {
|
|
43
|
-
return ['mark', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
44
|
-
},
|
|
45
|
-
addCommands() {
|
|
46
|
-
return {
|
|
47
|
-
setHighlight: attributes => ({ commands }) => {
|
|
48
|
-
return commands.setMark('highlight', attributes);
|
|
49
|
-
},
|
|
50
|
-
toggleHighlight: attributes => ({ commands }) => {
|
|
51
|
-
return commands.toggleMark('highlight', attributes);
|
|
52
|
-
},
|
|
53
|
-
unsetHighlight: () => ({ commands }) => {
|
|
54
|
-
return commands.unsetMark('highlight');
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
addKeyboardShortcuts() {
|
|
59
|
-
return {
|
|
60
|
-
'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
addInputRules() {
|
|
64
|
-
return [
|
|
65
|
-
core.markInputRule(inputRegex, this.type),
|
|
66
|
-
];
|
|
67
|
-
},
|
|
68
|
-
addPasteRules() {
|
|
69
|
-
return [
|
|
70
|
-
core.markPasteRule(pasteRegex, this.type),
|
|
71
|
-
];
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
exports.Highlight = Highlight;
|
|
76
|
-
exports["default"] = Highlight;
|
|
77
|
-
exports.inputRegex = inputRegex;
|
|
78
|
-
exports.pasteRegex = pasteRegex;
|
|
79
|
-
//# sourceMappingURL=tiptap-extension-highlight.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-highlight.cjs.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Mark,\n markInputRule,\n markPasteRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface HighlightOptions {\n multicolor: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))$/gm\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))/gm\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n defaultOptions: {\n multicolor: false,\n HTMLAttributes: {},\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}`,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'mark',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setHighlight: attributes => ({ commands }) => {\n return commands.setMark('highlight', attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark('highlight', attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark('highlight')\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule(inputRegex, this.type),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule(pasteRegex, this.type),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;MA+Ba,UAAU,GAAG,uCAAsC;MACnD,UAAU,GAAG,sCAAqC;MAElD,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;IACrD,IAAI,EAAE,WAAW;IAEjB,cAAc,EAAE;QACd,UAAU,EAAE,KAAK;QACjB,cAAc,EAAE,EAAE;KACnB;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC5B,OAAO,EAAE,CAAA;SACV;QAED,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;gBACzF,UAAU,EAAE,UAAU;oBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;wBACrB,OAAO,EAAE,CAAA;qBACV;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;wBAC9B,KAAK,EAAE,qBAAqB,UAAU,CAAC,KAAK,EAAE;qBAC/C,CAAA;iBACF;aACF;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,MAAM;aACZ;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBACvC,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACjD;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACpD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;aACvC;SACF,CAAA;KACF;IAED,oBAAoB;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;CACF;;;;;;;"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm;
|
|
4
|
-
const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm;
|
|
5
|
-
const Highlight = Mark.create({
|
|
6
|
-
name: 'highlight',
|
|
7
|
-
defaultOptions: {
|
|
8
|
-
multicolor: false,
|
|
9
|
-
HTMLAttributes: {},
|
|
10
|
-
},
|
|
11
|
-
addAttributes() {
|
|
12
|
-
if (!this.options.multicolor) {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
color: {
|
|
17
|
-
default: null,
|
|
18
|
-
parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
|
|
19
|
-
renderHTML: attributes => {
|
|
20
|
-
if (!attributes.color) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
'data-color': attributes.color,
|
|
25
|
-
style: `background-color: ${attributes.color}`,
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
parseHTML() {
|
|
32
|
-
return [
|
|
33
|
-
{
|
|
34
|
-
tag: 'mark',
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
},
|
|
38
|
-
renderHTML({ HTMLAttributes }) {
|
|
39
|
-
return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
40
|
-
},
|
|
41
|
-
addCommands() {
|
|
42
|
-
return {
|
|
43
|
-
setHighlight: attributes => ({ commands }) => {
|
|
44
|
-
return commands.setMark('highlight', attributes);
|
|
45
|
-
},
|
|
46
|
-
toggleHighlight: attributes => ({ commands }) => {
|
|
47
|
-
return commands.toggleMark('highlight', attributes);
|
|
48
|
-
},
|
|
49
|
-
unsetHighlight: () => ({ commands }) => {
|
|
50
|
-
return commands.unsetMark('highlight');
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
addKeyboardShortcuts() {
|
|
55
|
-
return {
|
|
56
|
-
'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
addInputRules() {
|
|
60
|
-
return [
|
|
61
|
-
markInputRule(inputRegex, this.type),
|
|
62
|
-
];
|
|
63
|
-
},
|
|
64
|
-
addPasteRules() {
|
|
65
|
-
return [
|
|
66
|
-
markPasteRule(pasteRegex, this.type),
|
|
67
|
-
];
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
export { Highlight, Highlight as default, inputRegex, pasteRegex };
|
|
72
|
-
//# sourceMappingURL=tiptap-extension-highlight.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-highlight.esm.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Mark,\n markInputRule,\n markPasteRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface HighlightOptions {\n multicolor: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))$/gm\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))/gm\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n defaultOptions: {\n multicolor: false,\n HTMLAttributes: {},\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}`,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'mark',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setHighlight: attributes => ({ commands }) => {\n return commands.setMark('highlight', attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark('highlight', attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark('highlight')\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule(inputRegex, this.type),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule(pasteRegex, this.type),\n ]\n },\n})\n"],"names":[],"mappings":";;MA+Ba,UAAU,GAAG,uCAAsC;MACnD,UAAU,GAAG,sCAAqC;MAElD,SAAS,GAAG,IAAI,CAAC,MAAM,CAAmB;IACrD,IAAI,EAAE,WAAW;IAEjB,cAAc,EAAE;QACd,UAAU,EAAE,KAAK;QACjB,cAAc,EAAE,EAAE;KACnB;IAED,aAAa;QACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC5B,OAAO,EAAE,CAAA;SACV;QAED,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;gBACzF,UAAU,EAAE,UAAU;oBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;wBACrB,OAAO,EAAE,CAAA;qBACV;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;wBAC9B,KAAK,EAAE,qBAAqB,UAAU,CAAC,KAAK,EAAE;qBAC/C,CAAA;iBACF;aACF;SACF,CAAA;KACF;IAED,SAAS;QACP,OAAO;YACL;gBACE,GAAG,EAAE,MAAM;aACZ;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC3B,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBACvC,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACjD;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;gBAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;aACpD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;gBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;aACvC;SACF,CAAA;KACF;IAED,oBAAoB;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACL,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;IAED,aAAa;QACX,OAAO;YACL,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;SACrC,CAAA;KACF;CACF;;;;"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-highlight"] = {}, global.core));
|
|
5
|
-
})(this, (function (exports, core) { 'use strict';
|
|
6
|
-
|
|
7
|
-
const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm;
|
|
8
|
-
const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm;
|
|
9
|
-
const Highlight = core.Mark.create({
|
|
10
|
-
name: 'highlight',
|
|
11
|
-
defaultOptions: {
|
|
12
|
-
multicolor: false,
|
|
13
|
-
HTMLAttributes: {},
|
|
14
|
-
},
|
|
15
|
-
addAttributes() {
|
|
16
|
-
if (!this.options.multicolor) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
color: {
|
|
21
|
-
default: null,
|
|
22
|
-
parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,
|
|
23
|
-
renderHTML: attributes => {
|
|
24
|
-
if (!attributes.color) {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
'data-color': attributes.color,
|
|
29
|
-
style: `background-color: ${attributes.color}`,
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
parseHTML() {
|
|
36
|
-
return [
|
|
37
|
-
{
|
|
38
|
-
tag: 'mark',
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
},
|
|
42
|
-
renderHTML({ HTMLAttributes }) {
|
|
43
|
-
return ['mark', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
44
|
-
},
|
|
45
|
-
addCommands() {
|
|
46
|
-
return {
|
|
47
|
-
setHighlight: attributes => ({ commands }) => {
|
|
48
|
-
return commands.setMark('highlight', attributes);
|
|
49
|
-
},
|
|
50
|
-
toggleHighlight: attributes => ({ commands }) => {
|
|
51
|
-
return commands.toggleMark('highlight', attributes);
|
|
52
|
-
},
|
|
53
|
-
unsetHighlight: () => ({ commands }) => {
|
|
54
|
-
return commands.unsetMark('highlight');
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
addKeyboardShortcuts() {
|
|
59
|
-
return {
|
|
60
|
-
'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
addInputRules() {
|
|
64
|
-
return [
|
|
65
|
-
core.markInputRule(inputRegex, this.type),
|
|
66
|
-
];
|
|
67
|
-
},
|
|
68
|
-
addPasteRules() {
|
|
69
|
-
return [
|
|
70
|
-
core.markPasteRule(pasteRegex, this.type),
|
|
71
|
-
];
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
exports.Highlight = Highlight;
|
|
76
|
-
exports["default"] = Highlight;
|
|
77
|
-
exports.inputRegex = inputRegex;
|
|
78
|
-
exports.pasteRegex = pasteRegex;
|
|
79
|
-
|
|
80
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
81
|
-
|
|
82
|
-
}));
|
|
83
|
-
//# sourceMappingURL=tiptap-extension-highlight.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-highlight.umd.js","sources":["../src/highlight.ts"],"sourcesContent":["import {\n Mark,\n markInputRule,\n markPasteRule,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface HighlightOptions {\n multicolor: boolean,\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n */\n setHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Toggle a highlight mark\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType,\n /**\n * Unset a highlight mark\n */\n unsetHighlight: () => ReturnType,\n }\n }\n}\n\nexport const inputRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))$/gm\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~]+))(?:==))/gm\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n defaultOptions: {\n multicolor: false,\n HTMLAttributes: {},\n },\n\n addAttributes() {\n if (!this.options.multicolor) {\n return {}\n }\n\n return {\n color: {\n default: null,\n parseHTML: element => element.getAttribute('data-color') || element.style.backgroundColor,\n renderHTML: attributes => {\n if (!attributes.color) {\n return {}\n }\n\n return {\n 'data-color': attributes.color,\n style: `background-color: ${attributes.color}`,\n }\n },\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'mark',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['mark', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n setHighlight: attributes => ({ commands }) => {\n return commands.setMark('highlight', attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark('highlight', attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark('highlight')\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-h': () => this.editor.commands.toggleHighlight(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule(inputRegex, this.type),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule(pasteRegex, this.type),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;QA+Ba,UAAU,GAAG,uCAAsC;QACnD,UAAU,GAAG,sCAAqC;QAElD,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;MACrD,IAAI,EAAE,WAAW;MAEjB,cAAc,EAAE;UACd,UAAU,EAAE,KAAK;UACjB,cAAc,EAAE,EAAE;OACnB;MAED,aAAa;UACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;cAC5B,OAAO,EAAE,CAAA;WACV;UAED,OAAO;cACL,KAAK,EAAE;kBACL,OAAO,EAAE,IAAI;kBACb,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;kBACzF,UAAU,EAAE,UAAU;sBACpB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;0BACrB,OAAO,EAAE,CAAA;uBACV;sBAED,OAAO;0BACL,YAAY,EAAE,UAAU,CAAC,KAAK;0BAC9B,KAAK,EAAE,qBAAqB,UAAU,CAAC,KAAK,EAAE;uBAC/C,CAAA;mBACF;eACF;WACF,CAAA;OACF;MAED,SAAS;UACP,OAAO;cACL;kBACE,GAAG,EAAE,MAAM;eACZ;WACF,CAAA;OACF;MAED,UAAU,CAAC,EAAE,cAAc,EAAE;UAC3B,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;OACjF;MAED,WAAW;UACT,OAAO;cACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;kBACvC,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;eACjD;cACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE;kBAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;eACpD;cACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE;kBACjC,OAAO,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;eACvC;WACF,CAAA;OACF;MAED,oBAAoB;UAClB,OAAO;cACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;WAC5D,CAAA;OACF;MAED,aAAa;UACX,OAAO;cACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;WACrC,CAAA;OACF;MAED,aAAa;UACX,OAAO;cACLC,kBAAa,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC;WACrC,CAAA;OACF;GACF;;;;;;;;;;;;;"}
|