@principal-ade/industry-themed-mdx-editor 0.1.3 → 0.1.4

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.mjs CHANGED
@@ -6,6 +6,21 @@ import "@mdxeditor/editor/style.css";
6
6
 
7
7
  // src/plugins/mdx-auto-fix/preprocessor.ts
8
8
  var defaultPreprocessRules = [
9
+ {
10
+ name: "normalize-code-block-language",
11
+ description: "Normalize unknown code block language identifiers",
12
+ pattern: /```(argdown|N\/A|n\/a)\n/gi,
13
+ replacement: (_match, lang) => {
14
+ const langLower = lang.toLowerCase();
15
+ if (langLower === "n/a") {
16
+ return "```text\n";
17
+ }
18
+ if (langLower === "argdown") {
19
+ return "```markdown\n";
20
+ }
21
+ return "```text\n";
22
+ }
23
+ },
9
24
  {
10
25
  name: "less-than-digit",
11
26
  description: "Escape < followed by digit",
@@ -86,17 +101,41 @@ function preprocessMDX(markdown, options = {}) {
86
101
  totalFixes: 0,
87
102
  byTransformer: {}
88
103
  };
104
+ let result = markdown;
105
+ const codeBlockLangRule = activeRules.find((r) => r.name === "normalize-code-block-language");
106
+ if (codeBlockLangRule) {
107
+ let fixCount = 0;
108
+ if (typeof codeBlockLangRule.replacement === "function") {
109
+ result = result.replace(codeBlockLangRule.pattern, (...args) => {
110
+ fixCount++;
111
+ return codeBlockLangRule.replacement(...args);
112
+ });
113
+ } else {
114
+ result = result.replace(codeBlockLangRule.pattern, () => {
115
+ fixCount++;
116
+ return codeBlockLangRule.replacement;
117
+ });
118
+ }
119
+ if (fixCount > 0) {
120
+ stats.byTransformer[codeBlockLangRule.name] = fixCount;
121
+ stats.totalFixes += fixCount;
122
+ if (debug) {
123
+ console.log(`[mdx-auto-fix] ${codeBlockLangRule.name}: ${fixCount} fixes`);
124
+ }
125
+ }
126
+ }
127
+ const otherRules = activeRules.filter((r) => r.name !== "normalize-code-block-language");
89
128
  const transform = (text) => {
90
- let result2 = text;
91
- for (const rule of activeRules) {
129
+ let transformed = text;
130
+ for (const rule of otherRules) {
92
131
  let fixCount = 0;
93
132
  if (typeof rule.replacement === "function") {
94
- result2 = result2.replace(rule.pattern, (...args) => {
133
+ transformed = transformed.replace(rule.pattern, (...args) => {
95
134
  fixCount++;
96
135
  return rule.replacement(...args);
97
136
  });
98
137
  } else {
99
- result2 = result2.replace(rule.pattern, () => {
138
+ transformed = transformed.replace(rule.pattern, () => {
100
139
  fixCount++;
101
140
  return rule.replacement;
102
141
  });
@@ -109,9 +148,9 @@ function preprocessMDX(markdown, options = {}) {
109
148
  }
110
149
  }
111
150
  }
112
- return result2;
151
+ return transformed;
113
152
  };
114
- const result = preserveCodeBlocks ? preserveCode(markdown, transform) : transform(markdown);
153
+ result = preserveCodeBlocks ? preserveCode(result, transform) : transform(result);
115
154
  if (onStats && stats.totalFixes > 0) {
116
155
  onStats(stats);
117
156
  }
@@ -288,16 +327,124 @@ var invalidTagNamesTransformer = {
288
327
  ]
289
328
  };
290
329
 
330
+ // src/plugins/mdx-auto-fix/transformers/code-block-language.ts
331
+ import { visit as visit4 } from "unist-util-visit";
332
+ var LANGUAGE_MAP = {
333
+ "N/A": "text",
334
+ "n/a": "text",
335
+ "argdown": "markdown"
336
+ // Map argdown to markdown for better syntax highlighting
337
+ // Add more mappings as needed
338
+ };
339
+ var KNOWN_LANGUAGES = /* @__PURE__ */ new Set([
340
+ "javascript",
341
+ "js",
342
+ "typescript",
343
+ "ts",
344
+ "jsx",
345
+ "tsx",
346
+ "python",
347
+ "py",
348
+ "java",
349
+ "c",
350
+ "cpp",
351
+ "csharp",
352
+ "cs",
353
+ "html",
354
+ "css",
355
+ "scss",
356
+ "sass",
357
+ "less",
358
+ "json",
359
+ "yaml",
360
+ "yml",
361
+ "xml",
362
+ "toml",
363
+ "bash",
364
+ "sh",
365
+ "shell",
366
+ "powershell",
367
+ "sql",
368
+ "graphql",
369
+ "markdown",
370
+ "md",
371
+ "rust",
372
+ "go",
373
+ "ruby",
374
+ "php",
375
+ "swift",
376
+ "kotlin",
377
+ "dart",
378
+ "r",
379
+ "matlab",
380
+ "diff",
381
+ "text",
382
+ "plaintext"
383
+ ]);
384
+ var codeBlockLanguageTransformer = {
385
+ name: "code-block-language",
386
+ description: "Normalizes unrecognized code block language identifiers to safe alternatives",
387
+ defaultEnabled: true,
388
+ transform: (context) => {
389
+ let fixCount = 0;
390
+ visit4(context.tree, "code", (node) => {
391
+ const lang = node.lang?.toLowerCase().trim();
392
+ if (!lang) {
393
+ node.lang = "text";
394
+ fixCount++;
395
+ return;
396
+ }
397
+ if (LANGUAGE_MAP[lang]) {
398
+ node.lang = LANGUAGE_MAP[lang];
399
+ fixCount++;
400
+ return;
401
+ }
402
+ if (!KNOWN_LANGUAGES.has(lang)) {
403
+ }
404
+ });
405
+ context.stats.byTransformer[codeBlockLanguageTransformer.name] = fixCount;
406
+ context.stats.totalFixes += fixCount;
407
+ },
408
+ testCases: [
409
+ {
410
+ description: "Code block with N/A language",
411
+ input: "```N/A\ncode here\n```",
412
+ expected: "```text\ncode here\n```",
413
+ shouldFix: "Should convert N/A to text"
414
+ },
415
+ {
416
+ description: "Code block with argdown language",
417
+ input: "```argdown\n[Claim]: Statement\n```",
418
+ expected: "```markdown\n[Claim]: Statement\n```",
419
+ shouldFix: "Should convert argdown to markdown"
420
+ },
421
+ {
422
+ description: "Code block without language",
423
+ input: "```\ncode here\n```",
424
+ expected: "```text\ncode here\n```",
425
+ shouldFix: "Should add text language to blocks without one"
426
+ },
427
+ {
428
+ description: "Should preserve known languages",
429
+ input: "```javascript\nconst x = 1;\n```",
430
+ expected: "```javascript\nconst x = 1;\n```",
431
+ shouldFix: "Should not modify known languages"
432
+ }
433
+ ]
434
+ };
435
+
291
436
  // src/plugins/mdx-auto-fix/transformers/index.ts
292
437
  var defaultTransformers = [
293
438
  lessThanDigitTransformer,
294
439
  greaterThanDigitTransformer,
295
- invalidTagNamesTransformer
440
+ invalidTagNamesTransformer,
441
+ codeBlockLanguageTransformer
296
442
  ];
297
443
  var allTransformers = [
298
444
  lessThanDigitTransformer,
299
445
  greaterThanDigitTransformer,
300
- invalidTagNamesTransformer
446
+ invalidTagNamesTransformer,
447
+ codeBlockLanguageTransformer
301
448
  ];
302
449
 
303
450
  // src/plugins/mdx-auto-fix/plugin.ts
@@ -1 +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"}
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,EA8ClD,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,CAyGR"}
@@ -0,0 +1,3 @@
1
+ import type { Transformer } from '../types';
2
+ export declare const codeBlockLanguageTransformer: Transformer;
3
+ //# sourceMappingURL=code-block-language.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-block-language.d.ts","sourceRoot":"","sources":["../../../../../src/plugins/mdx-auto-fix/transformers/code-block-language.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,UAAU,CAAC;AA8BhE,eAAO,MAAM,4BAA4B,EAAE,WA+D1C,CAAC"}
@@ -1,6 +1,7 @@
1
1
  export { lessThanDigitTransformer } from './less-than-digit';
2
2
  export { greaterThanDigitTransformer } from './greater-than-digit';
3
3
  export { invalidTagNamesTransformer } from './invalid-tag-names';
4
+ export { codeBlockLanguageTransformer } from './code-block-language';
4
5
  import type { Transformer } from '../types';
5
6
  export declare const defaultTransformers: Transformer[];
6
7
  export declare const allTransformers: Transformer[];
@@ -1 +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"}
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;AACjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAMrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAK5C,eAAO,MAAM,mBAAmB,EAAE,WAAW,EAK5C,CAAC;AAKF,eAAO,MAAM,eAAe,EAAE,WAAW,EAKxC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principal-ade/industry-themed-mdx-editor",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Industry-themed MDX editor wrapper with integrated theming",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",