@principal-ade/industry-themed-mdx-editor 0.1.2 → 0.1.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/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +364 -1
- package/dist/src/components/ThemedMDXEditor.d.ts +1 -0
- package/dist/src/components/ThemedMDXEditor.d.ts.map +1 -1
- package/dist/src/plugins/mdx-auto-fix/index.d.ts +7 -0
- package/dist/src/plugins/mdx-auto-fix/index.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/plugin.d.ts +12 -0
- package/dist/src/plugins/mdx-auto-fix/plugin.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/preprocessor.d.ts +17 -0
- package/dist/src/plugins/mdx-auto-fix/preprocessor.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/greater-than-digit.d.ts +3 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/greater-than-digit.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/index.d.ts +7 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/index.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/invalid-tag-names.d.ts +3 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/invalid-tag-names.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/less-than-digit.d.ts +3 -0
- package/dist/src/plugins/mdx-auto-fix/transformers/less-than-digit.d.ts.map +1 -0
- package/dist/src/plugins/mdx-auto-fix/types.d.ts +24 -0
- package/dist/src/plugins/mdx-auto-fix/types.d.ts.map +1 -0
- package/package.json +8 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { ThemedMDXEditorWithProvider } from './src/components/ThemedMDXEditorWit
|
|
|
4
4
|
export type { ThemedMDXEditorWithProviderProps } from './src/components/ThemedMDXEditorWithProvider';
|
|
5
5
|
export { useThemedMDXEditor } from './src/hooks/useThemedMDXEditor';
|
|
6
6
|
export { createCodeMirrorTheme, createAutoCodeMirrorTheme } from './src/utils/codeMirrorTheme';
|
|
7
|
+
export { preprocessMDX, defaultPreprocessRules, mdxAutoFix, lessThanDigitTransformer, greaterThanDigitTransformer, invalidTagNamesTransformer, defaultTransformers, allTransformers, } from './src/plugins/mdx-auto-fix';
|
|
8
|
+
export type { PreprocessRule, MDXAutoFixOptions, Transformer, TransformerContext, TransformerStats, TransformerTestCase, } from './src/plugins/mdx-auto-fix';
|
|
7
9
|
export type { Theme } from '@a24z/industry-theme';
|
|
8
10
|
export type { MDXEditorMethods, MDXEditorProps } from '@mdxeditor/editor';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAE9F,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,YAAY,EAAE,gCAAgC,EAAE,MAAM,8CAA8C,CAAC;AAGrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGpE,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAE9F,OAAO,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAC3F,YAAY,EAAE,gCAAgC,EAAE,MAAM,8CAA8C,CAAC;AAGrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAGpE,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,UAAU,EACV,wBAAwB,EACxB,2BAA2B,EAC3B,0BAA0B,EAC1B,mBAAmB,EACnB,eAAe,GAChB,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AAGpC,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,352 @@ import {
|
|
|
3
3
|
MDXEditor
|
|
4
4
|
} from "@mdxeditor/editor";
|
|
5
5
|
import "@mdxeditor/editor/style.css";
|
|
6
|
+
|
|
7
|
+
// src/plugins/mdx-auto-fix/preprocessor.ts
|
|
8
|
+
var defaultPreprocessRules = [
|
|
9
|
+
{
|
|
10
|
+
name: "less-than-digit",
|
|
11
|
+
description: "Escape < followed by digit",
|
|
12
|
+
pattern: /<(?=\d)/g,
|
|
13
|
+
replacement: "<"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "less-than-space-digit",
|
|
17
|
+
description: "Escape < followed by space and digit",
|
|
18
|
+
pattern: /<(\s+)(?=\d)/g,
|
|
19
|
+
replacement: (_match, spaces) => `<${spaces}`
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "greater-than-digit",
|
|
23
|
+
description: "Escape > followed by digit",
|
|
24
|
+
pattern: /(?<![-\w])>(?=\s?\d)/g,
|
|
25
|
+
replacement: ">"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "invalid-tag-opening",
|
|
29
|
+
description: "Escape invalid opening tags starting with digit",
|
|
30
|
+
pattern: /<(\/?(?:\d[^>\s]*))/g,
|
|
31
|
+
replacement: (_match, tagContent) => `<${tagContent}`
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "numeric-only-tag",
|
|
35
|
+
description: "Escape tags that are only numbers",
|
|
36
|
+
pattern: /<(\d+)>/g,
|
|
37
|
+
replacement: (_match, number) => `<${number}>`
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
function preserveCode(markdown, transform) {
|
|
41
|
+
const parts = [];
|
|
42
|
+
const codeRegex = /(```[\s\S]*?```|`[^`\n]+`)/g;
|
|
43
|
+
let lastIndex = 0;
|
|
44
|
+
let match;
|
|
45
|
+
while ((match = codeRegex.exec(markdown)) !== null) {
|
|
46
|
+
if (match.index > lastIndex) {
|
|
47
|
+
parts.push({
|
|
48
|
+
type: "text",
|
|
49
|
+
content: markdown.slice(lastIndex, match.index)
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
parts.push({
|
|
53
|
+
type: "code",
|
|
54
|
+
content: match[0]
|
|
55
|
+
});
|
|
56
|
+
lastIndex = match.index + match[0].length;
|
|
57
|
+
}
|
|
58
|
+
if (lastIndex < markdown.length) {
|
|
59
|
+
parts.push({
|
|
60
|
+
type: "text",
|
|
61
|
+
content: markdown.slice(lastIndex)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return parts.map((part) => part.type === "code" ? part.content : transform(part.content)).join("");
|
|
65
|
+
}
|
|
66
|
+
function preprocessMDX(markdown, options = {}) {
|
|
67
|
+
const {
|
|
68
|
+
rules = defaultPreprocessRules,
|
|
69
|
+
enable,
|
|
70
|
+
disable,
|
|
71
|
+
preserveCodeBlocks = true,
|
|
72
|
+
onStats,
|
|
73
|
+
debug = false
|
|
74
|
+
} = options;
|
|
75
|
+
let activeRules = rules;
|
|
76
|
+
if (enable && enable.length > 0) {
|
|
77
|
+
activeRules = rules.filter((r) => enable.includes(r.name));
|
|
78
|
+
}
|
|
79
|
+
if (disable && disable.length > 0) {
|
|
80
|
+
activeRules = activeRules.filter((r) => !disable.includes(r.name));
|
|
81
|
+
}
|
|
82
|
+
if (debug) {
|
|
83
|
+
console.log("[mdx-auto-fix] Active preprocessing rules:", activeRules.map((r) => r.name));
|
|
84
|
+
}
|
|
85
|
+
const stats = {
|
|
86
|
+
totalFixes: 0,
|
|
87
|
+
byTransformer: {}
|
|
88
|
+
};
|
|
89
|
+
const transform = (text) => {
|
|
90
|
+
let result2 = text;
|
|
91
|
+
for (const rule of activeRules) {
|
|
92
|
+
let fixCount = 0;
|
|
93
|
+
if (typeof rule.replacement === "function") {
|
|
94
|
+
result2 = result2.replace(rule.pattern, (...args) => {
|
|
95
|
+
fixCount++;
|
|
96
|
+
return rule.replacement(...args);
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
result2 = result2.replace(rule.pattern, () => {
|
|
100
|
+
fixCount++;
|
|
101
|
+
return rule.replacement;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (fixCount > 0) {
|
|
105
|
+
stats.byTransformer[rule.name] = (stats.byTransformer[rule.name] || 0) + fixCount;
|
|
106
|
+
stats.totalFixes += fixCount;
|
|
107
|
+
if (debug) {
|
|
108
|
+
console.log(`[mdx-auto-fix] ${rule.name}: ${fixCount} fixes`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result2;
|
|
113
|
+
};
|
|
114
|
+
const result = preserveCodeBlocks ? preserveCode(markdown, transform) : transform(markdown);
|
|
115
|
+
if (onStats && stats.totalFixes > 0) {
|
|
116
|
+
onStats(stats);
|
|
117
|
+
}
|
|
118
|
+
if (debug && stats.totalFixes > 0) {
|
|
119
|
+
console.log(`[mdx-auto-fix] Total preprocessing fixes: ${stats.totalFixes}`);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/plugins/mdx-auto-fix/transformers/less-than-digit.ts
|
|
125
|
+
import { visit } from "unist-util-visit";
|
|
126
|
+
var lessThanDigitTransformer = {
|
|
127
|
+
name: "less-than-digit",
|
|
128
|
+
description: 'Escapes < when followed by a digit (e.g., "<5 minutes" \u2192 "<5 minutes")',
|
|
129
|
+
defaultEnabled: true,
|
|
130
|
+
transform: (context) => {
|
|
131
|
+
let fixCount = 0;
|
|
132
|
+
visit(context.tree, "text", (node) => {
|
|
133
|
+
node.value = node.value.replace(/<(?=\d)/g, () => {
|
|
134
|
+
fixCount++;
|
|
135
|
+
return "<";
|
|
136
|
+
});
|
|
137
|
+
node.value = node.value.replace(/<\s+(?=\d)/g, (match) => {
|
|
138
|
+
fixCount++;
|
|
139
|
+
return match.replace("<", "<");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
context.stats.byTransformer[lessThanDigitTransformer.name] = fixCount;
|
|
143
|
+
context.stats.totalFixes += fixCount;
|
|
144
|
+
},
|
|
145
|
+
testCases: [
|
|
146
|
+
{
|
|
147
|
+
description: "Basic less-than with digit",
|
|
148
|
+
input: "- <5 minutes to complete",
|
|
149
|
+
expected: "- <5 minutes to complete",
|
|
150
|
+
shouldFix: "Should escape < immediately followed by digit"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
description: "Less-than with space and digit",
|
|
154
|
+
input: "- < 5 minutes to complete",
|
|
155
|
+
expected: "- < 5 minutes to complete",
|
|
156
|
+
shouldFix: "Should escape < followed by space and digit"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
description: "Multiple occurrences",
|
|
160
|
+
input: "Metrics: <5ms latency, <10MB memory, <2% error rate",
|
|
161
|
+
expected: "Metrics: <5ms latency, <10MB memory, <2% error rate",
|
|
162
|
+
shouldFix: "Should fix all occurrences in a line"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
description: "Percentage comparisons",
|
|
166
|
+
input: "- <5% configuration error rate",
|
|
167
|
+
expected: "- <5% configuration error rate",
|
|
168
|
+
shouldFix: "Should fix percentage comparisons"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
description: "Size comparisons",
|
|
172
|
+
input: "Bundle size: <20MB",
|
|
173
|
+
expected: "Bundle size: <20MB",
|
|
174
|
+
shouldFix: "Should fix size comparisons"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
description: "Time estimates in lists",
|
|
178
|
+
input: `**Target**:
|
|
179
|
+
- 90%+ setup completion rate
|
|
180
|
+
- <5 minutes to first workflow
|
|
181
|
+
- <5% configuration error rate`,
|
|
182
|
+
expected: `**Target**:
|
|
183
|
+
- 90%+ setup completion rate
|
|
184
|
+
- <5 minutes to first workflow
|
|
185
|
+
- <5% configuration error rate`,
|
|
186
|
+
shouldFix: "Should fix real-world documentation patterns"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
description: "Should not affect valid JSX",
|
|
190
|
+
input: "<Component prop={5} />",
|
|
191
|
+
expected: "<Component prop={5} />",
|
|
192
|
+
shouldFix: "Should preserve valid JSX tags"
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/plugins/mdx-auto-fix/transformers/greater-than-digit.ts
|
|
198
|
+
import { visit as visit2 } from "unist-util-visit";
|
|
199
|
+
var greaterThanDigitTransformer = {
|
|
200
|
+
name: "greater-than-digit",
|
|
201
|
+
description: 'Escapes > when followed by a digit (e.g., ">5 users" \u2192 ">5 users")',
|
|
202
|
+
defaultEnabled: true,
|
|
203
|
+
transform: (context) => {
|
|
204
|
+
let fixCount = 0;
|
|
205
|
+
visit2(context.tree, "text", (node) => {
|
|
206
|
+
node.value = node.value.replace(/(?<![-\w])>(?=\s?\d)/g, () => {
|
|
207
|
+
fixCount++;
|
|
208
|
+
return ">";
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
context.stats.byTransformer[greaterThanDigitTransformer.name] = fixCount;
|
|
212
|
+
context.stats.totalFixes += fixCount;
|
|
213
|
+
},
|
|
214
|
+
testCases: [
|
|
215
|
+
{
|
|
216
|
+
description: "Basic greater-than with digit",
|
|
217
|
+
input: "- >90% completion rate",
|
|
218
|
+
expected: "- >90% completion rate",
|
|
219
|
+
shouldFix: "Should escape > immediately followed by digit"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
description: "Greater-than with space and digit",
|
|
223
|
+
input: "- > 5 users online",
|
|
224
|
+
expected: "- > 5 users online",
|
|
225
|
+
shouldFix: "Should escape > followed by space and digit"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
description: "Multiple occurrences",
|
|
229
|
+
input: "Requirements: >5GB RAM, >10 cores, >100GB storage",
|
|
230
|
+
expected: "Requirements: >5GB RAM, >10 cores, >100GB storage",
|
|
231
|
+
shouldFix: "Should fix all occurrences"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
description: "Should not affect valid JSX closing tags",
|
|
235
|
+
input: "<Component>content</Component>",
|
|
236
|
+
expected: "<Component>content</Component>",
|
|
237
|
+
shouldFix: "Should preserve valid JSX closing tags"
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/plugins/mdx-auto-fix/transformers/invalid-tag-names.ts
|
|
243
|
+
import { visit as visit3 } from "unist-util-visit";
|
|
244
|
+
var invalidTagNamesTransformer = {
|
|
245
|
+
name: "invalid-tag-names",
|
|
246
|
+
description: 'Escapes tags with invalid names (e.g., "<5Column>" \u2192 "<5Column>")',
|
|
247
|
+
defaultEnabled: true,
|
|
248
|
+
transform: (context) => {
|
|
249
|
+
let fixCount = 0;
|
|
250
|
+
visit3(context.tree, "text", (node) => {
|
|
251
|
+
node.value = node.value.replace(/<\/?(\d[^>\s]*)/g, (match) => {
|
|
252
|
+
fixCount++;
|
|
253
|
+
return match.replace("<", "<");
|
|
254
|
+
});
|
|
255
|
+
node.value = node.value.replace(/<(\d+)>/g, (match) => {
|
|
256
|
+
fixCount++;
|
|
257
|
+
return match.replace("<", "<");
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
context.stats.byTransformer[invalidTagNamesTransformer.name] = fixCount;
|
|
261
|
+
context.stats.totalFixes += fixCount;
|
|
262
|
+
},
|
|
263
|
+
testCases: [
|
|
264
|
+
{
|
|
265
|
+
description: "Tag starting with number",
|
|
266
|
+
input: "<5Column>Content</5Column>",
|
|
267
|
+
expected: "<5Column>Content</5Column>",
|
|
268
|
+
shouldFix: "Should escape opening and closing tags that start with numbers"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
description: "Numeric-only tag",
|
|
272
|
+
input: "<123>",
|
|
273
|
+
expected: "<123>",
|
|
274
|
+
shouldFix: "Should escape tags that are only numbers"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
description: "Tag with number prefix",
|
|
278
|
+
input: '<3DModel src="path" />',
|
|
279
|
+
expected: '<3DModel src="path" />',
|
|
280
|
+
shouldFix: "Should escape self-closing tags that start with numbers"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
description: "Should preserve valid tags",
|
|
284
|
+
input: "<Component5>Content</Component5>",
|
|
285
|
+
expected: "<Component5>Content</Component5>",
|
|
286
|
+
shouldFix: "Should not affect tags that start with valid characters"
|
|
287
|
+
}
|
|
288
|
+
]
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// src/plugins/mdx-auto-fix/transformers/index.ts
|
|
292
|
+
var defaultTransformers = [
|
|
293
|
+
lessThanDigitTransformer,
|
|
294
|
+
greaterThanDigitTransformer,
|
|
295
|
+
invalidTagNamesTransformer
|
|
296
|
+
];
|
|
297
|
+
var allTransformers = [
|
|
298
|
+
lessThanDigitTransformer,
|
|
299
|
+
greaterThanDigitTransformer,
|
|
300
|
+
invalidTagNamesTransformer
|
|
301
|
+
];
|
|
302
|
+
|
|
303
|
+
// src/plugins/mdx-auto-fix/plugin.ts
|
|
304
|
+
var mdxAutoFix = (options = {}) => {
|
|
305
|
+
const {
|
|
306
|
+
transformers = defaultTransformers,
|
|
307
|
+
enable,
|
|
308
|
+
disable,
|
|
309
|
+
onStats,
|
|
310
|
+
debug = false
|
|
311
|
+
} = options;
|
|
312
|
+
return (tree) => {
|
|
313
|
+
const stats = {
|
|
314
|
+
totalFixes: 0,
|
|
315
|
+
byTransformer: {}
|
|
316
|
+
};
|
|
317
|
+
let activeTransformers = transformers.filter((t) => t.defaultEnabled);
|
|
318
|
+
if (enable && enable.length > 0) {
|
|
319
|
+
activeTransformers = transformers.filter((t) => enable.includes(t.name));
|
|
320
|
+
}
|
|
321
|
+
if (disable && disable.length > 0) {
|
|
322
|
+
activeTransformers = activeTransformers.filter((t) => !disable.includes(t.name));
|
|
323
|
+
}
|
|
324
|
+
if (debug) {
|
|
325
|
+
console.log("[mdx-auto-fix] Active transformers:", activeTransformers.map((t) => t.name));
|
|
326
|
+
}
|
|
327
|
+
for (const transformer of activeTransformers) {
|
|
328
|
+
try {
|
|
329
|
+
transformer.transform({
|
|
330
|
+
tree,
|
|
331
|
+
stats
|
|
332
|
+
});
|
|
333
|
+
if (debug && stats.byTransformer[transformer.name] > 0) {
|
|
334
|
+
console.log(
|
|
335
|
+
`[mdx-auto-fix] ${transformer.name}: ${stats.byTransformer[transformer.name]} fixes`
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
} catch (error) {
|
|
339
|
+
console.error(`[mdx-auto-fix] Error in transformer "${transformer.name}":`, error);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (debug && stats.totalFixes > 0) {
|
|
343
|
+
console.log(`[mdx-auto-fix] Total fixes applied: ${stats.totalFixes}`);
|
|
344
|
+
}
|
|
345
|
+
if (onStats && stats.totalFixes > 0) {
|
|
346
|
+
onStats(stats);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// src/components/ThemedMDXEditor.tsx
|
|
6
352
|
import {
|
|
7
353
|
useCallback,
|
|
8
354
|
useEffect,
|
|
@@ -91,6 +437,7 @@ var ThemedMDXEditor = forwardRef((props, ref) => {
|
|
|
91
437
|
containerStyle = {},
|
|
92
438
|
showLoadingState = false,
|
|
93
439
|
documentPadding,
|
|
440
|
+
autoFixMDX = true,
|
|
94
441
|
markdown: controlledMarkdown,
|
|
95
442
|
onChange: externalOnChange,
|
|
96
443
|
...restEditorProps
|
|
@@ -110,6 +457,14 @@ var ThemedMDXEditor = forwardRef((props, ref) => {
|
|
|
110
457
|
const [savedValue, setSavedValue] = useState(() => computeInitialValue());
|
|
111
458
|
const [isDirty, setIsDirty] = useState(false);
|
|
112
459
|
const currentValue = isControlled ? controlledMarkdown ?? "" : internalValue;
|
|
460
|
+
const processedMarkdown = useMemo(() => {
|
|
461
|
+
if (!autoFixMDX) {
|
|
462
|
+
return currentValue;
|
|
463
|
+
}
|
|
464
|
+
return preprocessMDX(currentValue, {
|
|
465
|
+
preserveCodeBlocks: true
|
|
466
|
+
});
|
|
467
|
+
}, [currentValue, autoFixMDX]);
|
|
113
468
|
useEffect(() => {
|
|
114
469
|
setIsMounted(true);
|
|
115
470
|
if (showLoadingState) {
|
|
@@ -332,7 +687,7 @@ var ThemedMDXEditor = forwardRef((props, ref) => {
|
|
|
332
687
|
MDXEditor,
|
|
333
688
|
{
|
|
334
689
|
ref: editorRef,
|
|
335
|
-
markdown:
|
|
690
|
+
markdown: processedMarkdown,
|
|
336
691
|
onChange: handleChange,
|
|
337
692
|
contentEditableClassName: "mdx-editor-content",
|
|
338
693
|
...restEditorProps
|
|
@@ -579,7 +934,15 @@ function useThemedMDXEditor() {
|
|
|
579
934
|
export {
|
|
580
935
|
ThemedMDXEditor,
|
|
581
936
|
ThemedMDXEditorWithProvider,
|
|
937
|
+
allTransformers,
|
|
582
938
|
createAutoCodeMirrorTheme,
|
|
583
939
|
createCodeMirrorTheme,
|
|
940
|
+
defaultPreprocessRules,
|
|
941
|
+
defaultTransformers,
|
|
942
|
+
greaterThanDigitTransformer,
|
|
943
|
+
invalidTagNamesTransformer,
|
|
944
|
+
lessThanDigitTransformer,
|
|
945
|
+
mdxAutoFix,
|
|
946
|
+
preprocessMDX,
|
|
584
947
|
useThemedMDXEditor
|
|
585
948
|
};
|
|
@@ -24,6 +24,7 @@ export interface ThemedMDXEditorProps extends Omit<MDXEditorProps, 'className' |
|
|
|
24
24
|
containerStyle?: React.CSSProperties;
|
|
25
25
|
showLoadingState?: boolean;
|
|
26
26
|
documentPadding?: DocumentPadding;
|
|
27
|
+
autoFixMDX?: boolean;
|
|
27
28
|
}
|
|
28
29
|
export declare const ThemedMDXEditor: React.ForwardRefExoticComponent<ThemedMDXEditorProps & React.RefAttributes<MDXEditorMethods>>;
|
|
29
30
|
//# sourceMappingURL=ThemedMDXEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemedMDXEditor.d.ts","sourceRoot":"","sources":["../../../src/components/ThemedMDXEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,6BAA6B,CAAC;AACrC,OAAO,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"ThemedMDXEditor.d.ts","sourceRoot":"","sources":["../../../src/components/ThemedMDXEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,6BAA6B,CAAC;AACrC,OAAO,gCAAgC,CAAC;AAExC,OAAO,KAQN,MAAM,OAAO,CAAC;AAMf,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,MAAM,GACN;IACE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,GACD,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,MAAM,CAAC;AAEX,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,0BAA0B,CAAC;IAI1G,KAAK,EAAE,KAAK,CAAC;IAIb,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAInC,YAAY,CAAC,EAAE,MAAM,CAAC;IAItB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAIjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAIlB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAK3C,aAAa,CAAC,EAAE,OAAO,CAAC;IAIxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAI5B,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAIrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAoB3B,eAAe,CAAC,EAAE,eAAe,CAAC;IAelC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAuFD,eAAO,MAAM,eAAe,+FA4W1B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { preprocessMDX, defaultPreprocessRules } from './preprocessor';
|
|
2
|
+
export type { PreprocessRule } from './preprocessor';
|
|
3
|
+
export { mdxAutoFix } from './plugin';
|
|
4
|
+
export type { MDXAutoFixOptions } from './plugin';
|
|
5
|
+
export type { Transformer, TransformerContext, TransformerStats, TransformerTestCase, } from './types';
|
|
6
|
+
export { lessThanDigitTransformer, greaterThanDigitTransformer, invalidTagNamesTransformer, defaultTransformers, allTransformers, } from './transformers';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mdx-auto-fix/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACvE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlD,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,0BAA0B,EAC1B,mBAAmB,EACnB,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { Transformer, TransformerStats } from './types';
|
|
3
|
+
import type { Plugin } from 'unified';
|
|
4
|
+
export interface MDXAutoFixOptions {
|
|
5
|
+
transformers?: Transformer[];
|
|
6
|
+
enable?: string[];
|
|
7
|
+
disable?: string[];
|
|
8
|
+
onStats?: (stats: TransformerStats) => void;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const mdxAutoFix: Plugin<[MDXAutoFixOptions?], Root>;
|
|
12
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mdx-auto-fix/plugin.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAKtC,MAAM,WAAW,iBAAiB;IAIhC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAK7B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAKlB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAKnB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAK5C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAKD,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC,EAAE,IAAI,CA2DzD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TransformerStats } from './types';
|
|
2
|
+
export interface PreprocessRule {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
pattern: RegExp;
|
|
6
|
+
replacement: string | ((match: string, ...args: any[]) => string);
|
|
7
|
+
}
|
|
8
|
+
export declare const defaultPreprocessRules: PreprocessRule[];
|
|
9
|
+
export declare function preprocessMDX(markdown: string, options?: {
|
|
10
|
+
rules?: PreprocessRule[];
|
|
11
|
+
enable?: string[];
|
|
12
|
+
disable?: string[];
|
|
13
|
+
preserveCodeBlocks?: boolean;
|
|
14
|
+
onStats?: (stats: TransformerStats) => void;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
//# sourceMappingURL=preprocessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preprocessor.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mdx-auto-fix/preprocessor.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAKhD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAC;CACnE;AAKD,eAAO,MAAM,sBAAsB,EAAE,cAAc,EA+BlD,CAAC;AAgDF,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;CACZ,GACL,MAAM,CA0ER"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greater-than-digit.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/mdx-auto-fix/transformers/greater-than-digit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,UAAU,CAAC;AAKhE,eAAO,MAAM,2BAA2B,EAAE,WA+CzC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { lessThanDigitTransformer } from './less-than-digit';
|
|
2
|
+
export { greaterThanDigitTransformer } from './greater-than-digit';
|
|
3
|
+
export { invalidTagNamesTransformer } from './invalid-tag-names';
|
|
4
|
+
import type { Transformer } from '../types';
|
|
5
|
+
export declare const defaultTransformers: Transformer[];
|
|
6
|
+
export declare const allTransformers: Transformer[];
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/mdx-auto-fix/transformers/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAKjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAK5C,eAAO,MAAM,mBAAmB,EAAE,WAAW,EAI5C,CAAC;AAKF,eAAO,MAAM,eAAe,EAAE,WAAW,EAIxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalid-tag-names.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/mdx-auto-fix/transformers/invalid-tag-names.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,UAAU,CAAC;AAKhE,eAAO,MAAM,0BAA0B,EAAE,WAqDxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"less-than-digit.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/mdx-auto-fix/transformers/less-than-digit.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,UAAU,CAAC;AAKhE,eAAO,MAAM,wBAAwB,EAAE,WA4EtC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export interface TransformerContext {
|
|
3
|
+
tree: Root;
|
|
4
|
+
originalMarkdown?: string;
|
|
5
|
+
stats: TransformerStats;
|
|
6
|
+
}
|
|
7
|
+
export interface TransformerStats {
|
|
8
|
+
totalFixes: number;
|
|
9
|
+
byTransformer: Record<string, number>;
|
|
10
|
+
}
|
|
11
|
+
export interface Transformer {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
defaultEnabled: boolean;
|
|
15
|
+
transform: (context: TransformerContext) => void;
|
|
16
|
+
testCases?: TransformerTestCase[];
|
|
17
|
+
}
|
|
18
|
+
export interface TransformerTestCase {
|
|
19
|
+
description: string;
|
|
20
|
+
input: string;
|
|
21
|
+
expected: string;
|
|
22
|
+
shouldFix?: string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/plugins/mdx-auto-fix/types.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAKlC,MAAM,WAAW,kBAAkB;IAIjC,IAAI,EAAE,IAAI,CAAC;IAKX,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAK1B,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAKD,MAAM,WAAW,gBAAgB;IAI/B,UAAU,EAAE,MAAM,CAAC;IAKnB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAKD,MAAM,WAAW,WAAW;IAI1B,IAAI,EAAE,MAAM,CAAC;IAKb,WAAW,EAAE,MAAM,CAAC;IAKpB,cAAc,EAAE,OAAO,CAAC;IAKxB,SAAS,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAKjD,SAAS,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACnC;AAKD,MAAM,WAAW,mBAAmB;IAIlC,WAAW,EAAE,MAAM,CAAC;IAKpB,KAAK,EAAE,MAAM,CAAC;IAKd,QAAQ,EAAE,MAAM,CAAC;IAKjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principal-ade/industry-themed-mdx-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Industry-themed MDX editor wrapper with integrated theming",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "bun run clean && bun run build:esm && bun run build:types && bun run build:styles",
|
|
21
|
-
"build:esm": "
|
|
21
|
+
"build:esm": "esbuild index.ts --bundle --format=esm --outfile=dist/index.mjs --external:react --external:react-dom --external:@mdxeditor/editor --external:@a24z/industry-theme --external:remark --external:remark-mdx --external:unist-util-visit --external:mdast --external:@codemirror/state --external:@codemirror/view",
|
|
22
22
|
"build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly --declaration --declarationMap",
|
|
23
23
|
"build:styles": "cp src/styles/mdx-editor-theme.css dist/styles.css",
|
|
24
24
|
"dev": "bun run build --watch",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@storybook/addon-webpack5-compiler-swc": "^4.0.1",
|
|
76
76
|
"@storybook/react-webpack5": "^9.1.13",
|
|
77
77
|
"@types/bun": "latest",
|
|
78
|
+
"@types/mdast": "^4.0.4",
|
|
78
79
|
"@types/node": "^22.15.26",
|
|
79
80
|
"@types/react": "^19.1.12",
|
|
80
81
|
"@types/react-dom": "^19.1.8",
|
|
@@ -86,12 +87,16 @@
|
|
|
86
87
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
87
88
|
"eslint-plugin-import": "^2.32.0",
|
|
88
89
|
"eslint-plugin-storybook": "^9.1.13",
|
|
90
|
+
"mdast": "^3.0.0",
|
|
89
91
|
"prettier": "^3.6.2",
|
|
90
92
|
"react": "^19.1.1",
|
|
91
93
|
"react-dom": "^19.1.1",
|
|
94
|
+
"remark": "^15.0.1",
|
|
95
|
+
"remark-mdx": "^3.1.1",
|
|
92
96
|
"storybook": "^9.1.13",
|
|
93
97
|
"typescript": "^5.0.4",
|
|
94
|
-
"typescript-eslint": "^8.38.0"
|
|
98
|
+
"typescript-eslint": "^8.38.0",
|
|
99
|
+
"unist-util-visit": "^5.0.0"
|
|
95
100
|
},
|
|
96
101
|
"files": [
|
|
97
102
|
"dist",
|