@mui/internal-docs-infra 0.3.1-canary.1 → 0.3.1-canary.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.
@@ -2,6 +2,8 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import { visit } from 'unist-util-visit';
5
+ import { normalizeLanguage } from "../loaderUtils/getLanguageFromExtension.js";
6
+
5
7
  /**
6
8
  * Remark plugin that transforms code blocks with variants into semantic HTML structures.
7
9
  *
@@ -54,67 +56,36 @@ import { visit } from 'unist-util-visit';
54
56
  * <dl>
55
57
  * <dt><code>index.js</code></dt>
56
58
  * <dd>
57
- * <pre><code class="language-bash">pnpm install @mui/internal-docs-infra</code></pre>
59
+ * <pre><code class="language-shell">pnpm install @mui/internal-docs-infra</code></pre>
58
60
  * </dd>
59
61
  * </dl>
60
62
  * </figure>
61
63
  * </section>
62
64
  *
63
- * Or for individual blocks (no figure/figcaption needed):
65
+ * Or for individual blocks without filename (no dl wrapper needed):
66
+ * <pre><code class="language-typescript" data-transform="true">console.log('test' as const)</code></pre>
67
+ *
68
+ * Or with explicit filename (uses dl/dt/dd structure):
64
69
  * <dl>
65
- * <dt><code>index.ts</code></dt>
70
+ * <dt><code>example.ts</code></dt>
66
71
  * <dd>
67
- * <pre><code class="language-ts" data-transform="true">console.log('test' as const)</code></pre>
72
+ * <pre><code class="language-typescript">console.log('test' as const)</code></pre>
68
73
  * </dd>
69
74
  * </dl>
75
+ *
76
+ * Note: The `dl/dt/dd` structure is only used when an explicit `filename` prop is provided.
77
+ * Language information is passed via the `class="language-*"` attribute on the code element.
70
78
  */
71
79
 
72
80
  /**
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
81
+ * Gets filename from explicit filename prop only.
82
+ * Does not derive filename from language - language is passed via className instead.
107
83
  */
108
- function getFileName(language, props) {
109
- // Check for explicit filename
84
+ function getFileName(props) {
85
+ // Only return explicit filename
110
86
  if (props.filename) {
111
87
  return props.filename;
112
88
  }
113
-
114
- // Derive from language
115
- if (language && LANGUAGE_TO_EXTENSION[language]) {
116
- return "index.".concat(LANGUAGE_TO_EXTENSION[language]);
117
- }
118
89
  return null;
119
90
  }
120
91
 
@@ -230,12 +201,11 @@ export var transformMarkdownCode = function transformMarkdownCode() {
230
201
 
231
202
  // Handle individual code blocks with options (but no variants)
232
203
  if (!metaData.variant && !metaData.variantType && Object.keys(allProps).length > 0) {
233
- // Create a dl element for individual blocks with options
234
204
  var codeHProperties = {};
235
205
 
236
- // Add language class if available
206
+ // Add normalized language as class
237
207
  if (langFromMeta) {
238
- codeHProperties.className = "language-".concat(langFromMeta);
208
+ codeHProperties.className = "language-".concat(normalizeLanguage(langFromMeta));
239
209
  }
240
210
 
241
211
  // Add all props as data attributes (in camelCase)
@@ -249,15 +219,40 @@ export var transformMarkdownCode = function transformMarkdownCode() {
249
219
  }).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
250
220
  codeHProperties[camelKey] = value;
251
221
  });
