Skip to content

Commit ce0c9e0

Browse files
authored
feat(core): make dynamic modifiers are public (#805)
1 parent d62b53a commit ce0c9e0

File tree

4 files changed

+31
-51
lines changed

4 files changed

+31
-51
lines changed

src/core/SchemaDynamicModifier.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import type {NodeSpec} from 'prosemirror-model';
22

33
export type TokenAttrs = {[name: string]: unknown};
44

5+
export interface NodeSpecProcessor {
6+
allowedAttrs?: string[];
7+
}
8+
9+
export interface SchemaDynamicModifierConfig {
10+
[elementType: string]: NodeSpecProcessor;
11+
}
12+
513
/**
614
* Class SchemaDynamicModifier
715
*
@@ -19,18 +27,6 @@ export type TokenAttrs = {[name: string]: unknown};
1927
* });
2028
* ```
2129
*/
22-
23-
/** @internal */
24-
export interface NodeSpecProcessor {
25-
allowedAttrs?: string[];
26-
}
27-
28-
/** @internal */
29-
export interface SchemaDynamicModifierConfig {
30-
[elementType: string]: NodeSpecProcessor;
31-
}
32-
33-
/** @internal */
3430
export class SchemaDynamicModifier {
3531
private nodeSpecsProcessors: Map<string, NodeSpecProcessor>;
3632

src/core/markdown/MarkdownParser.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,29 @@ function withoutTrailingNewline(str: string) {
374374
return str[str.length - 1] === '\n' || str.endsWith('\\n') ? str.slice(0, str.length - 1) : str;
375375
}
376376

377+
export type ProcessToken = (
378+
token: Token,
379+
index: number,
380+
rawMarkup: string,
381+
allowedAttrs?: string[],
382+
) => Token;
383+
export type ProcessNodeAttrs = (
384+
token: Token,
385+
attrs: TokenAttrs,
386+
allowedAttrs?: string[],
387+
) => TokenAttrs;
388+
export type ProcessNode = (node: Node) => Node;
389+
390+
export interface ElementProcessor {
391+
processToken?: ProcessToken[];
392+
processNodeAttrs?: ProcessNodeAttrs[];
393+
processNode?: ProcessNode[];
394+
}
395+
396+
export interface MarkdownParserDynamicModifierConfig {
397+
[elementType: string]: ElementProcessor;
398+
}
399+
377400
/**
378401
* Class MarkdownParserDynamicModifier
379402
*
@@ -425,34 +448,6 @@ function withoutTrailingNewline(str: string) {
425448
* - Modifying token metadata.
426449
* - Logging or customizing processing steps for debugging.
427450
*/
428-
429-
/** @internal */
430-
export type ProcessToken = (
431-
token: Token,
432-
index: number,
433-
rawMarkup: string,
434-
allowedAttrs?: string[],
435-
) => Token;
436-
export type ProcessNodeAttrs = (
437-
token: Token,
438-
attrs: TokenAttrs,
439-
allowedAttrs?: string[],
440-
) => TokenAttrs;
441-
export type ProcessNode = (node: Node) => Node;
442-
443-
/** @internal */
444-
export interface ElementProcessor {
445-
processToken?: ProcessToken[];
446-
processNodeAttrs?: ProcessNodeAttrs[];
447-
processNode?: ProcessNode[];
448-
}
449-
450-
/** @internal */
451-
export interface MarkdownParserDynamicModifierConfig {
452-
[elementType: string]: ElementProcessor;
453-
}
454-
455-
/** @internal */
456451
export class MarkdownParserDynamicModifier {
457452
private elementProcessors: Map<string, ElementProcessor>;
458453

src/core/markdown/MarkdownSerializerDynamicModifier.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type {Node} from 'prosemirror-model';
22

33
import type {SerializerNodeToken, SerializerState} from '../types/serializer';
44

5-
/** @internal */
65
export type SerializerProcessNode = (
76
state: SerializerState,
87
node: Node,
@@ -11,12 +10,10 @@ export type SerializerProcessNode = (
1110
callback?: SerializerNodeToken,
1211
) => void;
1312

14-
/** @internal */
1513
export interface SerializerNodeProcessor {
1614
processNode?: SerializerProcessNode[];
1715
}
1816

19-
/** @internal */
2017
export interface MarkdownSerializerDynamicModifierConfig {
2118
[nodeType: string]: SerializerNodeProcessor;
2219
}
@@ -47,8 +44,6 @@ export interface MarkdownSerializerDynamicModifierConfig {
4744
* - Customizing the serialization output.
4845
* - Logging or modifying node content during serialization.
4946
*/
50-
51-
/** @internal */
5247
export class MarkdownSerializerDynamicModifier {
5348
private nodeProcessors: Map<string, SerializerNodeProcessor>;
5449

src/core/types/dynamicModifiers.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
import type {ProcessNode, ProcessNodeAttrs, ProcessToken} from '../markdown/MarkdownParser';
22
import type {SerializerProcessNode} from '../markdown/MarkdownSerializerDynamicModifier';
33

4-
/** @internal */
54
export type DynamicModifiers =
65
| ParserTokenModifier
76
| ParserNodeAttrsModifier
87
| ParserNodeModifier
98
| SerializerNodeModifier
109
| SchemaNodeSpecModifier;
1110

12-
/** @internal */
1311
export type ParserTokenModifier = {
1412
type: 'parserToken';
1513
tokenName: string;
1614
process: ProcessToken;
1715
};
1816

19-
/** @internal */
2017
export type ParserNodeAttrsModifier = {
2118
type: 'parserNodeAttrs'; // TODO: fix name
2219
tokenName: string;
2320
process: ProcessNodeAttrs;
2421
};
2522

26-
/** @internal */
2723
export type ParserNodeModifier = {
2824
type: 'parserNode';
2925
nodeName: string;
3026
process: ProcessNode;
3127
};
3228

33-
/** @internal */
3429
export type SerializerNodeModifier = {
3530
type: 'serializerNode';
3631
nodeName: string;
3732
process: SerializerProcessNode;
3833
};
3934

40-
/** @internal */
4135
export type SchemaNodeSpecModifier = {
4236
type: 'schemaNodeSpec';
4337
nodeName: string;

0 commit comments

Comments
 (0)