@principal-ade/industry-themed-mdx-editor 0.1.4 → 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.
package/dist/index.mjs
CHANGED
|
@@ -8,17 +8,72 @@ 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:
|
|
13
|
-
replacement: (_match, lang) => {
|
|
14
|
-
const
|
|
11
|
+
description: "Normalize unknown or missing code block language identifiers",
|
|
12
|
+
pattern: /^(\s*)```([^\n`]*?)\n/gim,
|
|
13
|
+
replacement: (_match, indent, lang) => {
|
|
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 `${indent}\`\`\`text
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
const langLower = trimmedLang.toLowerCase();
|
|
15
68
|
if (langLower === "n/a") {
|
|
16
|
-
return
|
|
69
|
+
return `${indent}\`\`\`text
|
|
70
|
+
`;
|
|
17
71
|
}
|
|
18
72
|
if (langLower === "argdown") {
|
|
19
|
-
return
|
|
73
|
+
return `${indent}\`\`\`markdown
|
|
74
|
+
`;
|
|
20
75
|
}
|
|
21
|
-
return
|
|
76
|
+
return _match;
|
|
22
77
|
}
|
|
23
78
|
},
|
|
24
79
|
{
|
|
@@ -105,15 +160,33 @@ function preprocessMDX(markdown, options = {}) {
|
|
|
105
160
|
const codeBlockLangRule = activeRules.find((r) => r.name === "normalize-code-block-language");
|
|
106
161
|
if (codeBlockLangRule) {
|
|
107
162
|
let fixCount = 0;
|
|
163
|
+
let insideCodeBlock = false;
|
|
108
164
|
if (typeof codeBlockLangRule.replacement === "function") {
|
|
109
165
|
result = result.replace(codeBlockLangRule.pattern, (...args) => {
|
|
110
|
-
|
|
111
|
-
|
|
166
|
+
if (insideCodeBlock) {
|
|
167
|
+
insideCodeBlock = false;
|
|
168
|
+
return args[0];
|
|
169
|
+
}
|
|
170
|
+
insideCodeBlock = true;
|
|
171
|
+
const originalMatch = args[0];
|
|
172
|
+
const replacement = codeBlockLangRule.replacement(...args);
|
|
173
|
+
if (replacement !== originalMatch) {
|
|
174
|
+
fixCount++;
|
|
175
|
+
}
|
|
176
|
+
return replacement;
|
|
112
177
|
});
|
|
113
178
|
} else {
|
|
114
|
-
result = result.replace(codeBlockLangRule.pattern, () => {
|
|
115
|
-
|
|
116
|
-
|
|
179
|
+
result = result.replace(codeBlockLangRule.pattern, (match) => {
|
|
180
|
+
if (insideCodeBlock) {
|
|
181
|
+
insideCodeBlock = false;
|
|
182
|
+
return match;
|
|
183
|
+
}
|
|
184
|
+
insideCodeBlock = true;
|
|
185
|
+
const replacement = codeBlockLangRule.replacement;
|
|
186
|
+
if (replacement !== match) {
|
|
187
|
+
fixCount++;
|
|
188
|
+
}
|
|
189
|
+
return replacement;
|
|
117
190
|
});
|
|
118
191
|
}
|
|
119
192
|
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,
|
|
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"}
|