252
- var fileName = getFileName(langFromMeta, allProps);
253
- var dlElement = {
222
+ var fileName = getFileName(allProps);
223
+
224
+ // Create pre > code element
225
+ var preElement = {
226
+ type: 'element',
227
+ tagName: 'pre',
228
+ data: {
229
+ hName: 'pre',
230
+ hProperties: {}
231
+ },
232
+ children: [{
233
+ type: 'element',
234
+ tagName: 'code',
235
+ data: {
236
+ hName: 'code',
237
+ hProperties: codeHProperties
238
+ },
239
+ children: [{
240
+ type: 'text',
241
+ value: codeNode.value
242
+ }]
243
+ }]
244
+ };
245
+
246
+ // If there's a filename, wrap in dl/dt/dd structure
247
+ // Otherwise, just use pre > code directly
248
+ var outputElement = fileName ? {
254
249
  type: 'element',
255
250
  tagName: 'dl',
256
251
  data: {
257
252
  hName: 'dl',
258
253
  hProperties: {}
259
254
  },
260
- children: [].concat(_toConsumableArray(fileName ? [{
255
+ children: [{
261
256
  type: 'element',
262
257
  tagName: 'dt',
263
258
  data: {
@@ -276,38 +271,19 @@ export var transformMarkdownCode = function transformMarkdownCode() {
276
271
  value: fileName
277
272
  }]
278
273
  }]
279
- }] : []), [{
274
+ }, {
280
275
  type: 'element',
281
276
  tagName: 'dd',
282
277
  data: {
283
278
  hName: 'dd',
284
279
  hProperties: {}
285
280
  },
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
- };
281
+ children: [preElement]
282
+ }]
283
+ } : preElement;
308
284
 
309
285
  // Replace this individual code block immediately
310
- parentNode.children[index] = dlElement;
286
+ parentNode.children[index] = outputElement;
311
287
  processedIndices.add(index);
312
288
  return;
313
289
  }
@@ -499,9 +475,9 @@ export var transformMarkdownCode = function transformMarkdownCode() {
499
475
  // Build hProperties for HTML attributes
500
476
  var codeHProperties = {};
501
477
 
502
- // Add language class if available
478
+ // Add normalized language as class
503
479
  if (block.actualLang) {
504
- codeHProperties.className = "language-".concat(block.actualLang);
480
+ codeHProperties.className = "language-".concat(normalizeLanguage(block.actualLang));
505
481
  }
506
482
 
507
483
  // Add additional props as data attributes (in camelCase)
@@ -518,7 +494,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
518
494
 
519
495
  // Add data-variant to track the variant
520
496
  codeHProperties.dataVariant = block.variant;
521
- var fileName = getFileName(block.actualLang, block.props);
497
+ var fileName = getFileName(block.props);
522
498
  return {
523
499
  type: 'element',
524
500
  tagName: 'figure',
@@ -679,9 +655,9 @@ export var transformMarkdownCode = function transformMarkdownCode() {
679
655
  var block = codeBlocks[0];
680
656
  var _codeHProperties = {};
681
657
 
682
- // Add language class if available
658
+ // Add normalized language as class
683
659
  if (block.actualLang) {
684
- _codeHProperties.className = "language-".concat(block.actualLang);
660
+ _codeHProperties.className = "language-".concat(normalizeLanguage(block.actualLang));
685
661
  }
686
662
 
687
663
  // Add additional props as data attributes (in camelCase)
@@ -698,8 +674,8 @@ export var transformMarkdownCode = function transformMarkdownCode() {
698
674
 
699
675
  // Add data-variant to track the variant
700
676
  _codeHProperties.dataVariant = block.variant;
701
- var _fileName = getFileName(block.actualLang, block.props);
702
- var _dlElement = {
677
+ var _fileName = getFileName(block.props);
678
+ var dlElement = {
703
679
  type: 'element',
704
680
  tagName: 'dl',
705
681
  data: {
@@ -762,7 +738,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
762
738
  };
763
739
 
764
740
  // Replace this single code block
765
- parentNode.children[codeBlocks[0].index] = _dlElement;
741
+ parentNode.children[codeBlocks[0].index] = dlElement;
766
742
  }
767
743
  }
768
744
  }
@@ -305,8 +305,8 @@ function toPageMetadata(metadata, filePath) {
305
305
  descriptionMarkdown: (_options$visibleDescr2 = options.visibleDescriptionMarkdown) != null ? _options$visibleDescr2 : metadata.descriptionMarkdown,
306
306
  keywords: metadata.keywords,
307
307
  sections: metadata.sections,
308
- openGraph: metadata.openGraph,
309
- embeddings: metadata.embeddings
308
+ embeddings: metadata.embeddings,
309
+ image: metadata.image
310
310
  };
311
311
  }
312
312
 
@@ -720,26 +720,6 @@ export var transformMarkdownMetadata = function transformMarkdownMetadata() {
720
720
  shouldUpdateMetadata = true;
721
721
  }
722
722
 
723
- // Fill in openGraph title and description if missing
724
- if (!mutableMetadata.openGraph) {
725
- mutableMetadata.openGraph = {};
726
- }
727
- if (firstH1 && !mutableMetadata.openGraph.title) {
728
- mutableMetadata.openGraph.title = firstH1;
729
- shouldUpdateMetadata = true;
730
- }
731
-
732
- // Prioritize meta tag description over paragraph for openGraph
733
- if (!mutableMetadata.openGraph.description) {
734
- if (metaDescription) {
735
- mutableMetadata.openGraph.description = metaDescription;
736
- shouldUpdateMetadata = true;
737
- } else if (firstParagraphAfterH1) {
738
- mutableMetadata.openGraph.description = firstParagraphAfterH1;
739
- shouldUpdateMetadata = true;
740
- }
741
- }
742
-
743
723
  // Add sections hierarchy if we have headings
744
724
  hasSections = mutableMetadata.sections && Object.keys(mutableMetadata.sections).length > 0;
745
725
  if (headings.length > 1 && !hasSections) {
@@ -768,11 +748,7 @@ export var transformMarkdownMetadata = function transformMarkdownMetadata() {
768
748
  description: descriptionValue,
769
749
  descriptionMarkdown: descriptionMarkdownValue,
770
750
  keywords: metaKeywords || undefined,
771
- sections: headings.length > 1 ? buildHeadingHierarchy(headings) : undefined,
772
- openGraph: {
773
- title: firstH1 || undefined,
774
- description: descriptionValue
775
- }
751
+ sections: headings.length > 1 ? buildHeadingHierarchy(headings) : undefined
776
752
  };
777
753
 
778
754
  // Create a new metadata export and add it to the tree
@@ -863,7 +839,7 @@ export var transformMarkdownMetadata = function transformMarkdownMetadata() {
863
839
  exports: page.exports,
864
840
  tags: page.tags,
865
841
  skipDetailSection: page.skipDetailSection,
866
- openGraph: page.openGraph
842
+ image: page.image
867
843
  };
868
844
  })
869
845
  }; // Find and update the wrapper component in the AST
