@mui/internal-docs-infra 0.3.1-canary.2 → 0.3.1-canary.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.
Files changed (110) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +252 -327
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeHighlighter/types.d.ts +7 -1
  11. package/esm/CodeProvider/CodeContext.js +3 -3
  12. package/esm/CodeProvider/CodeProvider.js +31 -40
  13. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  14. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  15. package/esm/cli/index.js +1 -1
  16. package/esm/cli/runValidate.js +160 -264
  17. package/esm/createDemoData/createDemoData.js +11 -12
  18. package/esm/createSitemap/createSitemap.js +2 -2
  19. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  20. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  21. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  22. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  23. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  24. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  25. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  26. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  27. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  28. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  29. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  30. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +517 -727
  31. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +683 -1032
  32. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  33. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  34. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  35. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  36. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  42. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  47. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  48. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  49. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  50. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  51. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  52. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  53. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  54. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  55. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  56. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  57. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  58. package/esm/pipeline/loaderUtils/getLanguageFromExtension.d.ts +24 -0
  59. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +62 -0
  60. package/esm/pipeline/loaderUtils/index.d.ts +2 -1
  61. package/esm/pipeline/loaderUtils/index.js +2 -1
  62. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  63. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  64. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  65. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  66. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  67. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  68. package/esm/pipeline/parseSource/grammars.d.ts +12 -1
  69. package/esm/pipeline/parseSource/grammars.js +36 -4
  70. package/esm/pipeline/parseSource/index.d.ts +2 -1
  71. package/esm/pipeline/parseSource/index.js +2 -1
  72. package/esm/pipeline/parseSource/parseSource.js +23 -32
  73. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  74. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  75. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  76. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  77. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +266 -320
  78. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  79. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +183 -267
  80. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  81. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  82. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  83. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  84. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  85. package/esm/useCode/Pre.d.ts +2 -0
  86. package/esm/useCode/Pre.js +58 -60
  87. package/esm/useCode/useCode.js +59 -61
  88. package/esm/useCode/useCodeUtils.js +54 -63
  89. package/esm/useCode/useCopyFunctionality.js +10 -9
  90. package/esm/useCode/useFileNavigation.js +171 -209
  91. package/esm/useCode/useSourceEditing.js +17 -14
  92. package/esm/useCode/useTransformManagement.js +23 -26
  93. package/esm/useCode/useUIState.js +12 -20
  94. package/esm/useCode/useVariantSelection.js +62 -79
  95. package/esm/useCopier/index.js +29 -56
  96. package/esm/useDemo/createCodeSandbox.js +12 -15
  97. package/esm/useDemo/createStackBlitz.js +14 -20
  98. package/esm/useDemo/exportVariant.js +200 -180
  99. package/esm/useDemo/exportVariantAsCra.js +22 -25
  100. package/esm/useDemo/useDemo.js +80 -84
  101. package/esm/useErrors/ErrorsContext.js +1 -1
  102. package/esm/useErrors/useErrors.js +3 -3
  103. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  104. package/esm/usePreference/PreferencesProvider.js +1 -1
  105. package/esm/usePreference/usePreference.js +9 -11
  106. package/esm/useSearch/useSearch.js +290 -387
  107. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  108. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  109. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  110. package/package.json +7 -4
@@ -1,7 +1,6 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
1
  import { visit } from 'unist-util-visit';
2
+ import { normalizeLanguage } from "../loaderUtils/getLanguageFromExtension.js";
3
+
5
4
  /**
6
5
  * Remark plugin that transforms code blocks with variants into semantic HTML structures.
7
6
  *
@@ -54,67 +53,36 @@ import { visit } from 'unist-util-visit';
54
53
  * <dl>
55
54
  * <dt><code>index.js</code></dt>
56
55
  * <dd>
57
- * <pre><code class="language-bash">pnpm install @mui/internal-docs-infra</code></pre>
56
+ * <pre><code class="language-shell">pnpm install @mui/internal-docs-infra</code></pre>
58
57
  * </dd>
59
58
  * </dl>
60
59
  * </figure>
61
60
  * </section>
62
61
  *
63
- * Or for individual blocks (no figure/figcaption needed):
62
+ * Or for individual blocks without filename (no dl wrapper needed):
63
+ * <pre><code class="language-typescript" data-transform="true">console.log('test' as const)</code></pre>
64
+ *
65
+ * Or with explicit filename (uses dl/dt/dd structure):
64
66
  * <dl>
65
- * <dt><code>index.ts</code></dt>
67
+ * <dt><code>example.ts</code></dt>
66
68
  * <dd>
67
- * <pre><code class="language-ts" data-transform="true">console.log('test' as const)</code></pre>
69
+ * <pre><code class="language-typescript">console.log('test' as const)</code></pre>
68
70
  * </dd>
69
71
  * </dl>
72
+ *
73
+ * Note: The `dl/dt/dd` structure is only used when an explicit `filename` prop is provided.
74
+ * Language information is passed via the `class="language-*"` attribute on the code element.
70
75
  */
