@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5
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/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
5
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
1
|
import { visit } from 'unist-util-visit';
|
|
7
2
|
import { loadCodeVariant } from "../loadCodeVariant/loadCodeVariant.js";
|
|
8
3
|
import { createParseSource } from "../parseSource/index.js";
|
|
@@ -11,7 +6,7 @@ import { TypescriptToJavascriptTransformer } from "../transformTypescriptToJavas
|
|
|
11
6
|
* Reserved data properties that are handled internally and should not be passed to userProps.
|
|
12
7
|
* These are either processed by the transform pipeline or have special meaning.
|
|
13
8
|
*/
|
|
14
|
-
|
|
9
|
+
const RESERVED_DATA_PROPS = new Set(['dataFilename',
|
|
15
10
|
// Used for fileName
|
|
16
11
|
'dataVariant',
|
|
17
12
|
// Used for variant name
|
|
@@ -32,19 +27,16 @@ var RESERVED_DATA_PROPS = new Set(['dataFilename',
|
|
|
32
27
|
* Converts from camelCase (dataTitle) to kebab-case keys (title).
|
|
33
28
|
*/
|
|
34
29
|
function extractUserProps(codeElement) {
|
|
35
|
-
|
|
30
|
+
const props = codeElement.properties;
|
|
36
31
|
if (!props) {
|
|
37
32
|
return undefined;
|
|
38
33
|
}
|
|
39
|
-
|
|
40
|
-
for (
|
|
41
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
42
|
-
key = _Object$entries$_i[0],
|
|
43
|
-
value = _Object$entries$_i[1];
|
|
34
|
+
const userProps = {};
|
|
35
|
+
for (const [key, value] of Object.entries(props)) {
|
|
44
36
|
// Only process data-* attributes (in camelCase form: dataXxx)
|
|
45
37
|
if (key.startsWith('data') && key.length > 4 && !RESERVED_DATA_PROPS.has(key)) {
|
|
46
38
|
// Convert dataTitle -> title, dataHighlight -> highlight
|
|
47
|
-
|
|
39
|
+
const propName = key.charAt(4).toLowerCase() + key.slice(5);
|
|
48
40
|
// Convert value to string
|
|
49
41
|
userProps[propName] = String(value);
|
|
50
42
|
}
|
|
@@ -57,9 +49,8 @@ function extractUserProps(codeElement) {
|
|
|
57
49
|
* Returns undefined if no explicit filename is provided
|
|
58
50
|
*/
|
|
59
51
|
function getFileName(codeElement) {
|
|
60
|
-
var _codeElement$properti;
|
|
61
52
|
// Check for explicit data-filename attribute
|
|
62
|
-
|
|
53
|
+
const dataFilename = codeElement.properties?.dataFilename;
|
|
63
54
|
if (dataFilename && typeof dataFilename === 'string') {
|
|
64
55
|
return dataFilename;
|
|
65
56
|
}
|
|
@@ -74,20 +65,11 @@ function extractLanguageFromClassName(className) {
|
|
|
74
65
|
if (!className) {
|
|
75
66
|
return undefined;
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
82
|
-
var cls = _step.value;
|
|
83
|
-
if (typeof cls === 'string' && cls.startsWith('language-')) {
|
|
84
|
-
return cls.slice('language-'.length);
|
|
85
|
-
}
|
|
68
|
+
const classes = Array.isArray(className) ? className : [className];
|
|
69
|
+
for (const cls of classes) {
|
|
70
|
+
if (typeof cls === 'string' && cls.startsWith('language-')) {
|
|
71
|
+
return cls.slice('language-'.length);
|
|
86
72
|
}
|
|
87
|
-
} catch (err) {
|
|
88
|
-
_iterator.e(err);
|
|
89
|
-
} finally {
|
|
90
|
-
_iterator.f();
|
|
91
73
|
}
|
|
92
74
|
return undefined;
|
|
93
75
|
}
|
|
@@ -96,8 +78,7 @@ function extractLanguageFromClassName(className) {
|
|
|
96
78
|
* Gets the language from class="language-*" attribute
|
|
97
79
|
*/
|
|
98
80
|
function getLanguage(codeElement) {
|
|
99
|
-
|
|
100
|
-
var className = (_codeElement$properti2 = codeElement.properties) == null ? void 0 : _codeElement$properti2.className;
|
|
81
|
+
const className = codeElement.properties?.className;
|
|
101
82
|
return extractLanguageFromClassName(className);
|
|
102
83
|
}
|
|
103
84
|
|
|
@@ -109,9 +90,7 @@ function extractTextContent(node) {
|
|
|
109
90
|
return node.value;
|
|
110
91
|
}
|
|
111
92
|
if (node.type === 'element' && node.children) {
|
|
112
|
-
return node.children.map(
|
|
113
|
-
return extractTextContent(child);
|
|
114
|
-
}).join('');
|
|
93
|
+
return node.children.map(child => extractTextContent(child)).join('');
|
|
115
94
|
}
|
|
116
95
|
return '';
|
|
117
96
|
}
|
|
@@ -121,52 +100,37 @@ function extractTextContent(node) {
|
|
|
121
100
|
* Handles both section/figure/dl and standalone dl structures
|
|
122
101
|
*/
|
|
123
102
|
function extractCodeFromSemanticStructure(element) {
|
|
124
|
-
|
|
103
|
+
const results = [];
|
|
125
104
|
if (element.tagName === 'section') {
|
|
126
105
|
// Handle section with multiple figures
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Extract variant name from figcaption
|
|
136
|
-
var variantName = void 0;
|
|
137
|
-
var figcaption = figure.children.find(function (child) {
|
|
138
|
-
return child.type === 'element' && child.tagName === 'figcaption';
|
|
139
|
-
});
|
|
140
|
-
if (figcaption && figcaption.children[0] && figcaption.children[0].type === 'text') {
|
|
141
|
-
variantName = figcaption.children[0].value.replace(' variant', '');
|
|
142
|
-
}
|
|
106
|
+
const figures = element.children.filter(child => child.type === 'element' && child.tagName === 'figure');
|
|
107
|
+
for (const figure of figures) {
|
|
108
|
+
// Extract variant name from figcaption
|
|
109
|
+
let variantName;
|
|
110
|
+
const figcaption = figure.children.find(child => child.type === 'element' && child.tagName === 'figcaption');
|
|
111
|
+
if (figcaption && figcaption.children[0] && figcaption.children[0].type === 'text') {
|
|
112
|
+
variantName = figcaption.children[0].value.replace(' variant', '');
|
|
113
|
+
}
|
|
143
114
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
variantName: variantName || extracted.variantName
|
|
156
|
-
});
|
|
157
|
-
}
|
|
115
|
+
// Find dl element in figure
|
|
116
|
+
const dl = figure.children.find(child => child.type === 'element' && child.tagName === 'dl');
|
|
117
|
+
if (dl) {
|
|
118
|
+
const extracted = extractFromDl(dl);
|
|
119
|
+
if (extracted) {
|
|
120
|
+
results.push({
|
|
121
|
+
codeElement: extracted.codeElement,
|
|
122
|
+
filename: extracted.filename,
|
|
123
|
+
language: extracted.language,
|
|
124
|
+
variantName: variantName || extracted.variantName
|
|
125
|
+
});
|
|
158
126
|
}
|
|
159
127
|
}
|
|
160
|
-
} catch (err) {
|
|
161
|
-
_iterator2.e(err);
|
|
162
|
-
} finally {
|
|
163
|
-
_iterator2.f();
|
|
164
128
|
}
|
|
165
129
|
} else if (element.tagName === 'dl') {
|
|
166
130
|
// Handle standalone dl
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
results.push(
|
|
131
|
+
const extracted = extractFromDl(element);
|
|
132
|
+
if (extracted) {
|
|
133
|
+
results.push(extracted);
|
|
170
134
|
}
|
|
171
135
|
}
|
|
172
136
|
return results;
|
|
@@ -177,54 +141,38 @@ function extractCodeFromSemanticStructure(element) {
|
|
|
177
141
|
*/
|
|
178
142
|
function extractFromDl(dl) {
|
|
179
143
|
// Find dt for filename and dd for code
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// Extract code from dd > pre > code
|
|
198
|
-
var pre = child.children.find(function (ddChild) {
|
|
199
|
-
return ddChild.type === 'element' && ddChild.tagName === 'pre';
|
|
200
|
-
});
|
|
201
|
-
if (pre) {
|
|
202
|
-
var code = pre.children.find(function (preChild) {
|
|
203
|
-
return preChild.type === 'element' && preChild.tagName === 'code';
|
|
204
|
-
});
|
|
205
|
-
if (code) {
|
|
206
|
-
codeElement = code;
|
|
207
|
-
}
|
|
144
|
+
let filename;
|
|
145
|
+
let codeElement;
|
|
146
|
+
for (const child of dl.children) {
|
|
147
|
+
if (child.type === 'element') {
|
|
148
|
+
if (child.tagName === 'dt') {
|
|
149
|
+
// Extract filename from dt > code
|
|
150
|
+
const codeInDt = child.children.find(dtChild => dtChild.type === 'element' && dtChild.tagName === 'code');
|
|
151
|
+
if (codeInDt && codeInDt.children[0] && codeInDt.children[0].type === 'text') {
|
|
152
|
+
filename = codeInDt.children[0].value;
|
|
153
|
+
}
|
|
154
|
+
} else if (child.tagName === 'dd') {
|
|
155
|
+
// Extract code from dd > pre > code
|
|
156
|
+
const pre = child.children.find(ddChild => ddChild.type === 'element' && ddChild.tagName === 'pre');
|
|
157
|
+
if (pre) {
|
|
158
|
+
const code = pre.children.find(preChild => preChild.type === 'element' && preChild.tagName === 'code');
|
|
159
|
+
if (code) {
|
|
160
|
+
codeElement = code;
|
|
208
161
|
}
|
|
209
162
|
}
|
|
210
163
|
}
|
|
211
164
|
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_iterator3.e(err);
|
|
214
|
-
} finally {
|
|
215
|
-
_iterator3.f();
|
|
216
165
|
}
|
|
217
166
|
if (codeElement) {
|
|
218
|
-
var _codeElement$properti3;
|
|
219
167
|
// Extract variant name from data-variant if available
|
|
220
|
-
|
|
168
|
+
const variantName = codeElement.properties?.dataVariant;
|
|
221
169
|
// Extract language from className
|
|
222
|
-
|
|
170
|
+
const language = getLanguage(codeElement);
|
|
223
171
|
return {
|
|
224
|
-
codeElement
|
|
225
|
-
filename
|
|
226
|
-
language
|
|
227
|
-
variantName
|
|
172
|
+
codeElement,
|
|
173
|
+
filename,
|
|
174
|
+
language,
|
|
175
|
+
variantName
|
|
228
176
|
};
|
|
229
177
|
}
|
|
230
178
|
return null;
|
|
@@ -241,219 +189,173 @@ function extractFromDl(dl) {
|
|
|
241
189
|
* 5. Stores the combined precompute data on the root element
|
|
242
190
|
* 6. Clears all code element contents and replaces with error message
|
|
243
191
|
*/
|
|
244
|
-
export
|
|
245
|
-
return
|
|
246
|
-
|
|
247
|
-
var transformPromises, sourceParser, sourceTransformers;
|
|
248
|
-
return _regenerator().w(function (_context3) {
|
|
249
|
-
while (1) switch (_context3.n) {
|
|
250
|
-
case 0:
|
|
251
|
-
transformPromises = []; // Get the source parser and transformers
|
|
252
|
-
sourceParser = createParseSource();
|
|
253
|
-
sourceTransformers = [TypescriptToJavascriptTransformer];
|
|
254
|
-
visit(tree, 'element', function (node) {
|
|
255
|
-
var _node$properties;
|
|
256
|
-
var extractedElements = [];
|
|
192
|
+
export const transformHtmlCodePrecomputed = () => {
|
|
193
|
+
return async tree => {
|
|
194
|
+
const transformPromises = [];
|
|
257
195
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
196
|
+
// Get the source parser and transformers
|
|
197
|
+
const sourceParser = createParseSource();
|
|
198
|
+
const sourceTransformers = [TypescriptToJavascriptTransformer];
|
|
199
|
+
visit(tree, 'element', node => {
|
|
200
|
+
let extractedElements = [];
|
|
201
|
+
|
|
202
|
+
// Handle basic pre > code structure from standard markdown
|
|
203
|
+
if (node.tagName === 'pre' && node.children && node.children.length > 0 && !node.properties?.dataPrecompute // Don't process if already processed
|
|
204
|
+
) {
|
|
205
|
+
// Look for direct code element in pre
|
|
206
|
+
const codeElement = node.children.find(child => child.type === 'element' && child.tagName === 'code');
|
|
207
|
+
if (codeElement) {
|
|
208
|
+
// Extract filename from data-filename attribute (explicit only)
|
|
209
|
+
const filename = getFileName(codeElement);
|
|
210
|
+
// Extract language from className
|
|
211
|
+
const language = getLanguage(codeElement);
|
|
212
|
+
extractedElements = [{
|
|
213
|
+
codeElement,
|
|
214
|
+
filename,
|
|
215
|
+
language,
|
|
216
|
+
variantName: undefined // Basic pre > code doesn't have variants
|
|
217
|
+
}];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Look for section elements (multi-variant) or dl elements (single variant)
|
|
221
|
+
else if ((node.tagName === 'section' || node.tagName === 'dl') && node.children && node.children.length > 0) {
|
|
222
|
+
// Extract code elements from semantic structure
|
|
223
|
+
extractedElements = extractCodeFromSemanticStructure(node);
|
|
224
|
+
}
|
|
225
|
+
if (extractedElements.length > 0) {
|
|
226
|
+
const transformPromise = (async () => {
|
|
227
|
+
try {
|
|
228
|
+
// Create variants from extracted elements
|
|
229
|
+
const variants = {};
|
|
230
|
+
if (extractedElements.length === 1) {
|
|
231
|
+
// Single element - use "Default" as variant name
|
|
232
|
+
const {
|
|
233
|
+
codeElement,
|
|
234
|
+
filename,
|
|
235
|
+
language
|
|
236
|
+
} = extractedElements[0];
|
|
237
|
+
const sourceCode = extractTextContent(codeElement);
|
|
238
|
+
const variant = {
|
|
239
|
+
source: sourceCode,
|
|
240
|
+
skipTransforms: !codeElement.properties?.dataTransform
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// Add filename if explicitly provided
|
|
244
|
+
if (filename) {
|
|
245
|
+
variant.fileName = filename;
|
|
277
246
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
247
|
+
|
|
248
|
+
// Add language if available (from className)
|
|
249
|
+
if (language) {
|
|
250
|
+
variant.language = language;
|
|
282
251
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
// Single element - use "Default" as variant name
|
|
294
|
-
_extractedElements$ = extractedElements[0], _codeElement = _extractedElements$.codeElement, _filename = _extractedElements$.filename, _language = _extractedElements$.language;
|
|
295
|
-
sourceCode = extractTextContent(_codeElement);
|
|
296
|
-
variant = {
|
|
297
|
-
source: sourceCode,
|
|
298
|
-
skipTransforms: !((_codeElement$properti4 = _codeElement.properties) != null && _codeElement$properti4.dataTransform)
|
|
299
|
-
}; // Add filename if explicitly provided
|
|
300
|
-
if (_filename) {
|
|
301
|
-
variant.fileName = _filename;
|
|
302
|
-
}
|
|
252
|
+
variants.Default = variant;
|
|
253
|
+
} else {
|
|
254
|
+
// Multiple elements - use variant names
|
|
255
|
+
extractedElements.forEach(({
|
|
256
|
+
codeElement,
|
|
257
|
+
filename,
|
|
258
|
+
language,
|
|
259
|
+
variantName
|
|
260
|
+
}, index) => {
|
|
261
|
+
const sourceCode = extractTextContent(codeElement);
|
|
303
262
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
// Multiple elements - use variant names
|
|
311
|
-
extractedElements.forEach(function (_ref3, index) {
|
|
312
|
-
var _codeElement$properti5;
|
|
313
|
-
var codeElement = _ref3.codeElement,
|
|
314
|
-
filename = _ref3.filename,
|
|
315
|
-
language = _ref3.language,
|
|
316
|
-
variantName = _ref3.variantName;
|
|
317
|
-
var sourceCode = extractTextContent(codeElement);
|
|
263
|
+
// Determine variant name
|
|
264
|
+
const finalVariantName = variantName || `Variant ${index + 1}`;
|
|
265
|
+
const variant = {
|
|
266
|
+
source: sourceCode,
|
|
267
|
+
skipTransforms: !codeElement.properties?.dataTransform
|
|
268
|
+
};
|
|
318
269
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
skipTransforms: !((_codeElement$properti5 = codeElement.properties) != null && _codeElement$properti5.dataTransform)
|
|
324
|
-
};
|
|
270
|
+
// Add filename if explicitly provided
|
|
271
|
+
if (filename) {
|
|
272
|
+
variant.fileName = filename;
|
|
273
|
+
}
|
|
325
274
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
275
|
+
// Add language if available (from className)
|
|
276
|
+
if (language) {
|
|
277
|
+
variant.language = language;
|
|
278
|
+
}
|
|
279
|
+
variants[finalVariantName] = variant;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
330
282
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
283
|
+
// Process each variant with loadCodeVariant
|
|
284
|
+
const processedCode = {};
|
|
285
|
+
const variantPromises = Object.entries(variants).map(async ([variantName, variantData]) => {
|
|
286
|
+
if (variantData && typeof variantData === 'object') {
|
|
287
|
+
const result = await loadCodeVariant(undefined,
|
|
288
|
+
// url - not needed for inline code
|
|
289
|
+
variantName, variantData, {
|
|
290
|
+
sourceParser,
|
|
291
|
+
loadSource: undefined,
|
|
292
|
+
// loadSource - not needed since we have the data
|
|
293
|
+
loadVariantMeta: undefined,
|
|
294
|
+
// loadVariantMeta - not needed since we have the data
|
|
295
|
+
sourceTransformers,
|
|
296
|
+
disableTransforms: variantData.skipTransforms || false,
|
|
297
|
+
// TODO: output option
|
|
298
|
+
output: 'hastGzip'
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
variantName,
|
|
302
|
+
processedVariant: result.code
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
return null;
|
|
306
|
+
});
|
|
307
|
+
const variantResults = await Promise.all(variantPromises);
|
|
308
|
+
for (const result of variantResults) {
|
|
309
|
+
if (result) {
|
|
310
|
+
processedCode[result.variantName] = result.processedVariant;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
338
313
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
variantPromises = Object.entries(variants).map(/*#__PURE__*/function () {
|
|
342
|
-
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref4) {
|
|
343
|
-
var _ref6, variantName, variantData, result;
|
|
344
|
-
return _regenerator().w(function (_context) {
|
|
345
|
-
while (1) switch (_context.n) {
|
|
346
|
-
case 0:
|
|
347
|
-
_ref6 = _slicedToArray(_ref4, 2), variantName = _ref6[0], variantData = _ref6[1];
|
|
348
|
-
if (!(variantData && _typeof(variantData) === 'object')) {
|
|
349
|
-
_context.n = 2;
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
_context.n = 1;
|
|
353
|
-
return loadCodeVariant(undefined,
|
|
354
|
-
// url - not needed for inline code
|
|
355
|
-
variantName, variantData, {
|
|
356
|
-
sourceParser: sourceParser,
|
|
357
|
-
loadSource: undefined,
|
|
358
|
-
// loadSource - not needed since we have the data
|
|
359
|
-
loadVariantMeta: undefined,
|
|
360
|
-
// loadVariantMeta - not needed since we have the data
|
|
361
|
-
sourceTransformers: sourceTransformers,
|
|
362
|
-
disableTransforms: variantData.skipTransforms || false,
|
|
363
|
-
// TODO: output option
|
|
364
|
-
output: 'hastGzip'
|
|
365
|
-
});
|
|
366
|
-
case 1:
|
|
367
|
-
result = _context.v;
|
|
368
|
-
return _context.a(2, {
|
|
369
|
-
variantName: variantName,
|
|
370
|
-
processedVariant: result.code
|
|
371
|
-
});
|
|
372
|
-
case 2:
|
|
373
|
-
return _context.a(2, null);
|
|
374
|
-
}
|
|
375
|
-
}, _callee);
|
|
376
|
-
}));
|
|
377
|
-
return function (_x2) {
|
|
378
|
-
return _ref5.apply(this, arguments);
|
|
379
|
-
};
|
|
380
|
-
}());
|
|
381
|
-
_context2.n = 1;
|
|
382
|
-
return Promise.all(variantPromises);
|
|
383
|
-
case 1:
|
|
384
|
-
variantResults = _context2.v;
|
|
385
|
-
_iterator4 = _createForOfIteratorHelper(variantResults);
|
|
386
|
-
try {
|
|
387
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
388
|
-
result = _step4.value;
|
|
389
|
-
if (result) {
|
|
390
|
-
processedCode[result.variantName] = result.processedVariant;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
314
|
+
// Extract user props from the first code element (they should be the same for all variants)
|
|
315
|
+
const userProps = extractUserProps(extractedElements[0].codeElement);
|
|
393
316
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
userProps = extractUserProps(extractedElements[0].codeElement); // Clear all code element contents
|
|
401
|
-
extractedElements.forEach(function (_ref7) {
|
|
402
|
-
var codeElement = _ref7.codeElement;
|
|
403
|
-
codeElement.children = [];
|
|
404
|
-
});
|
|
317
|
+
// Clear all code element contents
|
|
318
|
+
extractedElements.forEach(({
|
|
319
|
+
codeElement
|
|
320
|
+
}) => {
|
|
321
|
+
codeElement.children = [];
|
|
322
|
+
});
|
|
405
323
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
324
|
+
// Replace the semantic structure with a <pre> element
|
|
325
|
+
node.tagName = 'pre';
|
|
326
|
+
node.children = [{
|
|
327
|
+
type: 'text',
|
|
328
|
+
value: 'Error: expected pre tag with precomputed data to be handled by the CodeHighlighter component'
|
|
329
|
+
}];
|
|
412
330
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
331
|
+
// Set the precompute data on the pre element directly on properties for immediate HTML serialization
|
|
332
|
+
if (!node.properties) {
|
|
333
|
+
node.properties = {};
|
|
334
|
+
}
|
|
335
|
+
node.properties.dataPrecompute = JSON.stringify(processedCode);
|
|
418
336
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
337
|
+
// Pass through name and slug if provided on the code element
|
|
338
|
+
const firstCodeElement = extractedElements[0].codeElement;
|
|
339
|
+
if (firstCodeElement.properties?.dataName) {
|
|
340
|
+
node.properties.dataName = firstCodeElement.properties.dataName;
|
|
341
|
+
}
|
|
342
|
+
if (firstCodeElement.properties?.dataSlug) {
|
|
343
|
+
node.properties.dataSlug = firstCodeElement.properties.dataSlug;
|
|
344
|
+
}
|
|
427
345
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return _context2.a(2);
|
|
440
|
-
}
|
|
441
|
-
}, _callee2, null, [[0, 2]]);
|
|
442
|
-
}))();
|
|
443
|
-
transformPromises.push(transformPromise);
|
|
444
|
-
}
|
|
445
|
-
});
|
|
346
|
+
// Set user props if any exist
|
|
347
|
+
if (userProps) {
|
|
348
|
+
node.properties.dataContentProps = JSON.stringify(userProps);
|
|
349
|
+
}
|
|
350
|
+
} catch (error) {
|
|
351
|
+
console.warn('Failed to transform code block:', error);
|
|
352
|
+
}
|
|
353
|
+
})();
|
|
354
|
+
transformPromises.push(transformPromise);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
446
357
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
case 1:
|
|
451
|
-
return _context3.a(2);
|
|
452
|
-
}
|
|
453
|
-
}, _callee3);
|
|
454
|
-
}));
|
|
455
|
-
return function (_x) {
|
|
456
|
-
return _ref.apply(this, arguments);
|
|
457
|
-
};
|
|
458
|
-
}();
|
|
358
|
+
// Wait for all transformations to complete
|
|
359
|
+
await Promise.all(transformPromises);
|
|
360
|
+
};
|
|
459
361
|
};
|