@@ -97,14 +97,8 @@ export interface ExtractedMetadata {
97
97
  keywords?: string[];
98
98
  sections?: HeadingHierarchy;
99
99
  embeddings?: number[];
100
- openGraph?: {
101
- title?: string;
102
- description?: string;
103
- images?: Array<{
104
- url: string;
105
- width: number;
106
- height: number;
107
- alt: string;
108
- }>;
100
+ image?: {
101
+ url: string;
102
+ alt?: string;
109
103
  };
110
104
  }
@@ -3,12 +3,14 @@ import type { VariantSource } from "../CodeHighlighter/types.js";
3
3
  export declare function Pre({
4
4
  children,
5
5
  className,
6
+ language,
6
7
  ref,
7
8
  shouldHighlight,
8
9
  hydrateMargin
9
10
  }: {
10
11
  children: VariantSource;
11
12
  className?: string;
13
+ language?: string;
12
14
  ref?: React.Ref<HTMLPreElement>;
13
15
  shouldHighlight?: boolean;
14
16
  hydrateMargin?: string;
@@ -41,6 +41,7 @@ function renderCode(hastChildren, renderHast, text) {
41
41
  export function Pre(_ref) {
42
42
  var children = _ref.children,
43
43
  className = _ref.className,
44
+ language = _ref.language,
44
45
  ref = _ref.ref,
45
46
  shouldHighlight = _ref.shouldHighlight,
46
47
  _ref$hydrateMargin = _ref.hydrateMargin,
@@ -162,6 +163,7 @@ export function Pre(_ref) {
162
163
  ref: bindIntersectionObserver,
163
164
  className: className,
164
165
  children: /*#__PURE__*/_jsx("code", {
166
+ className: language ? "language-".concat(language) : undefined,
165
167
  children: typeof children === 'string' ? children : frames
166
168
  })
167
169
  });
@@ -6,14 +6,32 @@ import { decompressSync, strFromU8 } from 'fflate';
6
6
  import { decode } from 'uint8-to-base64';
7
7
  import { useUrlHashState } from "../useUrlHashState/index.js";
8
8
  import { countLines } from "../pipeline/parseSource/addLineGutters.js";
9
+ import { getLanguageFromExtension } from "../pipeline/loaderUtils/getLanguageFromExtension.js";
9
10
  import { Pre } from "./Pre.js";
10
11
 
12
+ /**
13
+ * Gets the language from a filename by extracting its extension.
14
+ * @param fileName - The filename (e.g., 'index.tsx', 'styles.css')
15
+ * @returns The language name or undefined
16
+ */
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ function getLanguageFromFileName(fileName) {
19
+ if (!fileName) {
20
+ return undefined;
21
+ }
22
+ var lastDotIndex = fileName.lastIndexOf('.');
23
+ if (lastDotIndex === -1) {
24
+ return undefined;
25
+ }
26
+ var extension = fileName.substring(lastDotIndex);
27
+ return getLanguageFromExtension(extension);
28
+ }
29
+
11
30
  /**
12
31
  * Converts a string to kebab-case
13
32
  * @param str - The string to convert
14
33
  * @returns kebab-case string
15
34
  */
16
- import { jsx as _jsx } from "react/jsx-runtime";
17
35
  export function toKebabCase(str) {
18
36
  return str
19
37
  // Insert a dash before any uppercase letter that follows a lowercase letter or digit
@@ -402,6 +420,7 @@ export function useFileNavigation(_ref) {
402
420
  }
403
421
  return /*#__PURE__*/_jsx(Pre, {
404
422
  className: preClassName,
423
+ language: selectedVariant.language,
405
424
  ref: preRef,
406
425
  shouldHighlight: shouldHighlight,
407
426
  children: selectedVariant.source
@@ -424,6 +443,7 @@ export function useFileNavigation(_ref) {
424
443
  }
425
444
  return /*#__PURE__*/_jsx(Pre, {
426
445
  className: preClassName,
446
+ language: getLanguageFromFileName(selectedFileNameInternal),
427
447
  ref: preRef,
428
448
  shouldHighlight: shouldHighlight,
429
449
  children: source
@@ -497,6 +517,7 @@ export function useFileNavigation(_ref) {
497
517
  slug: generateFileSlug(mainSlug, selectedVariant.fileName, selectedVariantKey),
498
518
  component: /*#__PURE__*/_jsx(Pre, {
499
519
  className: preClassName,
520
+ language: selectedVariant.language,
500
521
  ref: preRef,
501
522
  shouldHighlight: shouldHighlight,
502
523
  children: selectedVariant.source
@@ -509,10 +530,12 @@ export function useFileNavigation(_ref) {
509
530
  fileName = _ref3[0],
510
531
  fileData = _ref3[1];
511
532
  var source;
533
+ var language;
512
534
  if (typeof fileData === 'string') {
513
535
  source = fileData;
514
536
  } else if (fileData && _typeof(fileData) === 'object' && 'source' in fileData) {
515
537
  source = fileData.source;
538
+ language = fileData.language;
516
539
  } else {
517
540
  return; // Skip invalid entries
518
541
  }
@@ -524,6 +547,7 @@ export function useFileNavigation(_ref) {
524
547
  slug: generateFileSlug(mainSlug, fileName, selectedVariantKey),
525
548
  component: /*#__PURE__*/_jsx(Pre, {
526
549
  className: preClassName,
550
+ language: language != null ? language : getLanguageFromFileName(fileName),
527
551
  ref: preRef,
528
552
  shouldHighlight: shouldHighlight,
529
553
  children: source
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.3.1-canary.1",
3
+ "version": "0.3.1-canary.3",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "bin": {
@@ -329,5 +329,5 @@
329
329
  },
330
330
  "./esm": null
331
331
  },
332
- "gitSha": "04aa71c45b922602c25a926df3a7e17cb3744ac1"
332
+ "gitSha": "d451af44f7bc27fd589bdeda8f07395fa2037ad8"
333
333
  }