@prosekit/extensions 0.1.5 → 0.1.6
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.
@@ -34,6 +34,11 @@ declare class AutocompleteRule {
|
|
34
34
|
export { AutocompleteRule }
|
35
35
|
export { AutocompleteRule as AutocompleteRule_alias_1 }
|
36
36
|
|
37
|
+
/**
|
38
|
+
* The attributes for the `codeBlock` node.
|
39
|
+
*
|
40
|
+
* @public
|
41
|
+
*/
|
37
42
|
declare interface CodeBlockAttrs {
|
38
43
|
language?: string;
|
39
44
|
}
|
@@ -108,15 +113,23 @@ toggleCode: [];
|
|
108
113
|
}>;
|
109
114
|
|
110
115
|
/**
|
116
|
+
* Adds `codeBlock` nodes to the editor. This includes the following extensions:
|
117
|
+
*
|
118
|
+
* - {@link defineCodeBlockSpec}
|
119
|
+
* - {@link defineCodeBlockInputRule}
|
120
|
+
* - {@link defineCodeBlockCommands}.
|
121
|
+
*
|
111
122
|
* @public
|
112
123
|
*/
|
113
124
|
export declare function defineCodeBlock(options?: {
|
114
125
|
/**
|
115
|
-
* @deprecated Use `
|
126
|
+
* @deprecated Use `defineCodeBlockHighlight` function instead.
|
116
127
|
*/
|
117
128
|
hljs?: HLJSApi;
|
118
129
|
/**
|
119
130
|
* A parser for the `prosemirror-highlight` package to use for syntax highlighting.
|
131
|
+
*
|
132
|
+
* @deprecated Use the standalone `defineCodeBlockHighlight` function instead.
|
120
133
|
*/
|
121
134
|
parser?: HighlightParser;
|
122
135
|
}): Extension< {
|
@@ -126,15 +139,32 @@ setCodeBlockLanguage: [language: string];
|
|
126
139
|
};
|
127
140
|
}>;
|
128
141
|
|
129
|
-
|
142
|
+
/**
|
143
|
+
* Adds commands for working with `codeBlock` nodes.
|
144
|
+
*
|
145
|
+
* @public
|
146
|
+
*/
|
147
|
+
declare function defineCodeBlockCommands(): Extension< {
|
130
148
|
COMMAND_ARGS: {
|
131
149
|
setCodeBlockLanguage: [language: string];
|
132
150
|
};
|
133
151
|
}>;
|
152
|
+
export { defineCodeBlockCommands }
|
153
|
+
export { defineCodeBlockCommands as defineCodeBlockCommands_alias_1 }
|
134
154
|
|
135
|
-
|
136
|
-
|
137
|
-
|
155
|
+
/**
|
156
|
+
* Adds syntax highlighting to code blocks. This function requires a `Parser`
|
157
|
+
* instance from the `prosemirror-highlight` package. See the
|
158
|
+
* [documentation](https://github.com/ocavue/prosemirror-highlight) for more
|
159
|
+
* information.
|
160
|
+
*
|
161
|
+
* @public
|
162
|
+
*/
|
163
|
+
declare function defineCodeBlockHighlight({ parser, }: {
|
164
|
+
parser: HighlightParser;
|
165
|
+
}): Extension;
|
166
|
+
export { defineCodeBlockHighlight }
|
167
|
+
export { defineCodeBlockHighlight as defineCodeBlockHighlight_alias_1 }
|
138
168
|
|
139
169
|
/**
|
140
170
|
* @deprecated
|
@@ -143,11 +173,25 @@ export declare function defineCodeBlockHighlightDeprecated(options: {
|
|
143
173
|
hljs?: HLJSApi;
|
144
174
|
}): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
145
175
|
|
146
|
-
|
176
|
+
/**
|
177
|
+
* Adds input rules for `codeBlock` nodes.
|
178
|
+
*
|
179
|
+
* @public
|
180
|
+
*/
|
181
|
+
declare function defineCodeBlockInputRule(): Extension<ExtensionTyping<string, string, CommandArgs>>;
|
182
|
+
export { defineCodeBlockInputRule }
|
183
|
+
export { defineCodeBlockInputRule as defineCodeBlockInputRule_alias_1 }
|
147
184
|
|
148
|
-
|
185
|
+
/**
|
186
|
+
* Defines the `codeBlock` node spec.
|
187
|
+
*
|
188
|
+
* @public
|
189
|
+
*/
|
190
|
+
declare function defineCodeBlockSpec(): Extension< {
|
149
191
|
NODES: "codeBlock";
|
150
192
|
}>;
|
193
|
+
export { defineCodeBlockSpec }
|
194
|
+
export { defineCodeBlockSpec as defineCodeBlockSpec_alias_1 }
|
151
195
|
|
152
196
|
export declare function defineCodeCommands(): Extension< {
|
153
197
|
COMMAND_ARGS: {
|
@@ -399,7 +443,9 @@ export declare interface HeadingAttrs {
|
|
399
443
|
*
|
400
444
|
* An alias for the `Parser` type from the `prosemirror-highlight` package.
|
401
445
|
*/
|
402
|
-
|
446
|
+
declare type HighlightParser = Parser;
|
447
|
+
export { HighlightParser }
|
448
|
+
export { HighlightParser as HighlightParser_alias_1 }
|
403
449
|
|
404
450
|
export declare interface ImageAttrs {
|
405
451
|
src?: string | null;
|
@@ -1,6 +1,7 @@
|
|
1
|
-
export { defineCodeBlockSpec } from './_tsup-dts-rollup';
|
2
|
-
export { defineCodeBlockInputRule } from './_tsup-dts-rollup';
|
3
|
-
export { defineCodeBlockCommands } from './_tsup-dts-rollup';
|
4
1
|
export { defineCodeBlock } from './_tsup-dts-rollup';
|
2
|
+
export { defineCodeBlockCommands_alias_1 as defineCodeBlockCommands } from './_tsup-dts-rollup';
|
3
|
+
export { defineCodeBlockHighlight_alias_1 as defineCodeBlockHighlight } from './_tsup-dts-rollup';
|
4
|
+
export { defineCodeBlockInputRule_alias_1 as defineCodeBlockInputRule } from './_tsup-dts-rollup';
|
5
|
+
export { defineCodeBlockSpec_alias_1 as defineCodeBlockSpec } from './_tsup-dts-rollup';
|
5
6
|
export { CodeBlockAttrs_alias_1 as CodeBlockAttrs } from './_tsup-dts-rollup';
|
6
|
-
export { HighlightParser } from './_tsup-dts-rollup';
|
7
|
+
export { HighlightParser_alias_1 as HighlightParser } from './_tsup-dts-rollup';
|
@@ -1,17 +1,30 @@
|
|
1
1
|
// src/code-block/index.ts
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
import { union } from "@prosekit/core";
|
3
|
+
|
4
|
+
// src/code-block/code-block-commands.ts
|
5
|
+
import { defineCommands } from "@prosekit/core";
|
6
|
+
function defineCodeBlockCommands() {
|
7
|
+
return defineCommands({
|
8
|
+
setCodeBlockLanguage: (language) => (state, dispatch) => {
|
9
|
+
const pos = state.selection.$from.before();
|
10
|
+
const codeBlock = state.doc.nodeAt(pos);
|
11
|
+
if (!codeBlock || codeBlock.type.name !== "codeBlock") {
|
12
|
+
return false;
|
13
|
+
}
|
14
|
+
const { tr } = state;
|
15
|
+
tr.setNodeMarkup(pos, void 0, { language });
|
16
|
+
dispatch == null ? void 0 : dispatch(tr);
|
17
|
+
return true;
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
10
21
|
|
11
22
|
// src/code-block/code-block-highlight.ts
|
12
23
|
import { definePlugin } from "@prosekit/core";
|
13
24
|
import { createHighlightPlugin } from "prosemirror-highlight";
|
14
|
-
function defineCodeBlockHighlight({
|
25
|
+
function defineCodeBlockHighlight({
|
26
|
+
parser
|
27
|
+
}) {
|
15
28
|
return definePlugin(
|
16
29
|
createHighlightPlugin({ parser, nodeTypes: ["codeBlock"] })
|
17
30
|
);
|
@@ -58,7 +71,21 @@ function languageExtractor(node) {
|
|
58
71
|
return node.attrs.language || "javascript";
|
59
72
|
}
|
60
73
|
|
61
|
-
// src/code-block/
|
74
|
+
// src/code-block/code-block-input-rule.ts
|
75
|
+
import { defineInputRule, getNodeType } from "@prosekit/core";
|
76
|
+
import { textblockTypeInputRule } from "@prosekit/pm/inputrules";
|
77
|
+
function defineCodeBlockInputRule() {
|
78
|
+
return defineInputRule(({ schema }) => {
|
79
|
+
const nodeType = getNodeType(schema, "codeBlock");
|
80
|
+
const getAttrs = (match) => {
|
81
|
+
return { language: match[1] || "" };
|
82
|
+
};
|
83
|
+
return textblockTypeInputRule(/^```(\S*)\s$/, nodeType, getAttrs);
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
// src/code-block/code-block-spec.ts
|
88
|
+
import { defineNodeSpec } from "@prosekit/core";
|
62
89
|
function defineCodeBlockSpec() {
|
63
90
|
return defineNodeSpec({
|
64
91
|
name: "codeBlock",
|
@@ -88,30 +115,8 @@ function defineCodeBlockSpec() {
|
|
88
115
|
}
|
89
116
|
});
|
90
117
|
}
|
91
|
-
|
92
|
-
|
93
|
-
const nodeType = getNodeType(schema, "codeBlock");
|
94
|
-
const getAttrs = (match) => {
|
95
|
-
return { language: match[1] || "" };
|
96
|
-
};
|
97
|
-
return textblockTypeInputRule(/^```(\S*)\s$/, nodeType, getAttrs);
|
98
|
-
});
|
99
|
-
}
|
100
|
-
function defineCodeBlockCommands() {
|
101
|
-
return defineCommands({
|
102
|
-
setCodeBlockLanguage: (language) => (state, dispatch) => {
|
103
|
-
const pos = state.selection.$from.before();
|
104
|
-
const codeBlock = state.doc.nodeAt(pos);
|
105
|
-
if (!codeBlock || codeBlock.type.name !== "codeBlock") {
|
106
|
-
return false;
|
107
|
-
}
|
108
|
-
const { tr } = state;
|
109
|
-
tr.setNodeMarkup(pos, void 0, { language });
|
110
|
-
dispatch == null ? void 0 : dispatch(tr);
|
111
|
-
return true;
|
112
|
-
}
|
113
|
-
});
|
114
|
-
}
|
118
|
+
|
119
|
+
// src/code-block/index.ts
|
115
120
|
function defineCodeBlock(options) {
|
116
121
|
const extensions = [
|
117
122
|
defineCodeBlockSpec(),
|
@@ -131,6 +136,7 @@ function defineCodeBlock(options) {
|
|
131
136
|
export {
|
132
137
|
defineCodeBlock,
|
133
138
|
defineCodeBlockCommands,
|
139
|
+
defineCodeBlockHighlight,
|
134
140
|
defineCodeBlockInputRule,
|
135
141
|
defineCodeBlockSpec
|
136
142
|
};
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/extensions",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.1.
|
4
|
+
"version": "0.1.6",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -121,18 +121,18 @@
|
|
121
121
|
"dist"
|
122
122
|
],
|
123
123
|
"dependencies": {
|
124
|
-
"@prosekit/core": "^0.1.
|
125
|
-
"@prosekit/pm": "^0.1.
|
124
|
+
"@prosekit/core": "^0.1.8",
|
125
|
+
"@prosekit/pm": "^0.1.1",
|
126
126
|
"highlight.js": "^11.9.0",
|
127
127
|
"prosemirror-flat-list": "^0.4.5",
|
128
|
-
"prosemirror-highlight": "^0.3.
|
128
|
+
"prosemirror-highlight": "^0.3.2",
|
129
129
|
"prosemirror-highlightjs": "^0.9.1"
|
130
130
|
},
|
131
131
|
"devDependencies": {
|
132
132
|
"@prosekit/dev": "*",
|
133
133
|
"tsup": "^8.0.1",
|
134
134
|
"typescript": "^5.3.3",
|
135
|
-
"vitest": "^1.0.
|
135
|
+
"vitest": "^1.0.4"
|
136
136
|
},
|
137
137
|
"scripts": {
|
138
138
|
"build:tsup": "tsup",
|