71
76
 
72
77
  /**
73
- * Maps common language names to file extensions
74
- */
75
- var LANGUAGE_TO_EXTENSION = {
76
- // JavaScript
77
- javascript: 'js',
78
- js: 'js',
79
- // TypeScript
80
- typescript: 'ts',
81
- ts: 'ts',
82
- // TSX/JSX
83
- tsx: 'tsx',
84
- jsx: 'jsx',
85
- // JSON
86
- json: 'json',
87
- // Markdown
88
- markdown: 'md',
89
- md: 'md',
90
- // MDX
91
- mdx: 'mdx',
92
- // HTML
93
- html: 'html',
94
- // CSS
95
- css: 'css',
96
- // Shell
97
- shell: 'sh',
98
- bash: 'sh',
99
- sh: 'sh',
100
- // YAML
101
- yaml: 'yaml',
102
- yml: 'yaml'
103
- };
104
-
105
- /**
106
- * Gets filename from language or explicit filename prop
78
+ * Gets filename from explicit filename prop only.
79
+ * Does not derive filename from language - language is passed via className instead.
107
80
  */
108
- function getFileName(language, props) {
109
- // Check for explicit filename
81
+ function getFileName(props) {
82
+ // Only return explicit filename
110
83
  if (props.filename) {
111
84
  return props.filename;
112
85
  }
113
-
114
- // Derive from language
115
- if (language && LANGUAGE_TO_EXTENSION[language]) {
116
- return "index.".concat(LANGUAGE_TO_EXTENSION[language]);
117
- }
118
86
  return null;
119
87
  }
120
88
 
@@ -122,26 +90,22 @@ function getFileName(language, props) {
122
90
  * Parse meta string to extract variant and other properties
123
91
  */
124
92
  function parseMeta(meta) {
125
- var result = {
93
+ const result = {
126
94
  props: {}
127
95
  };
128
96
 
129
97
  // Parse key=value pairs first, handling quoted values
130
- var keyValueRegex = /([\w-]+)=("(?:[^"\\]|\\.)*"|[^\s]+)/g;
131
- var match = keyValueRegex.exec(meta);
132
- var processedPositions = [];
98
+ const keyValueRegex = /([\w-]+)=("(?:[^"\\]|\\.)*"|[^\s]+)/g;
99
+ let match = keyValueRegex.exec(meta);
100
+ const processedPositions = [];
133
101
  while (match !== null) {
134
- var _match = match,
135
- _match2 = _slicedToArray(_match, 3),
136
- fullMatch = _match2[0],
137
- key = _match2[1],
138
- rawValue = _match2[2];
139
- var startPos = match.index;
140
- var endPos = match.index + fullMatch.length;
102
+ const [fullMatch, key, rawValue] = match;
103
+ const startPos = match.index;
104
+ const endPos = match.index + fullMatch.length;
141
105
  processedPositions.push([startPos, endPos]);
142
106
 
143
107
  // Remove quotes if present
144
- var value = rawValue.startsWith('"') && rawValue.endsWith('"') ? rawValue.slice(1, -1) : rawValue;
108
+ const value = rawValue.startsWith('"') && rawValue.endsWith('"') ? rawValue.slice(1, -1) : rawValue;
145
109
  if (key === 'variant') {
146
110
  result.variant = value;
147
111
  } else if (key === 'variant-type') {
@@ -153,46 +117,32 @@ function parseMeta(meta) {
153
117
  }
154
118
 
155
119
  // Extract remaining parts as standalone flags
156
- var remainingMeta = meta;
120
+ let remainingMeta = meta;
157
121
  // Remove processed key=value pairs from the string (in reverse order to maintain positions)
158
- processedPositions.sort(function (a, b) {
159
- return b[0] - a[0];
160
- }).forEach(function (_ref) {
161
- var _ref2 = _slicedToArray(_ref, 2),
162
- start = _ref2[0],
163
- end = _ref2[1];
122
+ processedPositions.sort((a, b) => b[0] - a[0]).forEach(([start, end]) => {
164
123
  remainingMeta = remainingMeta.slice(0, start) + remainingMeta.slice(end);
165
124
  });
166
125
 
167
126
  // Process remaining standalone flags
168
- var remainingParts = remainingMeta.trim().split(/\s+/).filter(Boolean);
169
- var _iterator = _createForOfIteratorHelper(remainingParts),
170
- _step;
171
- try {
172
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
173
- var part = _step.value;
174
- if (part === 'variant') {
175
- // This shouldn't happen, but just in case
176
- result.variant = 'true';
177
- } else if (part === 'variant-type') {
178
- // This shouldn't happen, but just in case
179
- result.variantType = 'true';
180
- } else {
181
- // Handle standalone flags (e.g., "transform" becomes "transform": "true")
182
- result.props[part] = 'true';
183
- }
127
+ const remainingParts = remainingMeta.trim().split(/\s+/).filter(Boolean);
128
+ for (const part of remainingParts) {
129
+ if (part === 'variant') {
130
+ // This shouldn't happen, but just in case
131
+ result.variant = 'true';
132
+ } else if (part === 'variant-type') {
133
+ // This shouldn't happen, but just in case
134
+ result.variantType = 'true';
135
+ } else {
136
+ // Handle standalone flags (e.g., "transform" becomes "transform": "true")
137
+ result.props[part] = 'true';
184
138
  }
185
- } catch (err) {
186
- _iterator.e(err);
187
- } finally {
188
- _iterator.f();
189
139
  }
190
140
  return result;
191
141
  }
192
- export var transformMarkdownCode = function transformMarkdownCode() {
193
- return function (tree) {
194
- var processedIndices = new Set();
195
- visit(tree, function (node, index, parent) {
142
+ export const transformMarkdownCode = () => {
143
+ return tree => {
144
+ const processedIndices = new Set();
145
+ visit(tree, (node, index, parent) => {
196
146
  if (!parent || !Array.isArray(parent.children) || typeof index !== 'number') {
197
147
  return;
198
148
  }
@@ -201,15 +151,15 @@ export var transformMarkdownCode = function transformMarkdownCode() {
201
151
  if (processedIndices.has(index)) {
202
152
  return;
203
153
  }
204
- var parentNode = parent;
154
+ const parentNode = parent;
205
155
 
206
156
  // Look for code blocks with variant metadata or options
207
157
  if (node.type === 'code') {
208
- var codeNode = node;
158
+ const codeNode = node;
209
159
 
210
160
  // Check if variant metadata is in meta field or lang field (when no language is specified)
211
- var metaString = codeNode.meta;
212
- var langFromMeta = codeNode.lang || null;
161
+ let metaString = codeNode.meta;
162
+ let langFromMeta = codeNode.lang || null;
213
163
 
214
164
  // If meta is empty but lang contains '=', it means variant info is in lang
215
165
  if (!metaString && codeNode.lang && codeNode.lang.includes('=')) {
@@ -218,7 +168,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
218
168
  }
219
169
 
220
170
  // Check if we have variants/variant-types or individual options
221
- var metaData = {
171
+ let metaData = {
222
172
  props: {}
223
173
  };
224
174
  if (metaString) {
@@ -226,38 +176,57 @@ export var transformMarkdownCode = function transformMarkdownCode() {
226
176
  }
227
177
 
228
178
  // Use props from meta as the options for individual blocks
229
- var allProps = metaData.props;
179
+ const allProps = metaData.props;
230
180
 
231
181
  // Handle individual code blocks with options (but no variants)
232
182
  if (!metaData.variant && !metaData.variantType && Object.keys(allProps).length > 0) {
233
- // Create a dl element for individual blocks with options
234
- var codeHProperties = {};
183
+ const codeHProperties = {};
235
184
 
236
- // Add language class if available
185
+ // Add normalized language as class
237
186
  if (langFromMeta) {
238
- codeHProperties.className = "language-".concat(langFromMeta);
187
+ codeHProperties.className = `language-${normalizeLanguage(langFromMeta)}`;
239
188
  }
240
189
 
241
190
  // Add all props as data attributes (in camelCase)
242
- Object.entries(allProps).forEach(function (_ref3) {
243
- var _ref4 = _slicedToArray(_ref3, 2),
244
- key = _ref4[0],
245
- value = _ref4[1];
191
+ Object.entries(allProps).forEach(([key, value]) => {
246
192
  // Convert kebab-case to camelCase for data attributes
247
- var camelKey = key.includes('-') ? "data".concat(key.split('-').map(function (part) {
248
- return part.charAt(0).toUpperCase() + part.slice(1);
249
- }).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
193
+ const camelKey = key.includes('-') ? `data${key.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('')}` : `data${key.charAt(0).toUpperCase() + key.slice(1)}`;
250
194
  codeHProperties[camelKey] = value;
251
195
  });
252
- var fileName = getFileName(langFromMeta, allProps);
253
- var dlElement = {
196
+ const fileName = getFileName(allProps);
197
+
198
+ // Create pre > code element
199
+ const preElement = {
200
+ type: 'element',
201
+ tagName: 'pre',
202
+ data: {
203
+ hName: 'pre',
204
+ hProperties: {}
205
+ },
206
+ children: [{
207
+ type: 'element',
208
+ tagName: 'code',
209
+ data: {
210
+ hName: 'code',
211
+ hProperties: codeHProperties
212
+ },
213
+ children: [{
214
+ type: 'text',
215
+ value: codeNode.value
216
+ }]
217
+ }]
218
+ };
219
+
220
+ // If there's a filename, wrap in dl/dt/dd structure
221
+ // Otherwise, just use pre > code directly
222
+ const outputElement = fileName ? {
254
223
  type: 'element',
255
224
  tagName: 'dl',
256
225
  data: {
257
226
  hName: 'dl',
258
227
  hProperties: {}
259
228
  },
260
- children: [].concat(_toConsumableArray(fileName ? [{
229
+ children: [{
261
230
  type: 'element',
262
231
  tagName: 'dt',
263
232
  data: {
@@ -276,38 +245,19 @@ export var transformMarkdownCode = function transformMarkdownCode() {
276
245
  value: fileName
277
246
  }]
278
247
  }]
279
- }] : []), [{
248
+ }, {
280
249
  type: 'element',
281
250
  tagName: 'dd',
282
251
  data: {
283
252
  hName: 'dd',
284
253
  hProperties: {}
285
254
  },
286
- children: [{
287
- type: 'element',
288
- tagName: 'pre',
289
- data: {
290
- hName: 'pre',
291
- hProperties: {}
292
- },
293
- children: [{
294
- type: 'element',
295
- tagName: 'code',
296
- data: {
297
- hName: 'code',
298
- hProperties: codeHProperties
299
- },
300
- children: [{
301
- type: 'text',
302
- value: codeNode.value
303
- }]
304
- }]
305
- }]
306
- }])
307
- };
255
+ children: [preElement]
256
+ }]
257
+ } : preElement;
308
258
 
309
259
  // Replace this individual code block immediately
310
- parentNode.children[index] = dlElement;
260
+ parentNode.children[index] = outputElement;
311
261
  processedIndices.add(index);
312
262
  return;
313
263
  }
@@ -318,24 +268,24 @@ export var transformMarkdownCode = function transformMarkdownCode() {
318
268
  }
319
269
  if (metaData.variant || metaData.variantType) {
320
270
  // Collect consecutive code blocks that belong together
321
- var codeBlocks = [];
322
- var currentIndex = index;
271
+ const codeBlocks = [];
272
+ let currentIndex = index;
323
273
 
324
274
  // For variant-type, look for pattern: [label] -> code block
325
275
  // For variant, look for adjacent code blocks only
326
276
 
327
277
  if (metaData.variantType) {
328
278
  // Add the current code block as the first one for variant-type
329
- var currentLabelFromPrevious;
279
+ let currentLabelFromPrevious;
330
280
  if (index > 0) {
331
- var prevNode = parentNode.children[index - 1];
281
+ const prevNode = parentNode.children[index - 1];
332
282
  if (prevNode.type === 'paragraph' && prevNode.children.length === 1 && prevNode.children[0].type === 'text') {
333
283
  currentLabelFromPrevious = prevNode.children[0].value.trim();
334
284
  }
335
285
  }
336
286
  codeBlocks.push({
337
287
  node: codeNode,
338
- index: index,
288
+ index,
339
289
  variant: currentLabelFromPrevious || metaData.variantType || 'default',
340
290
  props: allProps,
341
291
  actualLang: langFromMeta,
@@ -348,32 +298,32 @@ export var transformMarkdownCode = function transformMarkdownCode() {
348
298
 
349
299
  // Collect all blocks with the same variant-type
350
300
  while (currentIndex < parentNode.children.length) {
351
- var currentNode = parentNode.children[currentIndex];
301
+ const currentNode = parentNode.children[currentIndex];
352
302
 
353
303
  // Check if this is a potential label paragraph
354
304
  if (currentNode.type === 'paragraph' && currentNode.children.length === 1 && currentNode.children[0].type === 'text') {
355
305
  // Look for a code block after this paragraph
356
306
  if (currentIndex + 1 < parentNode.children.length) {
357
- var nextNode = parentNode.children[currentIndex + 1];
307
+ const nextNode = parentNode.children[currentIndex + 1];
358
308
  if (nextNode.type === 'code') {
359
309
  // Check if this code block has the same variant-type
360
- var nextMetaString = nextNode.meta;
361
- var nextActualLang = nextNode.lang;
310
+ let nextMetaString = nextNode.meta;
311
+ let nextActualLang = nextNode.lang;
362
312
  if (!nextMetaString && nextActualLang && nextActualLang.includes('=')) {
363
313
  nextMetaString = nextActualLang;
364
314
  nextActualLang = null;
365
315
  }
366
316
  if (nextMetaString) {
367
- var nextMetaData = parseMeta(nextMetaString);
317
+ const nextMetaData = parseMeta(nextMetaString);
368
318
  if (nextMetaData.variantType === metaData.variantType) {
369
- var labelFromPrevious = currentNode.children[0].value.trim();
319
+ const labelFromPrevious = currentNode.children[0].value.trim();
370
320
  codeBlocks.push({
371
321
  node: nextNode,
372
322
  index: currentIndex + 1,
373
323
  variant: labelFromPrevious || nextMetaData.variantType || 'default',
374
324
  props: nextMetaData.props,
375
325
  actualLang: nextActualLang,
376
- labelFromPrevious: labelFromPrevious
326
+ labelFromPrevious
377
327
  });
378
328
  processedIndices.add(currentIndex + 1);
379
329
 
@@ -389,30 +339,30 @@ export var transformMarkdownCode = function transformMarkdownCode() {
389
339
  }
390
340
  if (currentNode.type === 'code') {
391
341
  // Parse language and meta for current node
392
- var currentMetaString = currentNode.meta;
393
- var currentActualLang = currentNode.lang;
342
+ let currentMetaString = currentNode.meta;
343
+ let currentActualLang = currentNode.lang;
394
344
  if (!currentMetaString && currentActualLang && currentActualLang.includes('=')) {
395
345
  currentMetaString = currentActualLang;
396
346
  currentActualLang = null;
397
347
  }
398
348
  if (currentMetaString) {
399
- var currentMetaData = parseMeta(currentMetaString);
349
+ const currentMetaData = parseMeta(currentMetaString);
400
350
  if (currentMetaData.variantType === metaData.variantType) {
401
351
  // Look for label before this code block
402
- var _labelFromPrevious = void 0;
352
+ let labelFromPrevious;
403
353
  if (currentIndex > 0) {
404
- var _prevNode = parentNode.children[currentIndex - 1];
405
- if (_prevNode.type === 'paragraph' && _prevNode.children.length === 1 && _prevNode.children[0].type === 'text') {
406
- _labelFromPrevious = _prevNode.children[0].value.trim();
354
+ const prevNode = parentNode.children[currentIndex - 1];
355
+ if (prevNode.type === 'paragraph' && prevNode.children.length === 1 && prevNode.children[0].type === 'text') {
356
+ labelFromPrevious = prevNode.children[0].value.trim();
407
357
  }
408
358
  }
409
359
  codeBlocks.push({
410
360
  node: currentNode,
411
361
  index: currentIndex,
412
- variant: _labelFromPrevious || currentMetaData.variantType || 'default',
362
+ variant: labelFromPrevious || currentMetaData.variantType || 'default',
413
363
  props: currentMetaData.props,
414
364
  actualLang: currentActualLang,
415
- labelFromPrevious: _labelFromPrevious
365
+ labelFromPrevious
416
366
  });
417
367
  processedIndices.add(currentIndex);
418
368
 
@@ -421,8 +371,8 @@ export var transformMarkdownCode = function transformMarkdownCode() {
421
371
 
422
372
  // Skip ahead past any paragraph that could be a label
423
373
  if (currentIndex < parentNode.children.length) {
424
- var _nextNode = parentNode.children[currentIndex];
425
- if (_nextNode.type === 'paragraph' && _nextNode.children.length === 1 && _nextNode.children[0].type === 'text') {
374
+ const nextNode = parentNode.children[currentIndex];
375
+ if (nextNode.type === 'paragraph' && nextNode.children.length === 1 && nextNode.children[0].type === 'text') {
426
376
  currentIndex += 1; // Skip the potential label
427
377
  }
428
378
  }
@@ -440,7 +390,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
440
390
  // Add the current code block as the first one for variant
441
391
  codeBlocks.push({
442
392
  node: codeNode,
443
- index: index,
393
+ index,
444
394
  variant: metaData.variant,
445
395
  props: allProps,
446
396
  actualLang: langFromMeta
@@ -452,24 +402,24 @@ export var transformMarkdownCode = function transformMarkdownCode() {
452
402
 
453
403
  // Collect adjacent code blocks with variants
454
404
  while (currentIndex < parentNode.children.length) {
455
- var _currentNode = parentNode.children[currentIndex];
456
- if (_currentNode.type === 'code') {
405
+ const currentNode = parentNode.children[currentIndex];
406
+ if (currentNode.type === 'code') {
457
407
  // Parse language and meta for current node
458
- var _currentMetaString = _currentNode.meta;
459
- var _currentActualLang = _currentNode.lang;
460
- if (!_currentMetaString && _currentActualLang && _currentActualLang.includes('=')) {
461
- _currentMetaString = _currentActualLang;
462
- _currentActualLang = null;
408
+ let currentMetaString = currentNode.meta;
409
+ let currentActualLang = currentNode.lang;
410
+ if (!currentMetaString && currentActualLang && currentActualLang.includes('=')) {
411
+ currentMetaString = currentActualLang;
412
+ currentActualLang = null;
463
413
  }
464
- if (_currentMetaString) {
465
- var _currentMetaData = parseMeta(_currentMetaString);
466
- if (_currentMetaData.variant) {
414
+ if (currentMetaString) {
415
+ const currentMetaData = parseMeta(currentMetaString);
416
+ if (currentMetaData.variant) {
467
417
  codeBlocks.push({
468
- node: _currentNode,
418
+ node: currentNode,
469
419
  index: currentIndex,
470
- variant: _currentMetaData.variant,
471
- props: _currentMetaData.props,
472
- actualLang: _currentActualLang
420
+ variant: currentMetaData.variant,
421
+ props: currentMetaData.props,
422
+ actualLang: currentActualLang
473
423
  });
474
424
  processedIndices.add(currentIndex);
475
425
  currentIndex += 1;
@@ -488,37 +438,32 @@ export var transformMarkdownCode = function transformMarkdownCode() {
488
438
  // Only process if we have multiple blocks
489
439
  if (codeBlocks.length > 1) {
490
440
  // Create section with figure elements for each variant
491
- var sectionElement = {
441
+ const sectionElement = {
492
442
  type: 'element',
493
443
  tagName: 'section',
494
444
  data: {
495
445
  hName: 'section',
496
446
  hProperties: {}
497
447
  },
498
- children: codeBlocks.map(function (block) {
448
+ children: codeBlocks.map(block => {
499
449
  // Build hProperties for HTML attributes
500
- var codeHProperties = {};
450
+ const codeHProperties = {};
501
451
 
502
- // Add language class if available
452
+ // Add normalized language as class
503
453
  if (block.actualLang) {
504
- codeHProperties.className = "language-".concat(block.actualLang);
454
+ codeHProperties.className = `language-${normalizeLanguage(block.actualLang)}`;
505
455
  }
506
456
 
507
457
  // Add additional props as data attributes (in camelCase)
508
- Object.entries(block.props).forEach(function (_ref5) {
509
- var _ref6 = _slicedToArray(_ref5, 2),
510
- key = _ref6[0],
511
- value = _ref6[1];
458
+ Object.entries(block.props).forEach(([key, value]) => {
512
459
  // Convert kebab-case to camelCase for data attributes
513
- var camelKey = key.includes('-') ? "data".concat(key.split('-').map(function (part) {
514
- return part.charAt(0).toUpperCase() + part.slice(1);
515
- }).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
460
+ const camelKey = key.includes('-') ? `data${key.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('')}` : `data${key.charAt(0).toUpperCase() + key.slice(1)}`;
516
461
  codeHProperties[camelKey] = value;
517
462
  });
518
463
 
519
464
  // Add data-variant to track the variant
520
465
  codeHProperties.dataVariant = block.variant;
521
- var fileName = getFileName(block.actualLang, block.props);
466
+ const fileName = getFileName(block.props);
522
467
  return {
523
468
  type: 'element',
524
469
  tagName: 'figure',
@@ -535,7 +480,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
535
480
  },
536
481
  children: [{
537
482
  type: 'text',
538
- value: "".concat(block.variant, " variant")
483
+ value: `${block.variant} variant`
539
484
  }]
540
485
  }, {
541
486
  type: 'element',
@@ -544,7 +489,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
544
489
  hName: 'dl',
545
490
  hProperties: {}
546
491
  },
547
- children: [].concat(_toConsumableArray(fileName ? [{
492
+ children: [...(fileName ? [{
548
493
  type: 'element',
549
494
  tagName: 'dt',
550
495
  data: {
@@ -563,7 +508,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
563
508
  value: fileName
564
509
  }]
565
510
  }]
566
- }] : []), [{
511
+ }] : []), {
567
512
  type: 'element',
568
513
  tagName: 'dd',
569
514
  data: {
@@ -583,12 +528,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
583
528
  data: {
584
529
  hName: 'code',
585
530
  hProperties: codeHProperties,
586
- meta: "variant=".concat(block.variant).concat(Object.entries(block.props).map(function (_ref7) {
587
- var _ref8 = _slicedToArray(_ref7, 2),
588
- key = _ref8[0],
589
- value = _ref8[1];
590
- return " ".concat(key, "=").concat(value);
591
- }).join(''))
531
+ meta: `variant=${block.variant}${Object.entries(block.props).map(([key, value]) => ` ${key}=${value}`).join('')}`
592
532
  },
593
533
  children: [{
594
534
  type: 'text',
@@ -596,7 +536,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
596
536
  }]
597
537
  }]
598
538
  }]
599
- }])
539
+ }]
600
540
  }]
601
541
  };
602
542
  })
@@ -606,62 +546,48 @@ export var transformMarkdownCode = function transformMarkdownCode() {
606
546
  parentNode.children[codeBlocks[0].index] = sectionElement;
607
547
 
608
548
  // Remove all other code blocks and their labels (in reverse order to maintain indices)
609
- var indicesToRemove = codeBlocks.slice(1).map(function (block) {
610
- var indices = [block.index];
549
+ const indicesToRemove = codeBlocks.slice(1).map(block => {
550
+ const indices = [block.index];
611
551
  // Also include label paragraph if it exists
612
552
  if (block.labelFromPrevious && block.index > 0) {
613
- var _prevNode2 = parentNode.children[block.index - 1];
614
- if (_prevNode2.type === 'paragraph') {
553
+ const prevNode = parentNode.children[block.index - 1];
554
+ if (prevNode.type === 'paragraph') {
615
555
  indices.push(block.index - 1);
616
556
  }
617
557
  }
618
558
  return indices;
619
- }).flat().sort(function (a, b) {
620
- return b - a;
621
- }); // Sort in descending order
559
+ }).flat().sort((a, b) => b - a); // Sort in descending order
622
560
 
623
561
  // Remove the marked indices
624
- var _iterator2 = _createForOfIteratorHelper(indicesToRemove),
625
- _step2;
626
- try {
627
- var _loop = function _loop() {
628
- var removeIdx = _step2.value;
629
- if (removeIdx < parentNode.children.length) {
630
- parentNode.children.splice(removeIdx, 1);
631
- // Update processed indices to account for removed elements
632
- var _updatedProcessedIndices = new Set();
633
- processedIndices.forEach(function (processedIdx) {
634
- if (processedIdx > removeIdx) {
635
- _updatedProcessedIndices.add(processedIdx - 1);
636
- } else if (processedIdx < removeIdx) {
637
- _updatedProcessedIndices.add(processedIdx);
638
- }
639
- // Don't add the removed index
640
- });
641
- processedIndices.clear();
642
- _updatedProcessedIndices.forEach(function (processedIdx) {
643
- processedIndices.add(processedIdx);
644
- });
645
- }
646
- };
647
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
648
- _loop();
562
+ for (const removeIdx of indicesToRemove) {
563
+ if (removeIdx < parentNode.children.length) {
564
+ parentNode.children.splice(removeIdx, 1);
565
+ // Update processed indices to account for removed elements
566
+ const updatedProcessedIndices = new Set();
567
+ processedIndices.forEach(processedIdx => {
568
+ if (processedIdx > removeIdx) {
569
+ updatedProcessedIndices.add(processedIdx - 1);
570
+ } else if (processedIdx < removeIdx) {
571
+ updatedProcessedIndices.add(processedIdx);
572
+ }
573
+ // Don't add the removed index
574
+ });
575
+ processedIndices.clear();
576
+ updatedProcessedIndices.forEach(processedIdx => {
577
+ processedIndices.add(processedIdx);
578
+ });
649
579
  }
650
-
651
- // Also remove the label of the first block if it exists
652
- } catch (err) {
653
- _iterator2.e(err);
654
- } finally {
655
- _iterator2.f();
656
580
  }
581
+
582
+ // Also remove the label of the first block if it exists
657
583
  if (codeBlocks[0].labelFromPrevious && codeBlocks[0].index > 0) {
658
- var labelIndex = codeBlocks[0].index - 1;
659
- var _prevNode3 = parentNode.children[labelIndex];
660
- if (_prevNode3 && _prevNode3.type === 'paragraph') {
584
+ const labelIndex = codeBlocks[0].index - 1;
585
+ const prevNode = parentNode.children[labelIndex];
586
+ if (prevNode && prevNode.type === 'paragraph') {
661
587
  parentNode.children.splice(labelIndex, 1);
662
588
  // Update processed indices
663
- var updatedProcessedIndices = new Set();
664
- processedIndices.forEach(function (processedIdx) {
589
+ const updatedProcessedIndices = new Set();
590
+ processedIndices.forEach(processedIdx => {
665
591
  if (processedIdx > labelIndex) {
666
592
  updatedProcessedIndices.add(processedIdx - 1);
667
593
  } else if (processedIdx < labelIndex) {
@@ -669,44 +595,39 @@ export var transformMarkdownCode = function transformMarkdownCode() {
669
595
  }
670
596
  });
671
597
  processedIndices.clear();
672
- updatedProcessedIndices.forEach(function (processedIdx) {
598
+ updatedProcessedIndices.forEach(processedIdx => {
673
599
  processedIndices.add(processedIdx);
674
600
  });
675
601
  }
676
602
  }
677
603
  } else if (codeBlocks.length === 1) {
678
604
  // Single code block with variant - create a simple dl without figure wrapper
679
- var block = codeBlocks[0];
680
- var _codeHProperties = {};
605
+ const block = codeBlocks[0];
606
+ const codeHProperties = {};
681
607
 
682
- // Add language class if available
608
+ // Add normalized language as class
683
609
  if (block.actualLang) {
684
- _codeHProperties.className = "language-".concat(block.actualLang);
610
+ codeHProperties.className = `language-${normalizeLanguage(block.actualLang)}`;
685
611
  }
686
612
 
687
613
  // Add additional props as data attributes (in camelCase)
688
- Object.entries(block.props).forEach(function (_ref9) {
689
- var _ref0 = _slicedToArray(_ref9, 2),
690
- key = _ref0[0],
691
- value = _ref0[1];
614
+ Object.entries(block.props).forEach(([key, value]) => {
692
615
  // Convert kebab-case to camelCase for data attributes
693
- var camelKey = key.includes('-') ? "data".concat(key.split('-').map(function (part) {
694
- return part.charAt(0).toUpperCase() + part.slice(1);
695
- }).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
696
- _codeHProperties[camelKey] = value;
616
+ const camelKey = key.includes('-') ? `data${key.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('')}` : `data${key.charAt(0).toUpperCase() + key.slice(1)}`;
617
+ codeHProperties[camelKey] = value;
697
618
  });
698
619
 
699
620
  // Add data-variant to track the variant
700
- _codeHProperties.dataVariant = block.variant;
701
- var _fileName = getFileName(block.actualLang, block.props);
702
- var _dlElement = {
621
+ codeHProperties.dataVariant = block.variant;
622
+ const fileName = getFileName(block.props);
623
+ const dlElement = {
703
624
  type: 'element',
704
625
  tagName: 'dl',
705
626
  data: {
706
627
  hName: 'dl',
707
628
  hProperties: {}
708
629
  },
709
- children: [].concat(_toConsumableArray(_fileName ? [{
630
+ children: [...(fileName ? [{
710
631
  type: 'element',
711
632
  tagName: 'dt',
712
633
  data: {
@@ -722,10 +643,10 @@ export var transformMarkdownCode = function transformMarkdownCode() {
722
643
  },
723
644
  children: [{
724
645
  type: 'text',
725
- value: _fileName
646
+ value: fileName
726
647
  }]
727
648
  }]
728
- }] : []), [{
649
+ }] : []), {
729
650
  type: 'element',
730
651
  tagName: 'dd',
731
652
  data: {
@@ -744,13 +665,8 @@ export var transformMarkdownCode = function transformMarkdownCode() {
744
665
  tagName: 'code',
745
666
  data: {
746
667
  hName: 'code',
747
- hProperties: _codeHProperties,
748
- meta: "variant=".concat(block.variant).concat(Object.entries(block.props).map(function (_ref1) {
749
- var _ref10 = _slicedToArray(_ref1, 2),
750
- key = _ref10[0],
751
- value = _ref10[1];
752
- return " ".concat(key, "=").concat(value);
753
- }).join(''))
668
+ hProperties: codeHProperties,
669
+ meta: `variant=${block.variant}${Object.entries(block.props).map(([key, value]) => ` ${key}=${value}`).join('')}`
754
670
  },
755
671
  children: [{
756
672
  type: 'text',
@@ -758,11 +674,11 @@ export var transformMarkdownCode = function transformMarkdownCode() {
758
674
  }]
759
675
  }]
760
676
  }]
761
- }])
677
+ }]
762
678
  };
763
679
 
764
680
  // Replace this single code block
765
- parentNode.children[codeBlocks[0].index] = _dlElement;
681
+ parentNode.children[codeBlocks[0].index] = dlElement;
766
682
  }
767
683
  }
768
684
  }