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

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
@@ -8,17 +8,69 @@ import "@mdxeditor/editor/style.css";
8
8
  var defaultPreprocessRules = [
9
9
  {
10
10
  name: "normalize-code-block-language",
11
- description: "Normalize unknown code block language identifiers",
12
- pattern: /```(argdown|N\/A|n\/a)\n/gi,
11
+ description: "Normalize unknown or missing code block language identifiers",
12
+ pattern: /^```([^\n`]*?)\n/gim,
13
13
  replacement: (_match, lang) => {
14
- const langLower = lang.toLowerCase();
14
+ const trimmedLang = lang.trim();
15
+ const knownLanguages = [
16
+ "javascript",
17
+ "js",
18
+ "typescript",
19
+ "ts",
20
+ "jsx",
21
+ "tsx",
22
+ "python",
23
+ "py",
24
+ "java",
25
+ "c",
26
+ "cpp",
27
+ "csharp",
28
+ "cs",
29
+ "html",
30
+ "css",
31
+ "scss",
32
+ "sass",
33
+ "less",
34
+ "json",
35
+ "yaml",
36
+ "yml",
37
+ "xml",
38
+ "toml",
39
+ "bash",
40
+ "sh",
41
+ "shell",
42
+ "powershell",
43
+ "sql",
44
+ "graphql",
45
+ "markdown",
46
+ "md",
47
+ "rust",
48
+ "go",
49
+ "ruby",
50
+ "php",
51
+ "swift",
52
+ "kotlin",
53
+ "dart",
54
+ "r",
55
+ "matlab",
56
+ "diff",
57
+ "text",
58
+ "plaintext"
59
+ ];
60
+ if (knownLanguages.includes(trimmedLang.toLowerCase())) {
61
+ return _match;
62
+ }
63
+ if (!trimmedLang || trimmedLang === "") {
64
+ return "```text\n";
65
+ }
66
+ const langLower = trimmedLang.toLowerCase();
15
67
  if (langLower === "n/a") {
16
68
  return "```text\n";
17
69
  }
18
70
  if (langLower === "argdown") {
19
71
  return "```markdown\n";
20
72
  }
21
- return "```text\n";
73
+ return _match;
22
74
  }
23
75
  },
24
76
  {
@@ -105,15 +157,33 @@ function preprocessMDX(markdown, options = {}) {
105
157
  const codeBlockLangRule = activeRules.find((r) => r.name === "normalize-code-block-language");
106
158
  if (codeBlockLangRule) {
107
159
  let fixCount = 0;
160
+ let insideCodeBlock = false;
108
161
  if (typeof codeBlockLangRule.replacement === "function") {
109
162
  result = result.replace(codeBlockLangRule.pattern, (...args) => {
110
- fixCount++;
111
- return codeBlockLangRule.replacement(...args);
163
+ if (insideCodeBlock) {
164
+ insideCodeBlock = false;
165
+ return args[0];
166
+ }
167
+ insideCodeBlock = true;
168
+ const originalMatch = args[0];
169
+ const replacement = codeBlockLangRule.replacement(...args);
170
+ if (replacement !== originalMatch) {
171
+ fixCount++;
172
+ }
173
+ return replacement;
112
174
  });
113
175
  } else {
114
- result = result.replace(codeBlockLangRule.pattern, () => {
115
- fixCount++;
116
- return codeBlockLangRule.replacement;
176
+ result = result.replace(codeBlockLangRule.pattern, (match) => {
177
+ if (insideCodeBlock) {
178
+ insideCodeBlock = false;
179
+ return match;
180
+ }
181
+ insideCodeBlock = true;
182
+ const replacement = codeBlockLangRule.replacement;
183
+ if (replacement !== match) {
184
+ fixCount++;
185
+ }
186
+ return replacement;
117
187
  });
118
188
  }
119
189
  if (fixCount > 0) {
@@ -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,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"}
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,EA2ElD,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,CAwIR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principal-ade/industry-themed-mdx-editor",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Industry-themed MDX editor wrapper with integrated theming",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",