@tiptap/extension-highlight 3.20.2 → 3.20.3
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/package.json +3 -3
- package/dist/index.cjs +0 -141
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -58
- package/dist/index.d.ts +0 -58
- package/dist/index.js +0 -112
- package/dist/index.js.map +0 -1
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": "3.20.
|
|
4
|
+
"version": "3.20.3",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tiptap/core": "^3.20.
|
|
34
|
+
"@tiptap/core": "^3.20.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@tiptap/core": "^3.20.
|
|
37
|
+
"@tiptap/core": "^3.20.3"
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
package/dist/index.cjs
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
Highlight: () => Highlight,
|
|
24
|
-
default: () => index_default,
|
|
25
|
-
inputRegex: () => inputRegex,
|
|
26
|
-
pasteRegex: () => pasteRegex
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
|
-
// src/highlight.ts
|
|
31
|
-
var import_core = require("@tiptap/core");
|
|
32
|
-
var inputRegex = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/;
|
|
33
|
-
var pasteRegex = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g;
|
|
34
|
-
var Highlight = import_core.Mark.create({
|
|
35
|
-
name: "highlight",
|
|
36
|
-
addOptions() {
|
|
37
|
-
return {
|
|
38
|
-
multicolor: false,
|
|
39
|
-
HTMLAttributes: {}
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
addAttributes() {
|
|
43
|
-
if (!this.options.multicolor) {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
color: {
|
|
48
|
-
default: null,
|
|
49
|
-
parseHTML: (element) => element.getAttribute("data-color") || element.style.backgroundColor,
|
|
50
|
-
renderHTML: (attributes) => {
|
|
51
|
-
if (!attributes.color) {
|
|
52
|
-
return {};
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
"data-color": attributes.color,
|
|
56
|
-
style: `background-color: ${attributes.color}; color: inherit`
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
parseHTML() {
|
|
63
|
-
return [
|
|
64
|
-
{
|
|
65
|
-
tag: "mark"
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
},
|
|
69
|
-
renderHTML({ HTMLAttributes }) {
|
|
70
|
-
return ["mark", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
71
|
-
},
|
|
72
|
-
renderMarkdown: (node, h) => {
|
|
73
|
-
return `==${h.renderChildren(node)}==`;
|
|
74
|
-
},
|
|
75
|
-
parseMarkdown: (token, h) => {
|
|
76
|
-
return h.applyMark("highlight", h.parseInline(token.tokens || []));
|
|
77
|
-
},
|
|
78
|
-
markdownTokenizer: {
|
|
79
|
-
name: "highlight",
|
|
80
|
-
level: "inline",
|
|
81
|
-
start: (src) => src.indexOf("=="),
|
|
82
|
-
tokenize(src, _, h) {
|
|
83
|
-
const rule = /^(==)([^=]+)(==)/;
|
|
84
|
-
const match = rule.exec(src);
|
|
85
|
-
if (match) {
|
|
86
|
-
const innerContent = match[2].trim();
|
|
87
|
-
const children = h.inlineTokens(innerContent);
|
|
88
|
-
return {
|
|
89
|
-
type: "highlight",
|
|
90
|
-
raw: match[0],
|
|
91
|
-
text: innerContent,
|
|
92
|
-
tokens: children
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
addCommands() {
|
|
98
|
-
return {
|
|
99
|
-
setHighlight: (attributes) => ({ commands }) => {
|
|
100
|
-
return commands.setMark(this.name, attributes);
|
|
101
|
-
},
|
|
102
|
-
toggleHighlight: (attributes) => ({ commands }) => {
|
|
103
|
-
return commands.toggleMark(this.name, attributes);
|
|
104
|
-
},
|
|
105
|
-
unsetHighlight: () => ({ commands }) => {
|
|
106
|
-
return commands.unsetMark(this.name);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
addKeyboardShortcuts() {
|
|
111
|
-
return {
|
|
112
|
-
"Mod-Shift-h": () => this.editor.commands.toggleHighlight()
|
|
113
|
-
};
|
|
114
|
-
},
|
|
115
|
-
addInputRules() {
|
|
116
|
-
return [
|
|
117
|
-
(0, import_core.markInputRule)({
|
|
118
|
-
find: inputRegex,
|
|
119
|
-
type: this.type
|
|
120
|
-
})
|
|
121
|
-
];
|
|
122
|
-
},
|
|
123
|
-
addPasteRules() {
|
|
124
|
-
return [
|
|
125
|
-
(0, import_core.markPasteRule)({
|
|
126
|
-
find: pasteRegex,
|
|
127
|
-
type: this.type
|
|
128
|
-
})
|
|
129
|
-
];
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// src/index.ts
|
|
134
|
-
var index_default = Highlight;
|
|
135
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
-
0 && (module.exports = {
|
|
137
|
-
Highlight,
|
|
138
|
-
inputRegex,
|
|
139
|
-
pasteRegex
|
|
140
|
-
});
|
|
141
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/highlight.ts"],"sourcesContent":["import { Highlight } from './highlight.js'\n\nexport * from './highlight.js'\n\nexport default Highlight\n","import { Mark, markInputRule, markPasteRule, mergeAttributes } from '@tiptap/core'\n\nexport interface HighlightOptions {\n /**\n * Allow multiple highlight colors\n * @default false\n * @example true\n */\n multicolor: boolean\n\n /**\n * HTML attributes to add to the highlight element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n * @param attributes The highlight attributes\n * @example editor.commands.setHighlight({ color: 'red' })\n */\n setHighlight: (attributes?: { color: string }) => ReturnType\n /**\n * Toggle a highlight mark\n * @param attributes The highlight attributes\n * @example editor.commands.toggleHighlight({ color: 'red' })\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType\n /**\n * Unset a highlight mark\n * @example editor.commands.unsetHighlight()\n */\n unsetHighlight: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a highlight to a ==highlight== on input.\n */\nexport const inputRegex = /(?:^|\\s)(==(?!\\s+==)((?:[^=]+))==(?!\\s+==))$/\n\n/**\n * Matches a highlight to a ==highlight== on paste.\n */\nexport const pasteRegex = /(?:^|\\s)(==(?!\\s+==)((?:[^=]+))==(?!\\s+==))/g\n\n/**\n * This extension allows you to highlight text.\n * @see https://www.tiptap.dev/api/marks/highlight\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 renderMarkdown: (node, h) => {\n return `==${h.renderChildren(node)}==`\n },\n\n parseMarkdown: (token, h) => {\n return h.applyMark('highlight', h.parseInline(token.tokens || []))\n },\n\n markdownTokenizer: {\n name: 'highlight',\n level: 'inline',\n start: (src: string) => src.indexOf('=='),\n tokenize(src, _, h) {\n const rule = /^(==)([^=]+)(==)/ // ==highlighted text==\n const match = rule.exec(src)\n\n if (match) {\n const innerContent = match[2].trim()\n\n const children = h.inlineTokens(innerContent)\n\n return {\n type: 'highlight',\n raw: match[0],\n text: innerContent,\n tokens: children,\n }\n }\n },\n },\n\n addCommands() {\n return {\n setHighlight:\n attributes =>\n ({ commands }) => {\n return commands.setMark(this.name, attributes)\n },\n toggleHighlight:\n attributes =>\n ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight:\n () =>\n ({ 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAoE;AA6C7D,IAAM,aAAa;AAKnB,IAAM,aAAa;AAMnB,IAAM,YAAY,iBAAK,OAAyB;AAAA,EACrD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,QAAI,CAAC,KAAK,QAAQ,YAAY;AAC5B,aAAO,CAAC;AAAA,IACV;AAEA,WAAO;AAAA,MACL,OAAO;AAAA,QACL,SAAS;AAAA,QACT,WAAW,aAAW,QAAQ,aAAa,YAAY,KAAK,QAAQ,MAAM;AAAA,QAC1E,YAAY,gBAAc;AACxB,cAAI,CAAC,WAAW,OAAO;AACrB,mBAAO,CAAC;AAAA,UACV;AAEA,iBAAO;AAAA,YACL,cAAc,WAAW;AAAA,YACzB,OAAO,qBAAqB,WAAW,KAAK;AAAA,UAC9C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO;AAAA,MACL;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,YAAQ,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG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A,IACH;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,UACL,2BAAc;AAAA,QACZ,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AD3KD,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Mark } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
interface HighlightOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Allow multiple highlight colors
|
|
6
|
-
* @default false
|
|
7
|
-
* @example true
|
|
8
|
-
*/
|
|
9
|
-
multicolor: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* HTML attributes to add to the highlight element.
|
|
12
|
-
* @default {}
|
|
13
|
-
* @example { class: 'foo' }
|
|
14
|
-
*/
|
|
15
|
-
HTMLAttributes: Record<string, any>;
|
|
16
|
-
}
|
|
17
|
-
declare module '@tiptap/core' {
|
|
18
|
-
interface Commands<ReturnType> {
|
|
19
|
-
highlight: {
|
|
20
|
-
/**
|
|
21
|
-
* Set a highlight mark
|
|
22
|
-
* @param attributes The highlight attributes
|
|
23
|
-
* @example editor.commands.setHighlight({ color: 'red' })
|
|
24
|
-
*/
|
|
25
|
-
setHighlight: (attributes?: {
|
|
26
|
-
color: string;
|
|
27
|
-
}) => ReturnType;
|
|
28
|
-
/**
|
|
29
|
-
* Toggle a highlight mark
|
|
30
|
-
* @param attributes The highlight attributes
|
|
31
|
-
* @example editor.commands.toggleHighlight({ color: 'red' })
|
|
32
|
-
*/
|
|
33
|
-
toggleHighlight: (attributes?: {
|
|
34
|
-
color: string;
|
|
35
|
-
}) => ReturnType;
|
|
36
|
-
/**
|
|
37
|
-
* Unset a highlight mark
|
|
38
|
-
* @example editor.commands.unsetHighlight()
|
|
39
|
-
*/
|
|
40
|
-
unsetHighlight: () => ReturnType;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Matches a highlight to a ==highlight== on input.
|
|
46
|
-
*/
|
|
47
|
-
declare const inputRegex: RegExp;
|
|
48
|
-
/**
|
|
49
|
-
* Matches a highlight to a ==highlight== on paste.
|
|
50
|
-
*/
|
|
51
|
-
declare const pasteRegex: RegExp;
|
|
52
|
-
/**
|
|
53
|
-
* This extension allows you to highlight text.
|
|
54
|
-
* @see https://www.tiptap.dev/api/marks/highlight
|
|
55
|
-
*/
|
|
56
|
-
declare const Highlight: Mark<HighlightOptions, any>;
|
|
57
|
-
|
|
58
|
-
export { Highlight, type HighlightOptions, Highlight as default, inputRegex, pasteRegex };
|
package/dist/index.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Mark } from '@tiptap/core';
|
|
2
|
-
|
|
3
|
-
interface HighlightOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Allow multiple highlight colors
|
|
6
|
-
* @default false
|
|
7
|
-
* @example true
|
|
8
|
-
*/
|
|
9
|
-
multicolor: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* HTML attributes to add to the highlight element.
|
|
12
|
-
* @default {}
|
|
13
|
-
* @example { class: 'foo' }
|
|
14
|
-
*/
|
|
15
|
-
HTMLAttributes: Record<string, any>;
|
|
16
|
-
}
|
|
17
|
-
declare module '@tiptap/core' {
|
|
18
|
-
interface Commands<ReturnType> {
|
|
19
|
-
highlight: {
|
|
20
|
-
/**
|
|
21
|
-
* Set a highlight mark
|
|
22
|
-
* @param attributes The highlight attributes
|
|
23
|
-
* @example editor.commands.setHighlight({ color: 'red' })
|
|
24
|
-
*/
|
|
25
|
-
setHighlight: (attributes?: {
|
|
26
|
-
color: string;
|
|
27
|
-
}) => ReturnType;
|
|
28
|
-
/**
|
|
29
|
-
* Toggle a highlight mark
|
|
30
|
-
* @param attributes The highlight attributes
|
|
31
|
-
* @example editor.commands.toggleHighlight({ color: 'red' })
|
|
32
|
-
*/
|
|
33
|
-
toggleHighlight: (attributes?: {
|
|
34
|
-
color: string;
|
|
35
|
-
}) => ReturnType;
|
|
36
|
-
/**
|
|
37
|
-
* Unset a highlight mark
|
|
38
|
-
* @example editor.commands.unsetHighlight()
|
|
39
|
-
*/
|
|
40
|
-
unsetHighlight: () => ReturnType;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Matches a highlight to a ==highlight== on input.
|
|
46
|
-
*/
|
|
47
|
-
declare const inputRegex: RegExp;
|
|
48
|
-
/**
|
|
49
|
-
* Matches a highlight to a ==highlight== on paste.
|
|
50
|
-
*/
|
|
51
|
-
declare const pasteRegex: RegExp;
|
|
52
|
-
/**
|
|
53
|
-
* This extension allows you to highlight text.
|
|
54
|
-
* @see https://www.tiptap.dev/api/marks/highlight
|
|
55
|
-
*/
|
|
56
|
-
declare const Highlight: Mark<HighlightOptions, any>;
|
|
57
|
-
|
|
58
|
-
export { Highlight, type HighlightOptions, Highlight as default, inputRegex, pasteRegex };
|
package/dist/index.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// src/highlight.ts
|
|
2
|
-
import { Mark, markInputRule, markPasteRule, mergeAttributes } from "@tiptap/core";
|
|
3
|
-
var inputRegex = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))$/;
|
|
4
|
-
var pasteRegex = /(?:^|\s)(==(?!\s+==)((?:[^=]+))==(?!\s+==))/g;
|
|
5
|
-
var Highlight = Mark.create({
|
|
6
|
-
name: "highlight",
|
|
7
|
-
addOptions() {
|
|
8
|
-
return {
|
|
9
|
-
multicolor: false,
|
|
10
|
-
HTMLAttributes: {}
|
|
11
|
-
};
|
|
12
|
-
},
|
|
13
|
-
addAttributes() {
|
|
14
|
-
if (!this.options.multicolor) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
color: {
|
|
19
|
-
default: null,
|
|
20
|
-
parseHTML: (element) => element.getAttribute("data-color") || element.style.backgroundColor,
|
|
21
|
-
renderHTML: (attributes) => {
|
|
22
|
-
if (!attributes.color) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
"data-color": attributes.color,
|
|
27
|
-
style: `background-color: ${attributes.color}; color: inherit`
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
parseHTML() {
|
|
34
|
-
return [
|
|
35
|
-
{
|
|
36
|
-
tag: "mark"
|
|
37
|
-
}
|
|
38
|
-
];
|
|
39
|
-
},
|
|
40
|
-
renderHTML({ HTMLAttributes }) {
|
|
41
|
-
return ["mark", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
42
|
-
},
|
|
43
|
-
renderMarkdown: (node, h) => {
|
|
44
|
-
return `==${h.renderChildren(node)}==`;
|
|
45
|
-
},
|
|
46
|
-
parseMarkdown: (token, h) => {
|
|
47
|
-
return h.applyMark("highlight", h.parseInline(token.tokens || []));
|
|
48
|
-
},
|
|
49
|
-
markdownTokenizer: {
|
|
50
|
-
name: "highlight",
|
|
51
|
-
level: "inline",
|
|
52
|
-
start: (src) => src.indexOf("=="),
|
|
53
|
-
tokenize(src, _, h) {
|
|
54
|
-
const rule = /^(==)([^=]+)(==)/;
|
|
55
|
-
const match = rule.exec(src);
|
|
56
|
-
if (match) {
|
|
57
|
-
const innerContent = match[2].trim();
|
|
58
|
-
const children = h.inlineTokens(innerContent);
|
|
59
|
-
return {
|
|
60
|
-
type: "highlight",
|
|
61
|
-
raw: match[0],
|
|
62
|
-
text: innerContent,
|
|
63
|
-
tokens: children
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
addCommands() {
|
|
69
|
-
return {
|
|
70
|
-
setHighlight: (attributes) => ({ commands }) => {
|
|
71
|
-
return commands.setMark(this.name, attributes);
|
|
72
|
-
},
|
|
73
|
-
toggleHighlight: (attributes) => ({ commands }) => {
|
|
74
|
-
return commands.toggleMark(this.name, attributes);
|
|
75
|
-
},
|
|
76
|
-
unsetHighlight: () => ({ commands }) => {
|
|
77
|
-
return commands.unsetMark(this.name);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
addKeyboardShortcuts() {
|
|
82
|
-
return {
|
|
83
|
-
"Mod-Shift-h": () => this.editor.commands.toggleHighlight()
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
addInputRules() {
|
|
87
|
-
return [
|
|
88
|
-
markInputRule({
|
|
89
|
-
find: inputRegex,
|
|
90
|
-
type: this.type
|
|
91
|
-
})
|
|
92
|
-
];
|
|
93
|
-
},
|
|
94
|
-
addPasteRules() {
|
|
95
|
-
return [
|
|
96
|
-
markPasteRule({
|
|
97
|
-
find: pasteRegex,
|
|
98
|
-
type: this.type
|
|
99
|
-
})
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// src/index.ts
|
|
105
|
-
var index_default = Highlight;
|
|
106
|
-
export {
|
|
107
|
-
Highlight,
|
|
108
|
-
index_default as default,
|
|
109
|
-
inputRegex,
|
|
110
|
-
pasteRegex
|
|
111
|
-
};
|
|
112
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/highlight.ts","../src/index.ts"],"sourcesContent":["import { Mark, markInputRule, markPasteRule, mergeAttributes } from '@tiptap/core'\n\nexport interface HighlightOptions {\n /**\n * Allow multiple highlight colors\n * @default false\n * @example true\n */\n multicolor: boolean\n\n /**\n * HTML attributes to add to the highlight element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n highlight: {\n /**\n * Set a highlight mark\n * @param attributes The highlight attributes\n * @example editor.commands.setHighlight({ color: 'red' })\n */\n setHighlight: (attributes?: { color: string }) => ReturnType\n /**\n * Toggle a highlight mark\n * @param attributes The highlight attributes\n * @example editor.commands.toggleHighlight({ color: 'red' })\n */\n toggleHighlight: (attributes?: { color: string }) => ReturnType\n /**\n * Unset a highlight mark\n * @example editor.commands.unsetHighlight()\n */\n unsetHighlight: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a highlight to a ==highlight== on input.\n */\nexport const inputRegex = /(?:^|\\s)(==(?!\\s+==)((?:[^=]+))==(?!\\s+==))$/\n\n/**\n * Matches a highlight to a ==highlight== on paste.\n */\nexport const pasteRegex = /(?:^|\\s)(==(?!\\s+==)((?:[^=]+))==(?!\\s+==))/g\n\n/**\n * This extension allows you to highlight text.\n * @see https://www.tiptap.dev/api/marks/highlight\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 renderMarkdown: (node, h) => {\n return `==${h.renderChildren(node)}==`\n },\n\n parseMarkdown: (token, h) => {\n return h.applyMark('highlight', h.parseInline(token.tokens || []))\n },\n\n markdownTokenizer: {\n name: 'highlight',\n level: 'inline',\n start: (src: string) => src.indexOf('=='),\n tokenize(src, _, h) {\n const rule = /^(==)([^=]+)(==)/ // ==highlighted text==\n const match = rule.exec(src)\n\n if (match) {\n const innerContent = match[2].trim()\n\n const children = h.inlineTokens(innerContent)\n\n return {\n type: 'highlight',\n raw: match[0],\n text: innerContent,\n tokens: children,\n }\n }\n },\n },\n\n addCommands() {\n return {\n setHighlight:\n attributes =>\n ({ commands }) => {\n return commands.setMark(this.name, attributes)\n },\n toggleHighlight:\n attributes =>\n ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n unsetHighlight:\n () =>\n ({ 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","import { Highlight } from './highlight.js'\n\nexport * from './highlight.js'\n\nexport default Highlight\n"],"mappings":";AAAA,SAAS,MAAM,eAAe,eAAe,uBAAuB;AA6C7D,IAAM,aAAa;AAKnB,IAAM,aAAa;AAMnB,IAAM,YAAY,KAAK,OAAyB;AAAA,EACrD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,QAAI,CAAC,KAAK,QAAQ,YAAY;AAC5B,aAAO,CAAC;AAAA,IACV;AAEA,WAAO;AAAA,MACL,OAAO;AAAA,QACL,SAAS;AAAA,QACT,WAAW,aAAW,QAAQ,aAAa,YAAY,KAAK,QAAQ,MAAM;AAAA,QAC1E,YAAY,gBAAc;AACxB,cAAI,CAAC,WAAW,OAAO;AACrB,mBAAO,CAAC;AAAA,UACV;AAEA,iBAAO;AAAA,YACL,cAAc,WAAW;AAAA,YACzB,OAAO,qBAAqB,WAAW,KAAK;AAAA,UAC9C;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY;AACV,WAAO;AAAA,MACL;AAAA,QACE,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW,EAAE,eAAe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