@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.
- package/esm/CodeHighlighter/CodeHighlighter.js +8 -1
- package/esm/CodeHighlighter/types.d.ts +7 -1
- package/esm/createSitemap/types.d.ts +3 -9
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +7 -2
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +101 -50
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.d.ts +24 -0
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +63 -0
- package/esm/pipeline/loaderUtils/index.d.ts +2 -1
- package/esm/pipeline/loaderUtils/index.js +2 -1
- package/esm/pipeline/parseSource/grammars.d.ts +12 -1
- package/esm/pipeline/parseSource/grammars.js +34 -2
- package/esm/pipeline/parseSource/index.d.ts +2 -1
- package/esm/pipeline/parseSource/index.js +2 -1
- package/esm/pipeline/parseSource/parseSource.js +14 -5
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +1 -6
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +12 -35
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +130 -86
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +59 -83
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +4 -28
- package/esm/pipeline/transformMarkdownMetadata/types.d.ts +3 -9
- package/esm/useCode/Pre.d.ts +2 -0
- package/esm/useCode/Pre.js +2 -0
- package/esm/useCode/useFileNavigation.js +25 -1
- package/package.json +2 -2
|
@@ -10,7 +10,7 @@ import { loadCodeFallback } from "../pipeline/loadCodeVariant/loadCodeFallback.j
|
|
|
10
10
|
import { CodeHighlighterClient } from "./CodeHighlighterClient.js";
|
|
11
11
|
import { maybeCodeInitialData } from "../pipeline/loadCodeVariant/maybeCodeInitialData.js";
|
|
12
12
|
import { hasAllVariants } from "../pipeline/loadCodeVariant/hasAllCodeVariants.js";
|
|
13
|
-
import { getFileNameFromUrl } from "../pipeline/loaderUtils/
|
|
13
|
+
import { getFileNameFromUrl, getLanguageFromExtension } from "../pipeline/loaderUtils/index.js";
|
|
14
14
|
import { codeToFallbackProps } from "./codeToFallbackProps.js";
|
|
15
15
|
import * as Errors from "./errors.js";
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -375,9 +375,16 @@ export function CodeHighlighter(props) {
|
|
|
375
375
|
var code = props.code;
|
|
376
376
|
if (props.children && typeof props.children === 'string') {
|
|
377
377
|
var fileName = props.fileName || (props.url ? getFileNameFromUrl(props.url).fileName : undefined);
|
|
378
|
+
// Derive language: use explicit prop, or derive from fileName extension
|
|
379
|
+
var language = props.language;
|
|
380
|
+
if (!language && fileName) {
|
|
381
|
+
var extension = fileName.slice(fileName.lastIndexOf('.'));
|
|
382
|
+
language = getLanguageFromExtension(extension);
|
|
383
|
+
}
|
|
378
384
|
code = {
|
|
379
385
|
Default: {
|
|
380
386
|
fileName: fileName,
|
|
387
|
+
language: language,
|
|
381
388
|
source: props.children,
|
|
382
389
|
url: props.url
|
|
383
390
|
}
|
|
@@ -6,6 +6,8 @@ export type Components = {
|
|
|
6
6
|
type CodeMeta = {
|
|
7
7
|
/** Name of the file (e.g., 'Button.tsx') */
|
|
8
8
|
fileName?: string;
|
|
9
|
+
/** Language for syntax highlighting (e.g., 'tsx', 'css'). When provided, fileName is not required. */
|
|
10
|
+
language?: string;
|
|
9
11
|
/** Flattened path for the file */
|
|
10
12
|
path?: string;
|
|
11
13
|
};
|
|
@@ -37,6 +39,8 @@ export type VariantExtraFiles = {
|
|
|
37
39
|
[fileName: string]: string | {
|
|
38
40
|
/** Source content for this file */
|
|
39
41
|
source?: VariantSource;
|
|
42
|
+
/** Language for syntax highlighting (e.g., 'tsx', 'css'). Derived from fileName extension if not provided. */
|
|
43
|
+
language?: string;
|
|
40
44
|
/** Transformations that can be applied to this file */
|
|
41
45
|
transforms?: Transforms;
|
|
42
46
|
/** Skip generating source transformers for this file */
|
|
@@ -123,7 +127,7 @@ export type TransformSource = (source: string, fileName: string) => Promise<Reco
|
|
|
123
127
|
source: string;
|
|
124
128
|
fileName?: string;
|
|
125
129
|
}> | undefined>;
|
|
126
|
-
export type ParseSource = (source: string, fileName: string) => HastRoot;
|
|
130
|
+
export type ParseSource = (source: string, fileName: string, language?: string) => HastRoot;
|
|
127
131
|
export type SourceTransformer = {
|
|
128
132
|
extensions: string[];
|
|
129
133
|
transformer: TransformSource;
|
|
@@ -190,6 +194,8 @@ export interface CodeContentProps {
|
|
|
190
194
|
variant?: string;
|
|
191
195
|
/** Currently selected file name */
|
|
192
196
|
fileName?: string;
|
|
197
|
+
/** Language for syntax highlighting (e.g., 'tsx', 'css'). When provided, fileName is not required for parsing. */
|
|
198
|
+
language?: string;
|
|
193
199
|
/** Default variant to show on first load */
|
|
194
200
|
initialVariant?: string;
|
|
195
201
|
/** Fallback variant when the requested variant is not available */
|
|
@@ -35,15 +35,9 @@ export interface SitemapPage {
|
|
|
35
35
|
exports?: Record<string, SitemapExport>;
|
|
36
36
|
tags?: string[];
|
|
37
37
|
skipDetailSection?: boolean;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
images?: Array<{
|
|
42
|
-
url: string;
|
|
43
|
-
width: number;
|
|
44
|
-
height: number;
|
|
45
|
-
alt: string;
|
|
46
|
-
}>;
|
|
38
|
+
image?: {
|
|
39
|
+
url: string;
|
|
40
|
+
alt?: string;
|
|
47
41
|
};
|
|
48
42
|
}
|
|
49
43
|
/**
|
|
@@ -5,7 +5,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
5
5
|
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
6
6
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
7
|
import { loadCodeVariant } from "./loadCodeVariant.js";
|
|
8
|
-
import { getFileNameFromUrl } from "../loaderUtils/index.js";
|
|
8
|
+
import { getFileNameFromUrl, getLanguageFromExtension } from "../loaderUtils/index.js";
|
|
9
9
|
import { performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
|
|
10
10
|
|
|
11
11
|
// Helper function to get the source for a specific filename from a variant
|
|
@@ -110,6 +110,8 @@ function _loadCodeFallback() {
|
|
|
110
110
|
result,
|
|
111
111
|
parseSource,
|
|
112
112
|
quickVariant,
|
|
113
|
+
derivedFileName,
|
|
114
|
+
extension,
|
|
113
115
|
beforeInitialVariantMark,
|
|
114
116
|
_allFileNames2,
|
|
115
117
|
_fileSource,
|
|
@@ -307,9 +309,12 @@ function _loadCodeFallback() {
|
|
|
307
309
|
break;
|
|
308
310
|
case 20:
|
|
309
311
|
// Create a basic variant using fallback logic
|
|
312
|
+
derivedFileName = getFileNameFromUrl(initial).fileName;
|
|
313
|
+
extension = derivedFileName.slice(derivedFileName.lastIndexOf('.'));
|
|
310
314
|
quickVariant = {
|
|
311
315
|
url: initial,
|
|
312
|
-
fileName:
|
|
316
|
+
fileName: derivedFileName,
|
|
317
|
+
language: getLanguageFromExtension(extension)
|
|
313
318
|
};
|
|
314
319
|
case 21:
|
|
315
320
|
beforeInitialVariantMark = currentMark;
|
|
@@ -10,7 +10,7 @@ import { compress, strToU8 } from 'fflate';
|
|
|
10
10
|
import { encode } from 'uint8-to-base64';
|
|
11
11
|
import { transformSource } from "./transformSource.js";
|
|
12
12
|
import { diffHast } from "./diffHast.js";
|
|
13
|
-
import { getFileNameFromUrl } from "../loaderUtils/index.js";
|
|
13
|
+
import { getFileNameFromUrl, getLanguageFromExtension, normalizeLanguage } from "../loaderUtils/index.js";
|
|
14
14
|
import { mergeExternals } from "../loaderUtils/mergeExternals.js";
|
|
15
15
|
import { performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
|
|
16
16
|
function compressAsync(input) {
|
|
@@ -144,6 +144,7 @@ function _loadSingleFile() {
|
|
|
144
144
|
var options,
|
|
145
145
|
allFilesListed,
|
|
146
146
|
knownExtraFiles,
|
|
147
|
+
language,
|
|
147
148
|
_options$disableTrans,
|
|
148
149
|
disableTransforms,
|
|
149
150
|
_options$disableParsi,
|
|
@@ -184,6 +185,7 @@ function _loadSingleFile() {
|
|
|
184
185
|
options = _args.length > 9 && _args[9] !== undefined ? _args[9] : {};
|
|
185
186
|
allFilesListed = _args.length > 10 && _args[10] !== undefined ? _args[10] : false;
|
|
186
187
|
knownExtraFiles = _args.length > 11 && _args[11] !== undefined ? _args[11] : new Set();
|
|
188
|
+
language = _args.length > 12 ? _args[12] : undefined;
|
|
187
189
|
_options$disableTrans = options.disableTransforms, disableTransforms = _options$disableTrans === void 0 ? false : _options$disableTrans, _options$disableParsi = options.disableParsing, disableParsing = _options$disableParsi === void 0 ? false : _options$disableParsi;
|
|
188
190
|
finalSource = source;
|
|
189
191
|
functionName = 'Load Variant File';
|
|
@@ -367,7 +369,7 @@ function _loadSingleFile() {
|
|
|
367
369
|
return sourceParser;
|
|
368
370
|
case 24:
|
|
369
371
|
parseSource = _context.v;
|
|
370
|
-
finalSource = parseSource(finalSource, fileName);
|
|
372
|
+
finalSource = parseSource(finalSource, fileName, language);
|
|
371
373
|
currentMark = performanceMeasure(currentMark, {
|
|
372
374
|
mark: 'Parsed File',
|
|
373
375
|
measure: 'File Parsing'
|
|
@@ -504,7 +506,7 @@ function _loadExtraFiles() {
|
|
|
504
506
|
allExternals = {}; // Start loading all extra files in parallel
|
|
505
507
|
extraFilePromises = Object.entries(extraFiles).map(/*#__PURE__*/function () {
|
|
506
508
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref) {
|
|
507
|
-
var _ref3, fileName, fileData, fileUrl, sourceData, transforms, fileResult, filesUsedFromFile, externalsFromFile, _t5;
|
|
509
|
+
var _ref3, fileName, fileData, fileUrl, sourceData, transforms, extraFileExtension, extraFileLanguage, fileResult, filesUsedFromFile, externalsFromFile, _t5;
|
|
508
510
|
return _regenerator().w(function (_context2) {
|
|
509
511
|
while (1) switch (_context2.p = _context2.n) {
|
|
510
512
|
case 0:
|
|
@@ -533,11 +535,14 @@ function _loadExtraFiles() {
|
|
|
533
535
|
transforms = fileData.transforms;
|
|
534
536
|
fileUrl = baseUrl; // Use base URL as fallback
|
|
535
537
|
case 4:
|
|
538
|
+
// Derive language from fileName for extra files
|
|
539
|
+
extraFileExtension = fileName.slice(fileName.lastIndexOf('.'));
|
|
540
|
+
extraFileLanguage = getLanguageFromExtension(extraFileExtension); // Load the file (this will handle recursive extra files)
|
|
536
541
|
_context2.n = 5;
|
|
537
542
|
return loadSingleFile(variantName, fileName, sourceData, fileUrl, loadSource, sourceParser, sourceTransformers, loadSourceCache, transforms, _extends(_extends({}, options), {}, {
|
|
538
543
|
maxDepth: maxDepth - 1,
|
|
539
544
|
loadedFiles: new Set(loadedFiles)
|
|
540
|
-
}), allFilesListed, knownExtraFiles);
|
|
545
|
+
}), allFilesListed, knownExtraFiles, extraFileLanguage);
|
|
541
546
|
case 5:
|
|
542
547
|
fileResult = _context2.v;
|
|
543
548
|
// Collect files used from this file load
|
|
@@ -582,7 +587,7 @@ function _loadExtraFiles() {
|
|
|
582
587
|
_iterator2 = _createForOfIteratorHelper(extraFileResults);
|
|
583
588
|
_context4.p = 3;
|
|
584
589
|
_loop = /*#__PURE__*/_regenerator().m(function _loop() {
|
|
585
|
-
var _step2$value, fileName, result, filesUsed, externals, normalizedFileName, originalFileData, metadata, mergedExternals, sourceFileUrl, fileData;
|
|
590
|
+
var _step2$value, fileName, result, filesUsed, externals, normalizedFileName, originalFileData, metadata, extraFileExtension, extraFileLanguage, mergedExternals, sourceFileUrl, fileData;
|
|
586
591
|
return _regenerator().w(function (_context3) {
|
|
587
592
|
while (1) switch (_context3.n) {
|
|
588
593
|
case 0:
|
|
@@ -594,10 +599,17 @@ function _loadExtraFiles() {
|
|
|
594
599
|
} else if (globalsFileKeys.has(fileName)) {
|
|
595
600
|
metadata = true;
|
|
596
601
|
}
|
|
597
|
-
|
|
598
|
-
|
|
602
|
+
|
|
603
|
+
// Derive language from fileName extension for extra files
|
|
604
|
+
extraFileExtension = normalizedFileName.slice(normalizedFileName.lastIndexOf('.'));
|
|
605
|
+
extraFileLanguage = getLanguageFromExtension(extraFileExtension);
|
|
606
|
+
processedExtraFiles[normalizedFileName] = _extends(_extends(_extends({
|
|
607
|
+
source: result.source
|
|
608
|
+
}, extraFileLanguage && {
|
|
609
|
+
language: extraFileLanguage
|
|
610
|
+
}), result.transforms && {
|
|
599
611
|
transforms: result.transforms
|
|
600
|
-
}, metadata !== undefined && {
|
|
612
|
+
}), metadata !== undefined && {
|
|
601
613
|
metadata: metadata
|
|
602
614
|
});
|
|
603
615
|
|
|
@@ -712,6 +724,7 @@ function _loadCodeVariant() {
|
|
|
712
724
|
loadVariantMeta,
|
|
713
725
|
sourceTransformers,
|
|
714
726
|
globalsCode,
|
|
727
|
+
disableParsing,
|
|
715
728
|
loadSourceCache,
|
|
716
729
|
functionName,
|
|
717
730
|
currentMark,
|
|
@@ -725,6 +738,10 @@ function _loadCodeVariant() {
|
|
|
725
738
|
_Object$keys2,
|
|
726
739
|
extraFileName,
|
|
727
740
|
fileName,
|
|
741
|
+
language,
|
|
742
|
+
extension,
|
|
743
|
+
finalSource,
|
|
744
|
+
parseSource,
|
|
728
745
|
_finalVariant,
|
|
729
746
|
mainFileResult,
|
|
730
747
|
_i5,
|
|
@@ -761,6 +778,8 @@ function _loadCodeVariant() {
|
|
|
761
778
|
_key3,
|
|
762
779
|
_value2,
|
|
763
780
|
metadata,
|
|
781
|
+
_extension,
|
|
782
|
+
extraFileLanguage,
|
|
764
783
|
urlFilesToLoad,
|
|
765
784
|
_i0,
|
|
766
785
|
_Object$entries6,
|
|
@@ -782,7 +801,7 @@ function _loadCodeVariant() {
|
|
|
782
801
|
}
|
|
783
802
|
throw new Error("Variant is missing from code: ".concat(variantName));
|
|
784
803
|
case 1:
|
|
785
|
-
sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, sourceTransformers = options.sourceTransformers, globalsCode = options.globalsCode; // Create a cache for loadSource calls scoped to this loadCodeVariant call
|
|
804
|
+
sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, sourceTransformers = options.sourceTransformers, globalsCode = options.globalsCode, disableParsing = options.disableParsing; // Create a cache for loadSource calls scoped to this loadCodeVariant call
|
|
786
805
|
loadSourceCache = new Map();
|
|
787
806
|
functionName = 'Load Variant';
|
|
788
807
|
currentMark = performanceMeasure(undefined, {
|
|
@@ -845,20 +864,46 @@ function _loadCodeVariant() {
|
|
|
845
864
|
}
|
|
846
865
|
|
|
847
866
|
// Load main file
|
|
848
|
-
fileName = variant.fileName || (url ? getFileNameFromUrl(url).fileName : undefined); //
|
|
867
|
+
fileName = variant.fileName || (url ? getFileNameFromUrl(url).fileName : undefined); // Derive language from variant.language or from fileName extension
|
|
868
|
+
// Normalize the language to its canonical form (e.g., 'js' -> 'javascript')
|
|
869
|
+
language = variant.language ? normalizeLanguage(variant.language) : undefined;
|
|
870
|
+
if (!language && fileName) {
|
|
871
|
+
extension = fileName.slice(fileName.lastIndexOf('.'));
|
|
872
|
+
language = getLanguageFromExtension(extension);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// If we don't have a fileName and no URL, we can still parse if we have language
|
|
849
876
|
if (!(!fileName && !url)) {
|
|
850
|
-
_context6.n =
|
|
877
|
+
_context6.n = 11;
|
|
851
878
|
break;
|
|
852
879
|
}
|
|
853
|
-
//
|
|
854
|
-
|
|
855
|
-
|
|
880
|
+
finalSource = variant.source; // Parse the source if we have language and sourceParser
|
|
881
|
+
if (!(typeof finalSource === 'string' && language && sourceParser && !disableParsing)) {
|
|
882
|
+
_context6.n = 9;
|
|
883
|
+
break;
|
|
884
|
+
}
|
|
885
|
+
_context6.n = 8;
|
|
886
|
+
return sourceParser;
|
|
887
|
+
case 8:
|
|
888
|
+
parseSource = _context6.v;
|
|
889
|
+
finalSource = parseSource(finalSource, '', language);
|
|
890
|
+
_context6.n = 10;
|
|
891
|
+
break;
|
|
892
|
+
case 9:
|
|
893
|
+
if (typeof finalSource === 'string') {
|
|
894
|
+
// No language or parser - return as plain text
|
|
895
|
+
finalSource = {
|
|
856
896
|
type: 'root',
|
|
857
897
|
children: [{
|
|
858
898
|
type: 'text',
|
|
859
|
-
value:
|
|
899
|
+
value: finalSource || ''
|
|
860
900
|
}]
|
|
861
|
-
}
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
case 10:
|
|
904
|
+
_finalVariant = _extends(_extends({}, variant), {}, {
|
|
905
|
+
language: language,
|
|
906
|
+
source: finalSource
|
|
862
907
|
});
|
|
863
908
|
return _context6.a(2, {
|
|
864
909
|
code: _finalVariant,
|
|
@@ -866,18 +911,18 @@ function _loadCodeVariant() {
|
|
|
866
911
|
// No dependencies without URL
|
|
867
912
|
externals: {} // No externals without URL
|
|
868
913
|
});
|
|
869
|
-
case
|
|
914
|
+
case 11:
|
|
870
915
|
if (fileName) {
|
|
871
|
-
_context6.n =
|
|
916
|
+
_context6.n = 12;
|
|
872
917
|
break;
|
|
873
918
|
}
|
|
874
919
|
throw new Error("No fileName available for variant \"".concat(variantName, "\". ") + "Please provide a fileName in the variant definition or ensure the URL has a valid file extension.");
|
|
875
|
-
case
|
|
876
|
-
_context6.n =
|
|
920
|
+
case 12:
|
|
921
|
+
_context6.n = 13;
|
|
877
922
|
return loadSingleFile(variantName, fileName, variant.source, url, loadSource, sourceParser, sourceTransformers, loadSourceCache, variant.transforms, _extends(_extends({}, options), {}, {
|
|
878
923
|
loadedFiles: loadedFiles
|
|
879
|
-
}), variant.allFilesListed || false, knownExtraFiles);
|
|
880
|
-
case
|
|
924
|
+
}), variant.allFilesListed || false, knownExtraFiles, language);
|
|
925
|
+
case 13:
|
|
881
926
|
mainFileResult = _context6.v;
|
|
882
927
|
// Add files used from main file loading
|
|
883
928
|
if (mainFileResult.extraDependencies) {
|
|
@@ -890,26 +935,26 @@ function _loadCodeVariant() {
|
|
|
890
935
|
|
|
891
936
|
// Validate extraFiles keys from variant definition
|
|
892
937
|
if (!variant.extraFiles) {
|
|
893
|
-
_context6.n =
|
|
938
|
+
_context6.n = 16;
|
|
894
939
|
break;
|
|
895
940
|
}
|
|
896
941
|
_i5 = 0, _Object$keys3 = Object.keys(variant.extraFiles);
|
|
897
|
-
case
|
|
942
|
+
case 14:
|
|
898
943
|
if (!(_i5 < _Object$keys3.length)) {
|
|
899
|
-
_context6.n =
|
|
944
|
+
_context6.n = 16;
|
|
900
945
|
break;
|
|
901
946
|
}
|
|
902
947
|
_extraFileName = _Object$keys3[_i5];
|
|
903
948
|
if (!isAbsolutePath(_extraFileName)) {
|
|
904
|
-
_context6.n =
|
|
949
|
+
_context6.n = 15;
|
|
905
950
|
break;
|
|
906
951
|
}
|
|
907
952
|
throw new Error("Invalid extraFiles key in variant: \"".concat(_extraFileName, "\" appears to be an absolute path. ") + "extraFiles keys in variant definition should be relative paths from the main file.");
|
|
908
|
-
case
|
|
953
|
+
case 15:
|
|
909
954
|
_i5++;
|
|
910
|
-
_context6.n =
|
|
955
|
+
_context6.n = 14;
|
|
911
956
|
break;
|
|
912
|
-
case
|
|
957
|
+
case 16:
|
|
913
958
|
// Collect extra files from variant definition and from loaded source
|
|
914
959
|
extraFilesToLoad = _extends(_extends({}, variant.extraFiles || {}), mainFileResult.extraFiles || {}); // Add externals from main file loading
|
|
915
960
|
if (mainFileResult.externals) {
|
|
@@ -925,7 +970,7 @@ function _loadCodeVariant() {
|
|
|
925
970
|
globalsFileKeys = new Set(); // Track globals file keys for loadExtraFiles
|
|
926
971
|
// Process globalsCode array and add to extraFiles if provided
|
|
927
972
|
if (!(globalsCode && globalsCode.length > 0)) {
|
|
928
|
-
_context6.n =
|
|
973
|
+
_context6.n = 18;
|
|
929
974
|
break;
|
|
930
975
|
}
|
|
931
976
|
// Collect existing filenames to avoid conflicts
|
|
@@ -1017,9 +1062,9 @@ function _loadCodeVariant() {
|
|
|
1017
1062
|
return _ref4.apply(this, arguments);
|
|
1018
1063
|
};
|
|
1019
1064
|
}()); // Wait for all globals to load
|
|
1020
|
-
_context6.n =
|
|
1065
|
+
_context6.n = 17;
|
|
1021
1066
|
return Promise.all(globalsPromises);
|
|
1022
|
-
case
|
|
1067
|
+
case 17:
|
|
1023
1068
|
globalsResults = _context6.v;
|
|
1024
1069
|
// Merge results from all globals
|
|
1025
1070
|
_iterator4 = _createForOfIteratorHelper(globalsResults);
|
|
@@ -1057,18 +1102,18 @@ function _loadCodeVariant() {
|
|
|
1057
1102
|
} finally {
|
|
1058
1103
|
_iterator4.f();
|
|
1059
1104
|
}
|
|
1060
|
-
case
|
|
1105
|
+
case 18:
|
|
1061
1106
|
currentMark = performanceMeasure(externalsMergedMark, {
|
|
1062
1107
|
mark: 'Globals Loaded',
|
|
1063
1108
|
measure: 'Globals Loading'
|
|
1064
1109
|
}, [functionName, url || fileName], true);
|
|
1065
1110
|
allExtraFiles = {}; // Load all extra files if any exist and we have a URL
|
|
1066
1111
|
if (!(Object.keys(extraFilesToLoad).length > 0)) {
|
|
1067
|
-
_context6.n =
|
|
1112
|
+
_context6.n = 24;
|
|
1068
1113
|
break;
|
|
1069
1114
|
}
|
|
1070
1115
|
if (url) {
|
|
1071
|
-
_context6.n =
|
|
1116
|
+
_context6.n = 21;
|
|
1072
1117
|
break;
|
|
1073
1118
|
}
|
|
1074
1119
|
// If there's no URL, we can only load extra files that have inline source or absolute URLs
|
|
@@ -1086,7 +1131,7 @@ function _loadCodeVariant() {
|
|
|
1086
1131
|
}
|
|
1087
1132
|
}
|
|
1088
1133
|
if (!(Object.keys(loadableFiles).length > 0)) {
|
|
1089
|
-
_context6.n =
|
|
1134
|
+
_context6.n = 20;
|
|
1090
1135
|
break;
|
|
1091
1136
|
}
|
|
1092
1137
|
// Process loadable files: inline sources without URL-based loading, absolute URLs with loading
|
|
@@ -1094,11 +1139,16 @@ function _loadCodeVariant() {
|
|
|
1094
1139
|
_Object$entries5$_i = _slicedToArray(_Object$entries5[_i9], 2), _key3 = _Object$entries5$_i[0], _value2 = _Object$entries5$_i[1];
|
|
1095
1140
|
if (typeof _value2 !== 'string') {
|
|
1096
1141
|
// Inline source - preserve metadata if it was marked as globals
|
|
1097
|
-
metadata = _value2.metadata || globalsFileKeys.has(_key3) ? true : undefined;
|
|
1098
|
-
|
|
1099
|
-
|
|
1142
|
+
metadata = _value2.metadata || globalsFileKeys.has(_key3) ? true : undefined; // Derive language from filename extension
|
|
1143
|
+
_extension = _key3.slice(_key3.lastIndexOf('.'));
|
|
1144
|
+
extraFileLanguage = getLanguageFromExtension(_extension);
|
|
1145
|
+
allExtraFiles[normalizePathKey(_key3)] = _extends(_extends(_extends({
|
|
1146
|
+
source: _value2.source
|
|
1147
|
+
}, extraFileLanguage && {
|
|
1148
|
+
language: extraFileLanguage
|
|
1149
|
+
}), _value2.transforms && {
|
|
1100
1150
|
transforms: _value2.transforms
|
|
1101
|
-
}, metadata !== undefined && {
|
|
1151
|
+
}), metadata !== undefined && {
|
|
1102
1152
|
metadata: metadata
|
|
1103
1153
|
});
|
|
1104
1154
|
}
|
|
@@ -1113,10 +1163,10 @@ function _loadCodeVariant() {
|
|
|
1113
1163
|
}
|
|
1114
1164
|
}
|
|
1115
1165
|
if (!(Object.keys(urlFilesToLoad).length > 0)) {
|
|
1116
|
-
_context6.n =
|
|
1166
|
+
_context6.n = 20;
|
|
1117
1167
|
break;
|
|
1118
1168
|
}
|
|
1119
|
-
_context6.n =
|
|
1169
|
+
_context6.n = 19;
|
|
1120
1170
|
return loadExtraFiles(variantName, urlFilesToLoad, '',
|
|
1121
1171
|
// No base URL needed for absolute URLs
|
|
1122
1172
|
'',
|
|
@@ -1125,35 +1175,36 @@ function _loadCodeVariant() {
|
|
|
1125
1175
|
loadedFiles: loadedFiles
|
|
1126
1176
|
}), variant.allFilesListed || false, knownExtraFiles, globalsFileKeys // Pass globals file tracking
|
|
1127
1177
|
);
|
|
1128
|
-
case
|
|
1178
|
+
case 19:
|
|
1129
1179
|
extraFilesResult = _context6.v;
|
|
1130
1180
|
allExtraFiles = _extends(_extends({}, allExtraFiles), extraFilesResult.extraFiles);
|
|
1131
1181
|
allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(extraFilesResult.allFilesUsed));
|
|
1132
1182
|
allExternals = mergeExternals([allExternals, extraFilesResult.allExternals]);
|
|
1133
|
-
case
|
|
1134
|
-
_context6.n =
|
|
1183
|
+
case 20:
|
|
1184
|
+
_context6.n = 23;
|
|
1135
1185
|
break;
|
|
1136
|
-
case
|
|
1137
|
-
_context6.n =
|
|
1186
|
+
case 21:
|
|
1187
|
+
_context6.n = 22;
|
|
1138
1188
|
return loadExtraFiles(variantName, extraFilesToLoad, url, url,
|
|
1139
1189
|
// Entry URL is the same as the main file URL
|
|
1140
1190
|
loadSource, sourceParser, sourceTransformers, loadSourceCache, _extends(_extends({}, options), {}, {
|
|
1141
1191
|
loadedFiles: loadedFiles
|
|
1142
1192
|
}), variant.allFilesListed || false, knownExtraFiles, globalsFileKeys // Pass globals file tracking
|
|
1143
1193
|
);
|
|
1144
|
-
case
|
|
1194
|
+
case 22:
|
|
1145
1195
|
_extraFilesResult = _context6.v;
|
|
1146
1196
|
allExtraFiles = _extraFilesResult.extraFiles;
|
|
1147
1197
|
allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(_extraFilesResult.allFilesUsed));
|
|
1148
1198
|
allExternals = mergeExternals([allExternals, _extraFilesResult.allExternals]);
|
|
1149
|
-
case
|
|
1199
|
+
case 23:
|
|
1150
1200
|
currentMark = performanceMeasure(currentMark, {
|
|
1151
1201
|
mark: 'Extra Files Loaded',
|
|
1152
1202
|
measure: 'Extra Files Loading'
|
|
1153
1203
|
}, [functionName, url || fileName], true);
|
|
1154
|
-
case
|
|
1204
|
+
case 24:
|
|
1155
1205
|
// Note: metadata marking is now handled during loadExtraFiles processing
|
|
1156
1206
|
finalVariant = _extends(_extends({}, variant), {}, {
|
|
1207
|
+
language: language,
|
|
1157
1208
|
source: mainFileResult.source,
|
|
1158
1209
|
transforms: mainFileResult.transforms,
|
|
1159
1210
|
extraFiles: Object.keys(allExtraFiles).length > 0 ? allExtraFiles : undefined,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps file extensions to language names.
|
|
3
|
+
* These are user-friendly names that can be used in the `language` prop.
|
|
4
|
+
*/
|
|
5
|
+
export declare const languageMap: Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Maps language aliases to canonical language names.
|
|
8
|
+
* Used to normalize short language names (e.g., from className like 'language-js')
|
|
9
|
+
* to their full names.
|
|
10
|
+
*/
|
|
11
|
+
export declare const languageAliasMap: Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the language name from a file extension.
|
|
14
|
+
* @param extension - The file extension (e.g., '.tsx', '.css')
|
|
15
|
+
* @returns The language name or undefined if not recognized
|
|
16
|
+
*/
|
|
17
|
+
export declare function getLanguageFromExtension(extension: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Normalizes a language name to its canonical form.
|
|
20
|
+
* This handles aliases like 'js' -> 'javascript', 'ts' -> 'typescript'.
|
|
21
|
+
* @param language - The language name or alias
|
|
22
|
+
* @returns The canonical language name, or the input if not a known alias
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeLanguage(language: string): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps file extensions to language names.
|
|
3
|
+
* These are user-friendly names that can be used in the `language` prop.
|
|
4
|
+
*/
|
|
5
|
+
export var languageMap = {
|
|
6
|
+
'.js': 'javascript',
|
|
7
|
+
'.ts': 'typescript',
|
|
8
|
+
'.jsx': 'jsx',
|
|
9
|
+
'.tsx': 'tsx',
|
|
10
|
+
'.json': 'json',
|
|
11
|
+
'.md': 'markdown',
|
|
12
|
+
'.mdx': 'mdx',
|
|
13
|
+
'.html': 'html',
|
|
14
|
+
'.css': 'css',
|
|
15
|
+
'.sh': 'shell',
|
|
16
|
+
'.yaml': 'yaml',
|
|
17
|
+
'.yml': 'yaml'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Maps language aliases to canonical language names.
|
|
22
|
+
* Used to normalize short language names (e.g., from className like 'language-js')
|
|
23
|
+
* to their full names.
|
|
24
|
+
*/
|
|
25
|
+
export var languageAliasMap = {
|
|
26
|
+
js: 'javascript',
|
|
27
|
+
ts: 'typescript',
|
|
28
|
+
javascript: 'javascript',
|
|
29
|
+
typescript: 'typescript',
|
|
30
|
+
jsx: 'jsx',
|
|
31
|
+
tsx: 'tsx',
|
|
32
|
+
json: 'json',
|
|
33
|
+
md: 'markdown',
|
|
34
|
+
markdown: 'markdown',
|
|
35
|
+
mdx: 'mdx',
|
|
36
|
+
html: 'html',
|
|
37
|
+
css: 'css',
|
|
38
|
+
sh: 'shell',
|
|
39
|
+
bash: 'shell',
|
|
40
|
+
shell: 'shell',
|
|
41
|
+
yaml: 'yaml',
|
|
42
|
+
yml: 'yaml'
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Gets the language name from a file extension.
|
|
47
|
+
* @param extension - The file extension (e.g., '.tsx', '.css')
|
|
48
|
+
* @returns The language name or undefined if not recognized
|
|
49
|
+
*/
|
|
50
|
+
export function getLanguageFromExtension(extension) {
|
|
51
|
+
return languageMap[extension];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Normalizes a language name to its canonical form.
|
|
56
|
+
* This handles aliases like 'js' -> 'javascript', 'ts' -> 'typescript'.
|
|
57
|
+
* @param language - The language name or alias
|
|
58
|
+
* @returns The canonical language name, or the input if not a known alias
|
|
59
|
+
*/
|
|
60
|
+
export function normalizeLanguage(language) {
|
|
61
|
+
var _languageAliasMap$lan;
|
|
62
|
+
return (_languageAliasMap$lan = languageAliasMap[language]) != null ? _languageAliasMap$lan : language;
|
|
63
|
+
}
|
|
@@ -5,4 +5,5 @@ export * from "./processRelativeImports.js";
|
|
|
5
5
|
export * from "./getFileNameFromUrl.js";
|
|
6
6
|
export * from "./extractNameAndSlugFromUrl.js";
|
|
7
7
|
export * from "./externalsToPackages.js";
|
|
8
|
-
export * from "./fileUrlToPortablePath.js";
|
|
8
|
+
export * from "./fileUrlToPortablePath.js";
|
|
9
|
+
export * from "./getLanguageFromExtension.js";
|
|
@@ -5,4 +5,5 @@ export * from "./processRelativeImports.js";
|
|
|
5
5
|
export * from "./getFileNameFromUrl.js";
|
|
6
6
|
export * from "./extractNameAndSlugFromUrl.js";
|
|
7
7
|
export * from "./externalsToPackages.js";
|
|
8
|
-
export * from "./fileUrlToPortablePath.js";
|
|
8
|
+
export * from "./fileUrlToPortablePath.js";
|
|
9
|
+
export * from "./getLanguageFromExtension.js";
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export declare const grammars: import("@wooorm/starry-night").Grammar[];
|
|
2
|
-
export declare const extensionMap: Record<string, string>;
|
|
2
|
+
export declare const extensionMap: Record<string, string>;
|
|
3
|
+
/**
|
|
4
|
+
* Maps simplified language names back to grammar scope names.
|
|
5
|
+
* Used when `language` prop is provided instead of fileName.
|
|
6
|
+
*/
|
|
7
|
+
export declare const languageToGrammarMap: Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Gets the grammar scope from a language name.
|
|
10
|
+
* @param language - The language name (e.g., 'tsx', 'css', 'typescript')
|
|
11
|
+
* @returns The grammar scope or undefined if not recognized
|
|
12
|
+
*/
|
|
13
|
+
export declare function getGrammarFromLanguage(language: string): string | undefined;
|
|
@@ -15,7 +15,6 @@ export var extensionMap = {
|
|
|
15
15
|
'.js': 'source.js',
|
|
16
16
|
'.ts': 'source.ts',
|
|
17
17
|
'.jsx': 'source.tsx',
|
|
18
|
-
// TODO: is there a JSX grammar?
|
|
19
18
|
'.tsx': 'source.tsx',
|
|
20
19
|
'.json': 'source.json',
|
|
21
20
|
'.md': 'text.md',
|
|
@@ -24,4 +23,37 @@ export var extensionMap = {
|
|
|
24
23
|
'.css': 'source.css',
|
|
25
24
|
'.sh': 'source.shell',
|
|
26
25
|
'.yaml': 'source.yaml'
|
|
27
|
-
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Maps simplified language names back to grammar scope names.
|
|
30
|
+
* Used when `language` prop is provided instead of fileName.
|
|
31
|
+
*/
|
|
32
|
+
export var languageToGrammarMap = {
|
|
33
|
+
js: 'source.js',
|
|
34
|
+
javascript: 'source.js',
|
|
35
|
+
ts: 'source.ts',
|
|
36
|
+
typescript: 'source.ts',
|
|
37
|
+
jsx: 'source.tsx',
|
|
38
|
+
tsx: 'source.tsx',
|
|
39
|
+
json: 'source.json',
|
|
40
|
+
md: 'text.md',
|
|
41
|
+
markdown: 'text.md',
|
|
42
|
+
mdx: 'source.mdx',
|
|
43
|
+
html: 'text.html.basic',
|
|
44
|
+
css: 'source.css',
|
|
45
|
+
sh: 'source.shell',
|
|
46
|
+
shell: 'source.shell',
|
|
47
|
+
bash: 'source.shell',
|
|
48
|
+
yaml: 'source.yaml',
|
|
49
|
+
yml: 'source.yaml'
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Gets the grammar scope from a language name.
|
|
54
|
+
* @param language - The language name (e.g., 'tsx', 'css', 'typescript')
|
|
55
|
+
* @returns The grammar scope or undefined if not recognized
|
|
56
|
+
*/
|
|
57
|
+
export function getGrammarFromLanguage(language) {
|
|
58
|
+
return languageToGrammarMap[language.toLowerCase()];
|
|
59
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./parseSource.js";
|
|
1
|
+
export * from "./parseSource.js";
|
|
2
|
+
export { getGrammarFromLanguage, languageToGrammarMap, extensionMap } from "./grammars.js";
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./parseSource.js";
|
|
1
|
+
export * from "./parseSource.js";
|
|
2
|
+
export { getGrammarFromLanguage, languageToGrammarMap, extensionMap } from "./grammars.js";
|