@mui/internal-docs-infra 0.1.1-canary.9 → 0.2.0-alpha.1
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/CHANGELOG.md +9 -0
- package/README.md +3 -11
- package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
- package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
- package/esm/CodeControllerContext/index.d.ts +1 -0
- package/esm/CodeControllerContext/index.js +1 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
- package/esm/CodeExternalsContext/index.d.ts +1 -0
- package/esm/CodeExternalsContext/index.js +1 -0
- package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
- package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
- package/esm/CodeHighlighter/applyTransform.js +75 -0
- package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
- package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
- package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
- package/esm/CodeHighlighter/errors.d.ts +141 -0
- package/esm/CodeHighlighter/errors.js +441 -0
- package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
- package/esm/CodeHighlighter/examineVariant.js +73 -0
- package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
- package/esm/CodeHighlighter/hasAllVariants.js +63 -0
- package/esm/CodeHighlighter/index.d.ts +1 -0
- package/esm/CodeHighlighter/index.js +1 -0
- package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
- package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
- package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
- package/esm/CodeHighlighter/loadVariant.js +1044 -0
- package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
- package/esm/CodeHighlighter/maybeInitialData.js +192 -0
- package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
- package/esm/CodeHighlighter/mergeMetadata.js +165 -0
- package/esm/CodeHighlighter/parseCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseCode.js +134 -0
- package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseControlledCode.js +87 -0
- package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
- package/esm/CodeHighlighter/pathUtils.js +258 -0
- package/esm/CodeHighlighter/transformCode.d.ts +21 -0
- package/esm/CodeHighlighter/transformCode.js +251 -0
- package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/esm/CodeHighlighter/transformParsedSource.js +60 -0
- package/esm/CodeHighlighter/transformSource.d.ts +2 -0
- package/esm/CodeHighlighter/transformSource.js +103 -0
- package/esm/CodeHighlighter/types.d.ts +276 -0
- package/esm/CodeHighlighter/types.js +1 -0
- package/esm/CodeProvider/CodeContext.d.ts +31 -0
- package/esm/CodeProvider/CodeContext.js +12 -0
- package/esm/CodeProvider/CodeProvider.d.ts +13 -0
- package/esm/CodeProvider/CodeProvider.js +83 -0
- package/esm/CodeProvider/index.d.ts +1 -0
- package/esm/CodeProvider/index.js +1 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
- package/esm/abstractCreateDemo/index.d.ts +1 -0
- package/esm/abstractCreateDemo/index.js +1 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
- package/esm/abstractCreateDemoClient/index.d.ts +1 -0
- package/esm/abstractCreateDemoClient/index.js +1 -0
- package/esm/createDemoData/createDemoData.d.ts +44 -0
- package/esm/createDemoData/createDemoData.js +74 -0
- package/esm/createDemoData/index.d.ts +1 -0
- package/esm/createDemoData/index.js +1 -0
- package/esm/createDemoData/types.d.ts +25 -0
- package/esm/createDemoData/types.js +1 -0
- package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
- package/esm/pipeline/hastUtils/hastUtils.js +67 -0
- package/esm/pipeline/hastUtils/index.d.ts +1 -0
- package/esm/pipeline/hastUtils/index.js +1 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
- package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
- package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
- package/esm/pipeline/loadServerSource/index.d.ts +1 -0
- package/esm/pipeline/loadServerSource/index.js +1 -0
- package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
- package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
- package/esm/pipeline/loaderUtils/index.d.ts +7 -0
- package/esm/pipeline/loaderUtils/index.js +7 -0
- package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
- package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
- package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/parseImports.js +306 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
- package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
- package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
- package/esm/pipeline/parseSource/addLineGutters.js +181 -0
- package/esm/pipeline/parseSource/grammars.d.ts +2 -0
- package/esm/pipeline/parseSource/grammars.js +27 -0
- package/esm/pipeline/parseSource/index.d.ts +1 -0
- package/esm/pipeline/parseSource/index.js +1 -0
- package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
- package/esm/pipeline/parseSource/parseSource.js +51 -0
- package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
- package/esm/pipeline/transformHtmlCode/index.js +4 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
- package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/index.js +4 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
- package/esm/useCode/Pre.d.ts +15 -0
- package/esm/useCode/Pre.js +164 -0
- package/esm/useCode/index.d.ts +1 -0
- package/esm/useCode/index.js +1 -0
- package/esm/useCode/useCode.d.ts +41 -0
- package/esm/useCode/useCode.js +128 -0
- package/esm/useCode/useCodeUtils.d.ts +44 -0
- package/esm/useCode/useCodeUtils.js +245 -0
- package/esm/useCode/useCopyFunctionality.d.ts +18 -0
- package/esm/useCode/useCopyFunctionality.js +28 -0
- package/esm/useCode/useFileNavigation.d.ts +41 -0
- package/esm/useCode/useFileNavigation.js +453 -0
- package/esm/useCode/useSourceEditing.d.ts +21 -0
- package/esm/useCode/useSourceEditing.js +32 -0
- package/esm/useCode/useTransformManagement.d.ts +30 -0
- package/esm/useCode/useTransformManagement.js +72 -0
- package/esm/useCode/useUIState.d.ts +16 -0
- package/esm/useCode/useUIState.js +21 -0
- package/esm/useCode/useVariantSelection.d.ts +23 -0
- package/esm/useCode/useVariantSelection.js +75 -0
- package/esm/useCopier/index.d.ts +1 -1
- package/esm/useCopier/index.js +5 -5
- package/esm/useDemo/createCodeSandbox.d.ts +15 -0
- package/esm/useDemo/createCodeSandbox.js +42 -0
- package/esm/useDemo/createStackBlitz.d.ts +22 -0
- package/esm/useDemo/createStackBlitz.js +38 -0
- package/esm/useDemo/exportVariant.d.ts +184 -0
- package/esm/useDemo/exportVariant.js +422 -0
- package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
- package/esm/useDemo/exportVariantAsCra.js +57 -0
- package/esm/useDemo/flattenVariant.d.ts +19 -0
- package/esm/useDemo/flattenVariant.js +49 -0
- package/esm/useDemo/index.d.ts +6 -51
- package/esm/useDemo/index.js +6 -104
- package/esm/useDemo/useDemo.d.ts +81 -0
- package/esm/useDemo/useDemo.js +193 -0
- package/esm/useErrors/ErrorsContext.d.ts +6 -0
- package/esm/useErrors/ErrorsContext.js +8 -0
- package/esm/useErrors/index.d.ts +1 -0
- package/esm/useErrors/index.js +1 -0
- package/esm/useErrors/useErrors.d.ts +5 -0
- package/esm/useErrors/useErrors.js +7 -0
- package/esm/useLocalStorageState/index.d.ts +2 -0
- package/esm/useLocalStorageState/index.js +2 -0
- package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
- package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
- package/esm/usePreference/PreferencesProvider.d.ts +6 -0
- package/esm/usePreference/PreferencesProvider.js +8 -0
- package/esm/usePreference/index.d.ts +2 -0
- package/esm/usePreference/index.js +2 -0
- package/esm/usePreference/usePreference.d.ts +2 -0
- package/esm/usePreference/usePreference.js +25 -0
- package/esm/useUrlHashState/index.d.ts +1 -0
- package/esm/useUrlHashState/index.js +1 -0
- package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
- package/esm/useUrlHashState/useUrlHashState.js +68 -0
- package/esm/withDocsInfra/index.d.ts +1 -0
- package/esm/withDocsInfra/index.js +1 -0
- package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
- package/esm/withDocsInfra/withDocsInfra.js +147 -0
- package/package.json +178 -11
- package/esm/useCopier/index.d.ts.map +0 -1
- package/esm/useDemo/index.d.ts.map +0 -1
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
3
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
|
+
import { visit } from 'unist-util-visit';
|
|
7
|
+
import { loadVariant } from "../../CodeHighlighter/loadVariant.js";
|
|
8
|
+
import { createParseSource } from "../parseSource/index.js";
|
|
9
|
+
import { TypescriptToJavascriptTransformer } from "../transformTypescriptToJavascript/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* Maps common language class names to file extensions
|
|
12
|
+
* Only includes languages that have corresponding grammars in parseSource/grammars.ts
|
|
13
|
+
*/
|
|
14
|
+
var LANGUAGE_TO_EXTENSION = {
|
|
15
|
+
// JavaScript
|
|
16
|
+
javascript: 'js',
|
|
17
|
+
js: 'js',
|
|
18
|
+
// TypeScript
|
|
19
|
+
typescript: 'ts',
|
|
20
|
+
ts: 'ts',
|
|
21
|
+
// TSX/JSX
|
|
22
|
+
tsx: 'tsx',
|
|
23
|
+
jsx: 'jsx',
|
|
24
|
+
// Maps to .jsx but uses tsx grammar
|
|
25
|
+
|
|
26
|
+
// JSON
|
|
27
|
+
json: 'json',
|
|
28
|
+
// Markdown
|
|
29
|
+
markdown: 'md',
|
|
30
|
+
md: 'md',
|
|
31
|
+
// MDX
|
|
32
|
+
mdx: 'mdx',
|
|
33
|
+
// HTML
|
|
34
|
+
html: 'html',
|
|
35
|
+
// CSS
|
|
36
|
+
css: 'css',
|
|
37
|
+
// Shell
|
|
38
|
+
shell: 'sh',
|
|
39
|
+
bash: 'sh',
|
|
40
|
+
sh: 'sh',
|
|
41
|
+
// YAML
|
|
42
|
+
yaml: 'yaml',
|
|
43
|
+
yml: 'yaml'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Extracts the language from className attribute
|
|
48
|
+
*/
|
|
49
|
+
function extractLanguageFromClassName(className) {
|
|
50
|
+
if (!className) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Handle array of class names (HAST format)
|
|
55
|
+
var classString = Array.isArray(className) ? className.join(' ') : className;
|
|
56
|
+
var match = classString.match(/(?:^|\s)language-(\w+)(?:\s|$)/);
|
|
57
|
+
return match ? match[1] : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Gets the filename from data-filename attribute or derives it from language
|
|
62
|
+
* Returns undefined if no explicit filename and no recognizable language
|
|
63
|
+
*/
|
|
64
|
+
function getFileName(codeElement) {
|
|
65
|
+
var _codeElement$properti, _codeElement$properti2;
|
|
66
|
+
// Check for explicit data-filename attribute
|
|
67
|
+
var dataFilename = (_codeElement$properti = codeElement.properties) == null ? void 0 : _codeElement$properti.dataFilename;
|
|
68
|
+
if (dataFilename && typeof dataFilename === 'string') {
|
|
69
|
+
return dataFilename;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Extract language from className
|
|
73
|
+
var className = (_codeElement$properti2 = codeElement.properties) == null ? void 0 : _codeElement$properti2.className;
|
|
74
|
+
var language = extractLanguageFromClassName(className);
|
|
75
|
+
if (language && LANGUAGE_TO_EXTENSION[language]) {
|
|
76
|
+
return "index.".concat(LANGUAGE_TO_EXTENSION[language]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Return undefined instead of a fallback - let the system handle gracefully
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Extracts text content from HAST nodes
|
|
85
|
+
*/
|
|
86
|
+
function extractTextContent(node) {
|
|
87
|
+
if (node.type === 'text') {
|
|
88
|
+
return node.value;
|
|
89
|
+
}
|
|
90
|
+
if (node.type === 'element' && node.children) {
|
|
91
|
+
return node.children.map(function (child) {
|
|
92
|
+
return extractTextContent(child);
|
|
93
|
+
}).join('');
|
|
94
|
+
}
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates variants from multiple code elements within a pre element
|
|
100
|
+
*/
|
|
101
|
+
function createVariantsFromCodeElements(codeElements) {
|
|
102
|
+
var variants = {};
|
|
103
|
+
if (codeElements.length === 1) {
|
|
104
|
+
var _codeElement$properti3;
|
|
105
|
+
// Single code element - use "Default" as variant name
|
|
106
|
+
var codeElement = codeElements[0];
|
|
107
|
+
var sourceCode = extractTextContent(codeElement);
|
|
108
|
+
var fileName = getFileName(codeElement);
|
|
109
|
+
var variant = {
|
|
110
|
+
source: sourceCode,
|
|
111
|
+
skipTransforms: !((_codeElement$properti3 = codeElement.properties) != null && _codeElement$properti3.dataTransform)
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Only add fileName if we have one
|
|
115
|
+
if (fileName) {
|
|
116
|
+
variant.fileName = fileName;
|
|
117
|
+
}
|
|
118
|
+
variants.Default = variant;
|
|
119
|
+
} else {
|
|
120
|
+
// Multiple code elements - create appropriate variant names
|
|
121
|
+
var languages = codeElements.map(function (element) {
|
|
122
|
+
var _element$properties;
|
|
123
|
+
var className = (_element$properties = element.properties) == null ? void 0 : _element$properties.className;
|
|
124
|
+
return extractLanguageFromClassName(className);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Check if all languages are the same (or all null)
|
|
128
|
+
var uniqueLanguages = Array.from(new Set(languages.filter(Boolean)));
|
|
129
|
+
var shouldUseLanguageNames = uniqueLanguages.length > 1;
|
|
130
|
+
codeElements.forEach(function (codeElement, index) {
|
|
131
|
+
var _codeElement$properti4, _codeElement$properti5;
|
|
132
|
+
var sourceCode = extractTextContent(codeElement);
|
|
133
|
+
var fileName = getFileName(codeElement);
|
|
134
|
+
|
|
135
|
+
// Check for explicit variant name
|
|
136
|
+
var dataVariant = (_codeElement$properti4 = codeElement.properties) == null ? void 0 : _codeElement$properti4.dataVariant;
|
|
137
|
+
var variantName;
|
|
138
|
+
if (dataVariant && typeof dataVariant === 'string') {
|
|
139
|
+
variantName = dataVariant;
|
|
140
|
+
} else if (shouldUseLanguageNames && languages[index]) {
|
|
141
|
+
// Use language name if languages differ
|
|
142
|
+
variantName = languages[index].charAt(0).toUpperCase() + languages[index].slice(1);
|
|
143
|
+
} else {
|
|
144
|
+
// Use numbered variants if languages are the same or unknown
|
|
145
|
+
variantName = "Variant ".concat(index + 1);
|
|
146
|
+
}
|
|
147
|
+
var variant = {
|
|
148
|
+
source: sourceCode,
|
|
149
|
+
skipTransforms: !((_codeElement$properti5 = codeElement.properties) != null && _codeElement$properti5.dataTransform)
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Only add fileName if we have one
|
|
153
|
+
if (fileName) {
|
|
154
|
+
variant.fileName = fileName;
|
|
155
|
+
}
|
|
156
|
+
variants[variantName] = variant;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return variants;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Rehype plugin that transforms pre > code elements to use loadVariant
|
|
164
|
+
*
|
|
165
|
+
* This plugin:
|
|
166
|
+
* 1. Finds pre elements in the HTML AST
|
|
167
|
+
* 2. Collects all code children within each pre element
|
|
168
|
+
* 3. Creates variants from multiple code elements or single Default variant
|
|
169
|
+
* 4. Uses loadVariant to process each variant
|
|
170
|
+
* 5. Stores the combined precompute data on the pre element
|
|
171
|
+
* 6. Clears all code element contents
|
|
172
|
+
*/
|
|
173
|
+
export var transformHtmlCode = function transformHtmlCode() {
|
|
174
|
+
return /*#__PURE__*/function () {
|
|
175
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(tree) {
|
|
176
|
+
var transformPromises, sourceParser, sourceTransformers;
|
|
177
|
+
return _regenerator().w(function (_context3) {
|
|
178
|
+
while (1) switch (_context3.n) {
|
|
179
|
+
case 0:
|
|
180
|
+
transformPromises = []; // Get the source parser and transformers
|
|
181
|
+
sourceParser = createParseSource();
|
|
182
|
+
sourceTransformers = [TypescriptToJavascriptTransformer];
|
|
183
|
+
visit(tree, 'element', function (node) {
|
|
184
|
+
// Look for pre elements
|
|
185
|
+
if (node.tagName === 'pre' && node.children && node.children.length > 0) {
|
|
186
|
+
// Find all code elements within this pre
|
|
187
|
+
var codeElements = node.children.filter(function (child) {
|
|
188
|
+
return child.type === 'element' && child.tagName === 'code';
|
|
189
|
+
});
|
|
190
|
+
if (codeElements.length > 0) {
|
|
191
|
+
var transformPromise = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
192
|
+
var variants, processedCode, variantPromises, variantResults, _iterator, _step, result, _t;
|
|
193
|
+
return _regenerator().w(function (_context2) {
|
|
194
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
195
|
+
case 0:
|
|
196
|
+
_context2.p = 0;
|
|
197
|
+
// Create variants from all code elements
|
|
198
|
+
variants = createVariantsFromCodeElements(codeElements); // Process each variant with loadVariant
|
|
199
|
+
processedCode = {};
|
|
200
|
+
variantPromises = Object.entries(variants).map(/*#__PURE__*/function () {
|
|
201
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref3) {
|
|
202
|
+
var _ref5, variantName, variantData, result;
|
|
203
|
+
return _regenerator().w(function (_context) {
|
|
204
|
+
while (1) switch (_context.n) {
|
|
205
|
+
case 0:
|
|
206
|
+
_ref5 = _slicedToArray(_ref3, 2), variantName = _ref5[0], variantData = _ref5[1];
|
|
207
|
+
if (!(variantData && _typeof(variantData) === 'object')) {
|
|
208
|
+
_context.n = 2;
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
_context.n = 1;
|
|
212
|
+
return loadVariant(undefined,
|
|
213
|
+
// url - not needed for inline code
|
|
214
|
+
variantName, variantData, {
|
|
215
|
+
sourceParser: sourceParser,
|
|
216
|
+
loadSource: undefined,
|
|
217
|
+
// loadSource - not needed since we have the data
|
|
218
|
+
loadVariantMeta: undefined,
|
|
219
|
+
// loadVariantMeta - not needed since we have the data
|
|
220
|
+
sourceTransformers: sourceTransformers,
|
|
221
|
+
disableTransforms: variantData.skipTransforms || false
|
|
222
|
+
});
|
|
223
|
+
case 1:
|
|
224
|
+
result = _context.v;
|
|
225
|
+
return _context.a(2, {
|
|
226
|
+
variantName: variantName,
|
|
227
|
+
processedVariant: result.code
|
|
228
|
+
});
|
|
229
|
+
case 2:
|
|
230
|
+
return _context.a(2, null);
|
|
231
|
+
}
|
|
232
|
+
}, _callee);
|
|
233
|
+
}));
|
|
234
|
+
return function (_x2) {
|
|
235
|
+
return _ref4.apply(this, arguments);
|
|
236
|
+
};
|
|
237
|
+
}());
|
|
238
|
+
_context2.n = 1;
|
|
239
|
+
return Promise.all(variantPromises);
|
|
240
|
+
case 1:
|
|
241
|
+
variantResults = _context2.v;
|
|
242
|
+
_iterator = _createForOfIteratorHelper(variantResults);
|
|
243
|
+
try {
|
|
244
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
245
|
+
result = _step.value;
|
|
246
|
+
if (result) {
|
|
247
|
+
processedCode[result.variantName] = result.processedVariant;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Clear all code element contents and replace with error message
|
|
252
|
+
} catch (err) {
|
|
253
|
+
_iterator.e(err);
|
|
254
|
+
} finally {
|
|
255
|
+
_iterator.f();
|
|
256
|
+
}
|
|
257
|
+
codeElements.forEach(function (codeElement) {
|
|
258
|
+
codeElement.children = [];
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Replace pre element children with error message for CodeHighlighter
|
|
262
|
+
node.children = [{
|
|
263
|
+
type: 'text',
|
|
264
|
+
value: 'Error: expected pre tag to be handled by CodeHighlighter'
|
|
265
|
+
}];
|
|
266
|
+
|
|
267
|
+
// Set the precompute data on the pre element directly on properties for immediate HTML serialization
|
|
268
|
+
if (!node.properties) {
|
|
269
|
+
node.properties = {};
|
|
270
|
+
}
|
|
271
|
+
node.properties.dataPrecompute = JSON.stringify(processedCode);
|
|
272
|
+
_context2.n = 3;
|
|
273
|
+
break;
|
|
274
|
+
case 2:
|
|
275
|
+
_context2.p = 2;
|
|
276
|
+
_t = _context2.v;
|
|
277
|
+
console.warn('Failed to transform code block:', _t);
|
|
278
|
+
case 3:
|
|
279
|
+
return _context2.a(2);
|
|
280
|
+
}
|
|
281
|
+
}, _callee2, null, [[0, 2]]);
|
|
282
|
+
}))();
|
|
283
|
+
transformPromises.push(transformPromise);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// Wait for all transformations to complete
|
|
289
|
+
_context3.n = 1;
|
|
290
|
+
return Promise.all(transformPromises);
|
|
291
|
+
case 1:
|
|
292
|
+
return _context3.a(2);
|
|
293
|
+
}
|
|
294
|
+
}, _callee3);
|
|
295
|
+
}));
|
|
296
|
+
return function (_x) {
|
|
297
|
+
return _ref.apply(this, arguments);
|
|
298
|
+
};
|
|
299
|
+
}();
|
|
300
|
+
};
|