@tiptap/extension-highlight 2.0.0-beta.20 → 2.0.0-beta.201
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/packages/extension-highlight/src/highlight.d.ts +1 -1
- package/dist/tiptap-extension-highlight.cjs.js +19 -11
- package/dist/tiptap-extension-highlight.cjs.js.map +1 -1
- package/dist/tiptap-extension-highlight.esm.js +19 -11
- package/dist/tiptap-extension-highlight.esm.js.map +1 -1
- package/dist/tiptap-extension-highlight.umd.js +19 -11
- package/dist/tiptap-extension-highlight.umd.js.map +1 -1
- package/package.json +3 -4
- package/src/highlight.ts +19 -11
- package/LICENSE.md +0 -21
|
@@ -4,13 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@tiptap/core');
|
|
6
6
|
|
|
7
|
-
const inputRegex = /(?:^|\s)((?:==)((?:[
|
|
8
|
-
const pasteRegex = /(?:^|\s)((?:==)((?:[
|
|
7
|
+
const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
8
|
+
const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
9
9
|
const Highlight = core.Mark.create({
|
|
10
10
|
name: 'highlight',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
multicolor: false,
|
|
14
|
+
HTMLAttributes: {},
|
|
15
|
+
};
|
|
14
16
|
},
|
|
15
17
|
addAttributes() {
|
|
16
18
|
if (!this.options.multicolor) {
|
|
@@ -26,7 +28,7 @@ const Highlight = core.Mark.create({
|
|
|
26
28
|
}
|
|
27
29
|
return {
|
|
28
30
|
'data-color': attributes.color,
|
|
29
|
-
style: `background-color: ${attributes.color}`,
|
|
31
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
30
32
|
};
|
|
31
33
|
},
|
|
32
34
|
},
|
|
@@ -45,13 +47,13 @@ const Highlight = core.Mark.create({
|
|
|
45
47
|
addCommands() {
|
|
46
48
|
return {
|
|
47
49
|
setHighlight: attributes => ({ commands }) => {
|
|
48
|
-
return commands.setMark(
|
|
50
|
+
return commands.setMark(this.name, attributes);
|
|
49
51
|
},
|
|
50
52
|
toggleHighlight: attributes => ({ commands }) => {
|
|
51
|
-
return commands.toggleMark(
|
|
53
|
+
return commands.toggleMark(this.name, attributes);
|
|
52
54
|
},
|
|
53
55
|
unsetHighlight: () => ({ commands }) => {
|
|
54
|
-
return commands.unsetMark(
|
|
56
|
+
return commands.unsetMark(this.name);
|
|
55
57
|
},
|
|
56
58
|
};
|
|
57
59
|
},
|
|
@@ -62,12 +64,18 @@ const Highlight = core.Mark.create({
|
|
|
62
64
|
},
|
|
63
65
|
addInputRules() {
|
|
64
66
|
return [
|
|
65
|
-
core.markInputRule(
|
|
67
|
+
core.markInputRule({
|
|
68
|
+
find: inputRegex,
|
|
69
|
+
type: this.type,
|
|
70
|
+
}),
|
|
66
71
|
];
|
|
67
72
|
},
|
|
68
73
|
addPasteRules() {
|
|
69
74
|
return [
|
|
70
|
-
core.markPasteRule(
|
|
75
|
+
core.markPasteRule({
|
|
76
|
+
find: pasteRegex,
|
|
77
|
+
type: this.type,
|
|
78
|
+
}),
|
|
71
79
|
];
|
|
72
80
|
},
|
|
73
81
|
});
|
|
@@ -1 +1 @@
|
|
|
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)((?:==)((?:[
|
|
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)((?:==)((?:[^~=]+))(?:==))$/\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))/g\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n addOptions() {\n return {\n multicolor: false,\n HTMLAttributes: {},\n }\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}; color: inherit`,\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(this.name, attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark(this.name)\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({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;AA+BO,MAAM,UAAU,GAAG,sCAAqC;AACxD,MAAM,UAAU,GAAG,sCAAqC;AAElD,MAAA,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;AACrD,IAAA,IAAI,EAAE,WAAW;IAEjB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,UAAU,EAAE,KAAK;AACjB,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,aAAa,GAAA;AACX,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;AAC5B,YAAA,OAAO,EAAE,CAAA;AACV,SAAA;QAED,OAAO;AACL,YAAA,KAAK,EAAE;AACL,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;gBACzF,UAAU,EAAE,UAAU,IAAG;AACvB,oBAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACrB,wBAAA,OAAO,EAAE,CAAA;AACV,qBAAA;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;AAC9B,wBAAA,KAAK,EAAE,CAAA,kBAAA,EAAqB,UAAU,CAAC,KAAK,CAAkB,gBAAA,CAAA;qBAC/D,CAAA;iBACF;AACF,aAAA;SACF,CAAA;KACF;IAED,SAAS,GAAA;QACP,OAAO;AACL,YAAA;AACE,gBAAA,GAAG,EAAE,MAAM;AACZ,aAAA;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;AAC3B,QAAA,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW,GAAA;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBAC3C,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;aAC/C;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBAC9C,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;aAClD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAI;gBACrC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACrC;SACF,CAAA;KACF;IAED,oBAAoB,GAAA;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAAC,kBAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAAC,kBAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;;;"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';
|
|
2
2
|
|
|
3
|
-
const inputRegex = /(?:^|\s)((?:==)((?:[
|
|
4
|
-
const pasteRegex = /(?:^|\s)((?:==)((?:[
|
|
3
|
+
const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
4
|
+
const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
5
5
|
const Highlight = Mark.create({
|
|
6
6
|
name: 'highlight',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
multicolor: false,
|
|
10
|
+
HTMLAttributes: {},
|
|
11
|
+
};
|
|
10
12
|
},
|
|
11
13
|
addAttributes() {
|
|
12
14
|
if (!this.options.multicolor) {
|
|
@@ -22,7 +24,7 @@ const Highlight = Mark.create({
|
|
|
22
24
|
}
|
|
23
25
|
return {
|
|
24
26
|
'data-color': attributes.color,
|
|
25
|
-
style: `background-color: ${attributes.color}`,
|
|
27
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
26
28
|
};
|
|
27
29
|
},
|
|
28
30
|
},
|
|
@@ -41,13 +43,13 @@ const Highlight = Mark.create({
|
|
|
41
43
|
addCommands() {
|
|
42
44
|
return {
|
|
43
45
|
setHighlight: attributes => ({ commands }) => {
|
|
44
|
-
return commands.setMark(
|
|
46
|
+
return commands.setMark(this.name, attributes);
|
|
45
47
|
},
|
|
46
48
|
toggleHighlight: attributes => ({ commands }) => {
|
|
47
|
-
return commands.toggleMark(
|
|
49
|
+
return commands.toggleMark(this.name, attributes);
|
|
48
50
|
},
|
|
49
51
|
unsetHighlight: () => ({ commands }) => {
|
|
50
|
-
return commands.unsetMark(
|
|
52
|
+
return commands.unsetMark(this.name);
|
|
51
53
|
},
|
|
52
54
|
};
|
|
53
55
|
},
|
|
@@ -58,12 +60,18 @@ const Highlight = Mark.create({
|
|
|
58
60
|
},
|
|
59
61
|
addInputRules() {
|
|
60
62
|
return [
|
|
61
|
-
markInputRule(
|
|
63
|
+
markInputRule({
|
|
64
|
+
find: inputRegex,
|
|
65
|
+
type: this.type,
|
|
66
|
+
}),
|
|
62
67
|
];
|
|
63
68
|
},
|
|
64
69
|
addPasteRules() {
|
|
65
70
|
return [
|
|
66
|
-
markPasteRule(
|
|
71
|
+
markPasteRule({
|
|
72
|
+
find: pasteRegex,
|
|
73
|
+
type: this.type,
|
|
74
|
+
}),
|
|
67
75
|
];
|
|
68
76
|
},
|
|
69
77
|
});
|
|
@@ -1 +1 @@
|
|
|
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)((?:==)((?:[
|
|
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)((?:==)((?:[^~=]+))(?:==))$/\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))/g\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n addOptions() {\n return {\n multicolor: false,\n HTMLAttributes: {},\n }\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}; color: inherit`,\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(this.name, attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark(this.name)\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({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"names":[],"mappings":";;AA+BO,MAAM,UAAU,GAAG,sCAAqC;AACxD,MAAM,UAAU,GAAG,sCAAqC;AAElD,MAAA,SAAS,GAAG,IAAI,CAAC,MAAM,CAAmB;AACrD,IAAA,IAAI,EAAE,WAAW;IAEjB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,UAAU,EAAE,KAAK;AACjB,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;IAED,aAAa,GAAA;AACX,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;AAC5B,YAAA,OAAO,EAAE,CAAA;AACV,SAAA;QAED,OAAO;AACL,YAAA,KAAK,EAAE;AACL,gBAAA,OAAO,EAAE,IAAI;AACb,gBAAA,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;gBACzF,UAAU,EAAE,UAAU,IAAG;AACvB,oBAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACrB,wBAAA,OAAO,EAAE,CAAA;AACV,qBAAA;oBAED,OAAO;wBACL,YAAY,EAAE,UAAU,CAAC,KAAK;AAC9B,wBAAA,KAAK,EAAE,CAAA,kBAAA,EAAqB,UAAU,CAAC,KAAK,CAAkB,gBAAA,CAAA;qBAC/D,CAAA;iBACF;AACF,aAAA;SACF,CAAA;KACF;IAED,SAAS,GAAA;QACP,OAAO;AACL,YAAA;AACE,gBAAA,GAAG,EAAE,MAAM;AACZ,aAAA;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;AAC3B,QAAA,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KACjF;IAED,WAAW,GAAA;QACT,OAAO;YACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBAC3C,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;aAC/C;YACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;gBAC9C,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;aAClD;YACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAI;gBACrC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACrC;SACF,CAAA;KACF;IAED,oBAAoB,GAAA;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;SAC5D,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAA,aAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;IAED,aAAa,GAAA;QACX,OAAO;AACL,YAAA,aAAa,CAAC;AACZ,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-highlight"] = {}, global.core));
|
|
5
5
|
})(this, (function (exports, core) { 'use strict';
|
|
6
6
|
|
|
7
|
-
const inputRegex = /(?:^|\s)((?:==)((?:[
|
|
8
|
-
const pasteRegex = /(?:^|\s)((?:==)((?:[
|
|
7
|
+
const inputRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))$/;
|
|
8
|
+
const pasteRegex = /(?:^|\s)((?:==)((?:[^~=]+))(?:==))/g;
|
|
9
9
|
const Highlight = core.Mark.create({
|
|
10
10
|
name: 'highlight',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
addOptions() {
|
|
12
|
+
return {
|
|
13
|
+
multicolor: false,
|
|
14
|
+
HTMLAttributes: {},
|
|
15
|
+
};
|
|
14
16
|
},
|
|
15
17
|
addAttributes() {
|
|
16
18
|
if (!this.options.multicolor) {
|
|
@@ -26,7 +28,7 @@
|
|
|
26
28
|
}
|
|
27
29
|
return {
|
|
28
30
|
'data-color': attributes.color,
|
|
29
|
-
style: `background-color: ${attributes.color}`,
|
|
31
|
+
style: `background-color: ${attributes.color}; color: inherit`,
|
|
30
32
|
};
|
|
31
33
|
},
|
|
32
34
|
},
|
|
@@ -45,13 +47,13 @@
|
|
|
45
47
|
addCommands() {
|
|
46
48
|
return {
|
|
47
49
|
setHighlight: attributes => ({ commands }) => {
|
|
48
|
-
return commands.setMark(
|
|
50
|
+
return commands.setMark(this.name, attributes);
|
|
49
51
|
},
|
|
50
52
|
toggleHighlight: attributes => ({ commands }) => {
|
|
51
|
-
return commands.toggleMark(
|
|
53
|
+
return commands.toggleMark(this.name, attributes);
|
|
52
54
|
},
|
|
53
55
|
unsetHighlight: () => ({ commands }) => {
|
|
54
|
-
return commands.unsetMark(
|
|
56
|
+
return commands.unsetMark(this.name);
|
|
55
57
|
},
|
|
56
58
|
};
|
|
57
59
|
},
|
|
@@ -62,12 +64,18 @@
|
|
|
62
64
|
},
|
|
63
65
|
addInputRules() {
|
|
64
66
|
return [
|
|
65
|
-
core.markInputRule(
|
|
67
|
+
core.markInputRule({
|
|
68
|
+
find: inputRegex,
|
|
69
|
+
type: this.type,
|
|
70
|
+
}),
|
|
66
71
|
];
|
|
67
72
|
},
|
|
68
73
|
addPasteRules() {
|
|
69
74
|
return [
|
|
70
|
-
core.markPasteRule(
|
|
75
|
+
core.markPasteRule({
|
|
76
|
+
find: pasteRegex,
|
|
77
|
+
type: this.type,
|
|
78
|
+
}),
|
|
71
79
|
];
|
|
72
80
|
},
|
|
73
81
|
});
|
|
@@ -1 +1 @@
|
|
|
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)((?:==)((?:[
|
|
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)((?:==)((?:[^~=]+))(?:==))$/\nexport const pasteRegex = /(?:^|\\s)((?:==)((?:[^~=]+))(?:==))/g\n\nexport const Highlight = Mark.create<HighlightOptions>({\n name: 'highlight',\n\n addOptions() {\n return {\n multicolor: false,\n HTMLAttributes: {},\n }\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}; color: inherit`,\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(this.name, attributes)\n },\n toggleHighlight: attributes => ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight: () => ({ commands }) => {\n return commands.unsetMark(this.name)\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({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"mappings":";;;;;;AA+BO,QAAM,UAAU,GAAG,sCAAqC;AACxD,QAAM,UAAU,GAAG,sCAAqC;AAElD,QAAA,SAAS,GAAGA,SAAI,CAAC,MAAM,CAAmB;EACrD,IAAA,IAAI,EAAE,WAAW;MAEjB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,UAAU,EAAE,KAAK;EACjB,YAAA,cAAc,EAAE,EAAE;WACnB,CAAA;OACF;MAED,aAAa,GAAA;EACX,QAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;EAC5B,YAAA,OAAO,EAAE,CAAA;EACV,SAAA;UAED,OAAO;EACL,YAAA,KAAK,EAAE;EACL,gBAAA,OAAO,EAAE,IAAI;EACb,gBAAA,SAAS,EAAE,OAAO,IAAI,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe;kBACzF,UAAU,EAAE,UAAU,IAAG;EACvB,oBAAA,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;EACrB,wBAAA,OAAO,EAAE,CAAA;EACV,qBAAA;sBAED,OAAO;0BACL,YAAY,EAAE,UAAU,CAAC,KAAK;EAC9B,wBAAA,KAAK,EAAE,CAAA,kBAAA,EAAqB,UAAU,CAAC,KAAK,CAAkB,gBAAA,CAAA;uBAC/D,CAAA;mBACF;EACF,aAAA;WACF,CAAA;OACF;MAED,SAAS,GAAA;UACP,OAAO;EACL,YAAA;EACE,gBAAA,GAAG,EAAE,MAAM;EACZ,aAAA;WACF,CAAA;OACF;MAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;EAC3B,QAAA,OAAO,CAAC,MAAM,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;OACjF;MAED,WAAW,GAAA;UACT,OAAO;cACL,YAAY,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;kBAC3C,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;eAC/C;cACD,eAAe,EAAE,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAI;kBAC9C,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;eAClD;cACD,cAAc,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,KAAI;kBACrC,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;eACrC;WACF,CAAA;OACF;MAED,oBAAoB,GAAA;UAClB,OAAO;cACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE;WAC5D,CAAA;OACF;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAAC,kBAAa,CAAC;EACZ,gBAAA,IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;eAChB,CAAC;WACH,CAAA;OACF;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAAC,kBAAa,CAAC;EACZ,gBAAA,IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;eAChB,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;;;"}
|
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.201",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -21,12 +21,11 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
24
|
+
"@tiptap/core": "^2.0.0-beta.193"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
28
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
29
29
|
"directory": "packages/extension-highlight"
|
|
30
|
-
}
|
|
31
|
-
"gitHead": "14f62dddb377701c9409495cc1a99922bb5f725f"
|
|
30
|
+
}
|
|
32
31
|
}
|
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.
|