@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,6 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
1
|
import { visit } from 'unist-util-visit';
|
|
5
2
|
import { normalizeLanguage } from "../loaderUtils/getLanguageFromExtension.js";
|
|
6
3
|
|
|
@@ -93,26 +90,22 @@ function getFileName(props) {
|
|
|
93
90
|
* Parse meta string to extract variant and other properties
|
|
94
91
|
*/
|
|
95
92
|
function parseMeta(meta) {
|
|
96
|
-
|
|
93
|
+
const result = {
|
|
97
94
|
props: {}
|
|
98
95
|
};
|
|
99
96
|
|
|
100
97
|
// Parse key=value pairs first, handling quoted values
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
const keyValueRegex = /([\w-]+)=("(?:[^"\\]|\\.)*"|[^\s]+)/g;
|
|
99
|
+
let match = keyValueRegex.exec(meta);
|
|
100
|
+
const processedPositions = [];
|
|
104
101
|
while (match !== null) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
key = _match2[1],
|
|
109
|
-
rawValue = _match2[2];
|
|
110
|
-
var startPos = match.index;
|
|
111
|
-
var endPos = match.index + fullMatch.length;
|
|
102
|
+
const [fullMatch, key, rawValue] = match;
|
|
103
|
+
const startPos = match.index;
|
|
104
|
+
const endPos = match.index + fullMatch.length;
|
|
112
105
|
processedPositions.push([startPos, endPos]);
|
|
113
106
|
|
|
114
107
|
// Remove quotes if present
|
|
115
|
-
|
|
108
|
+
const value = rawValue.startsWith('"') && rawValue.endsWith('"') ? rawValue.slice(1, -1) : rawValue;
|
|
116
109
|
if (key === 'variant') {
|
|
117
110
|
result.variant = value;
|
|
118
111
|
} else if (key === 'variant-type') {
|
|
@@ -124,46 +117,32 @@ function parseMeta(meta) {
|
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
// Extract remaining parts as standalone flags
|
|
127
|
-
|
|
120
|
+
let remainingMeta = meta;
|
|
128
121
|
// Remove processed key=value pairs from the string (in reverse order to maintain positions)
|
|
129
|
-
processedPositions.sort(
|
|
130
|
-
return b[0] - a[0];
|
|
131
|
-
}).forEach(function (_ref) {
|
|
132
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
133
|
-
start = _ref2[0],
|
|
134
|
-
end = _ref2[1];
|
|
122
|
+
processedPositions.sort((a, b) => b[0] - a[0]).forEach(([start, end]) => {
|
|
135
123
|
remainingMeta = remainingMeta.slice(0, start) + remainingMeta.slice(end);
|
|
136
124
|
});
|
|
137
125
|
|
|
138
126
|
// Process remaining standalone flags
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
result.variantType = 'true';
|
|
151
|
-
} else {
|
|
152
|
-
// Handle standalone flags (e.g., "transform" becomes "transform": "true")
|
|
153
|
-
result.props[part] = 'true';
|
|
154
|
-
}
|
|
127
|
+
const remainingParts = remainingMeta.trim().split(/\s+/).filter(Boolean);
|
|
128
|
+
for (const part of remainingParts) {
|
|
129
|
+
if (part === 'variant') {
|
|
130
|
+
// This shouldn't happen, but just in case
|
|
131
|
+
result.variant = 'true';
|
|
132
|
+
} else if (part === 'variant-type') {
|
|
133
|
+
// This shouldn't happen, but just in case
|
|
134
|
+
result.variantType = 'true';
|
|
135
|
+
} else {
|
|
136
|
+
// Handle standalone flags (e.g., "transform" becomes "transform": "true")
|
|
137
|
+
result.props[part] = 'true';
|
|
155
138
|
}
|
|
156
|
-
} catch (err) {
|
|
157
|
-
_iterator.e(err);
|
|
158
|
-
} finally {
|
|
159
|
-
_iterator.f();
|
|
160
139
|
}
|
|
161
140
|
return result;
|
|
162
141
|
}
|
|
163
|
-
export
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
visit(tree,
|
|
142
|
+
export const transformMarkdownCode = () => {
|
|
143
|
+
return tree => {
|
|
144
|
+
const processedIndices = new Set();
|
|
145
|
+
visit(tree, (node, index, parent) => {
|
|
167
146
|
if (!parent || !Array.isArray(parent.children) || typeof index !== 'number') {
|
|
168
147
|
return;
|
|
169
148
|
}
|
|
@@ -172,15 +151,15 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
172
151
|
if (processedIndices.has(index)) {
|
|
173
152
|
return;
|
|
174
153
|
}
|
|
175
|
-
|
|
154
|
+
const parentNode = parent;
|
|
176
155
|
|
|
177
156
|
// Look for code blocks with variant metadata or options
|
|
178
157
|
if (node.type === 'code') {
|
|
179
|
-
|
|
158
|
+
const codeNode = node;
|
|
180
159
|
|
|
181
160
|
// Check if variant metadata is in meta field or lang field (when no language is specified)
|
|
182
|
-
|
|
183
|
-
|
|
161
|
+
let metaString = codeNode.meta;
|
|
162
|
+
let langFromMeta = codeNode.lang || null;
|
|
184
163
|
|
|
185
164
|
// If meta is empty but lang contains '=', it means variant info is in lang
|
|
186
165
|
if (!metaString && codeNode.lang && codeNode.lang.includes('=')) {
|
|
@@ -189,7 +168,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
189
168
|
}
|
|
190
169
|
|
|
191
170
|
// Check if we have variants/variant-types or individual options
|
|
192
|
-
|
|
171
|
+
let metaData = {
|
|
193
172
|
props: {}
|
|
194
173
|
};
|
|
195
174
|
if (metaString) {
|
|
@@ -197,32 +176,27 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
197
176
|
}
|
|
198
177
|
|
|
199
178
|
// Use props from meta as the options for individual blocks
|
|
200
|
-
|
|
179
|
+
const allProps = metaData.props;
|
|
201
180
|
|
|
202
181
|
// Handle individual code blocks with options (but no variants)
|
|
203
182
|
if (!metaData.variant && !metaData.variantType && Object.keys(allProps).length > 0) {
|
|
204
|
-
|
|
183
|
+
const codeHProperties = {};
|
|
205
184
|
|
|
206
185
|
// Add normalized language as class
|
|
207
186
|
if (langFromMeta) {
|
|
208
|
-
codeHProperties.className =
|
|
187
|
+
codeHProperties.className = `language-${normalizeLanguage(langFromMeta)}`;
|
|
209
188
|
}
|
|
210
189
|
|
|
211
190
|
// Add all props as data attributes (in camelCase)
|
|
212
|
-
Object.entries(allProps).forEach(
|
|
213
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
214
|
-
key = _ref4[0],
|
|
215
|
-
value = _ref4[1];
|
|
191
|
+
Object.entries(allProps).forEach(([key, value]) => {
|
|
216
192
|
// Convert kebab-case to camelCase for data attributes
|
|
217
|
-
|
|
218
|
-
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
219
|
-
}).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
|
|
193
|
+
const camelKey = key.includes('-') ? `data${key.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('')}` : `data${key.charAt(0).toUpperCase() + key.slice(1)}`;
|
|
220
194
|
codeHProperties[camelKey] = value;
|
|
221
195
|
});
|
|
222
|
-
|
|
196
|
+
const fileName = getFileName(allProps);
|
|
223
197
|
|
|
224
198
|
// Create pre > code element
|
|
225
|
-
|
|
199
|
+
const preElement = {
|
|
226
200
|
type: 'element',
|
|
227
201
|
tagName: 'pre',
|
|
228
202
|
data: {
|
|
@@ -245,7 +219,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
245
219
|
|
|
246
220
|
// If there's a filename, wrap in dl/dt/dd structure
|
|
247
221
|
// Otherwise, just use pre > code directly
|
|
248
|
-
|
|
222
|
+
const outputElement = fileName ? {
|
|
249
223
|
type: 'element',
|
|
250
224
|
tagName: 'dl',
|
|
251
225
|
data: {
|
|
@@ -294,24 +268,24 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
294
268
|
}
|
|
295
269
|
if (metaData.variant || metaData.variantType) {
|
|
296
270
|
// Collect consecutive code blocks that belong together
|
|
297
|
-
|
|
298
|
-
|
|
271
|
+
const codeBlocks = [];
|
|
272
|
+
let currentIndex = index;
|
|
299
273
|
|
|
300
274
|
// For variant-type, look for pattern: [label] -> code block
|
|
301
275
|
// For variant, look for adjacent code blocks only
|
|
302
276
|
|
|
303
277
|
if (metaData.variantType) {
|
|
304
278
|
// Add the current code block as the first one for variant-type
|
|
305
|
-
|
|
279
|
+
let currentLabelFromPrevious;
|
|
306
280
|
if (index > 0) {
|
|
307
|
-
|
|
281
|
+
const prevNode = parentNode.children[index - 1];
|
|
308
282
|
if (prevNode.type === 'paragraph' && prevNode.children.length === 1 && prevNode.children[0].type === 'text') {
|
|
309
283
|
currentLabelFromPrevious = prevNode.children[0].value.trim();
|
|
310
284
|
}
|
|
311
285
|
}
|
|
312
286
|
codeBlocks.push({
|
|
313
287
|
node: codeNode,
|
|
314
|
-
index
|
|
288
|
+
index,
|
|
315
289
|
variant: currentLabelFromPrevious || metaData.variantType || 'default',
|
|
316
290
|
props: allProps,
|
|
317
291
|
actualLang: langFromMeta,
|
|
@@ -324,32 +298,32 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
324
298
|
|
|
325
299
|
// Collect all blocks with the same variant-type
|
|
326
300
|
while (currentIndex < parentNode.children.length) {
|
|
327
|
-
|
|
301
|
+
const currentNode = parentNode.children[currentIndex];
|
|
328
302
|
|
|
329
303
|
// Check if this is a potential label paragraph
|
|
330
304
|
if (currentNode.type === 'paragraph' && currentNode.children.length === 1 && currentNode.children[0].type === 'text') {
|
|
331
305
|
// Look for a code block after this paragraph
|
|
332
306
|
if (currentIndex + 1 < parentNode.children.length) {
|
|
333
|
-
|
|
307
|
+
const nextNode = parentNode.children[currentIndex + 1];
|
|
334
308
|
if (nextNode.type === 'code') {
|
|
335
309
|
// Check if this code block has the same variant-type
|
|
336
|
-
|
|
337
|
-
|
|
310
|
+
let nextMetaString = nextNode.meta;
|
|
311
|
+
let nextActualLang = nextNode.lang;
|
|
338
312
|
if (!nextMetaString && nextActualLang && nextActualLang.includes('=')) {
|
|
339
313
|
nextMetaString = nextActualLang;
|
|
340
314
|
nextActualLang = null;
|
|
341
315
|
}
|
|
342
316
|
if (nextMetaString) {
|
|
343
|
-
|
|
317
|
+
const nextMetaData = parseMeta(nextMetaString);
|
|
344
318
|
if (nextMetaData.variantType === metaData.variantType) {
|
|
345
|
-
|
|
319
|
+
const labelFromPrevious = currentNode.children[0].value.trim();
|
|
346
320
|
codeBlocks.push({
|
|
347
321
|
node: nextNode,
|
|
348
322
|
index: currentIndex + 1,
|
|
349
323
|
variant: labelFromPrevious || nextMetaData.variantType || 'default',
|
|
350
324
|
props: nextMetaData.props,
|
|
351
325
|
actualLang: nextActualLang,
|
|
352
|
-
labelFromPrevious
|
|
326
|
+
labelFromPrevious
|
|
353
327
|
});
|
|
354
328
|
processedIndices.add(currentIndex + 1);
|
|
355
329
|
|
|
@@ -365,30 +339,30 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
365
339
|
}
|
|
366
340
|
if (currentNode.type === 'code') {
|
|
367
341
|
// Parse language and meta for current node
|
|
368
|
-
|
|
369
|
-
|
|
342
|
+
let currentMetaString = currentNode.meta;
|
|
343
|
+
let currentActualLang = currentNode.lang;
|
|
370
344
|
if (!currentMetaString && currentActualLang && currentActualLang.includes('=')) {
|
|
371
345
|
currentMetaString = currentActualLang;
|
|
372
346
|
currentActualLang = null;
|
|
373
347
|
}
|
|
374
348
|
if (currentMetaString) {
|
|
375
|
-
|
|
349
|
+
const currentMetaData = parseMeta(currentMetaString);
|
|
376
350
|
if (currentMetaData.variantType === metaData.variantType) {
|
|
377
351
|
// Look for label before this code block
|
|
378
|
-
|
|
352
|
+
let labelFromPrevious;
|
|
379
353
|
if (currentIndex > 0) {
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
354
|
+
const prevNode = parentNode.children[currentIndex - 1];
|
|
355
|
+
if (prevNode.type === 'paragraph' && prevNode.children.length === 1 && prevNode.children[0].type === 'text') {
|
|
356
|
+
labelFromPrevious = prevNode.children[0].value.trim();
|
|
383
357
|
}
|
|
384
358
|
}
|
|
385
359
|
codeBlocks.push({
|
|
386
360
|
node: currentNode,
|
|
387
361
|
index: currentIndex,
|
|
388
|
-
variant:
|
|
362
|
+
variant: labelFromPrevious || currentMetaData.variantType || 'default',
|
|
389
363
|
props: currentMetaData.props,
|
|
390
364
|
actualLang: currentActualLang,
|
|
391
|
-
labelFromPrevious
|
|
365
|
+
labelFromPrevious
|
|
392
366
|
});
|
|
393
367
|
processedIndices.add(currentIndex);
|
|
394
368
|
|
|
@@ -397,8 +371,8 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
397
371
|
|
|
398
372
|
// Skip ahead past any paragraph that could be a label
|
|
399
373
|
if (currentIndex < parentNode.children.length) {
|
|
400
|
-
|
|
401
|
-
if (
|
|
374
|
+
const nextNode = parentNode.children[currentIndex];
|
|
375
|
+
if (nextNode.type === 'paragraph' && nextNode.children.length === 1 && nextNode.children[0].type === 'text') {
|
|
402
376
|
currentIndex += 1; // Skip the potential label
|
|
403
377
|
}
|
|
404
378
|
}
|
|
@@ -416,7 +390,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
416
390
|
// Add the current code block as the first one for variant
|
|
417
391
|
codeBlocks.push({
|
|
418
392
|
node: codeNode,
|
|
419
|
-
index
|
|
393
|
+
index,
|
|
420
394
|
variant: metaData.variant,
|
|
421
395
|
props: allProps,
|
|
422
396
|
actualLang: langFromMeta
|
|
@@ -428,24 +402,24 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
428
402
|
|
|
429
403
|
// Collect adjacent code blocks with variants
|
|
430
404
|
while (currentIndex < parentNode.children.length) {
|
|
431
|
-
|
|
432
|
-
if (
|
|
405
|
+
const currentNode = parentNode.children[currentIndex];
|
|
406
|
+
if (currentNode.type === 'code') {
|
|
433
407
|
// Parse language and meta for current node
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (!
|
|
437
|
-
|
|
438
|
-
|
|
408
|
+
let currentMetaString = currentNode.meta;
|
|
409
|
+
let currentActualLang = currentNode.lang;
|
|
410
|
+
if (!currentMetaString && currentActualLang && currentActualLang.includes('=')) {
|
|
411
|
+
currentMetaString = currentActualLang;
|
|
412
|
+
currentActualLang = null;
|
|
439
413
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
if (
|
|
414
|
+
if (currentMetaString) {
|
|
415
|
+
const currentMetaData = parseMeta(currentMetaString);
|
|
416
|
+
if (currentMetaData.variant) {
|
|
443
417
|
codeBlocks.push({
|
|
444
|
-
node:
|
|
418
|
+
node: currentNode,
|
|
445
419
|
index: currentIndex,
|
|
446
|
-
variant:
|
|
447
|
-
props:
|
|
448
|
-
actualLang:
|
|
420
|
+
variant: currentMetaData.variant,
|
|
421
|
+
props: currentMetaData.props,
|
|
422
|
+
actualLang: currentActualLang
|
|
449
423
|
});
|
|
450
424
|
processedIndices.add(currentIndex);
|
|
451
425
|
currentIndex += 1;
|
|
@@ -464,37 +438,32 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
464
438
|
// Only process if we have multiple blocks
|
|
465
439
|
if (codeBlocks.length > 1) {
|
|
466
440
|
// Create section with figure elements for each variant
|
|
467
|
-
|
|
441
|
+
const sectionElement = {
|
|
468
442
|
type: 'element',
|
|
469
443
|
tagName: 'section',
|
|
470
444
|
data: {
|
|
471
445
|
hName: 'section',
|
|
472
446
|
hProperties: {}
|
|
473
447
|
},
|
|
474
|
-
children: codeBlocks.map(
|
|
448
|
+
children: codeBlocks.map(block => {
|
|
475
449
|
// Build hProperties for HTML attributes
|
|
476
|
-
|
|
450
|
+
const codeHProperties = {};
|
|
477
451
|
|
|
478
452
|
// Add normalized language as class
|
|
479
453
|
if (block.actualLang) {
|
|
480
|
-
codeHProperties.className =
|
|
454
|
+
codeHProperties.className = `language-${normalizeLanguage(block.actualLang)}`;
|
|
481
455
|
}
|
|
482
456
|
|
|
483
457
|
// Add additional props as data attributes (in camelCase)
|
|
484
|
-
Object.entries(block.props).forEach(
|
|
485
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
486
|
-
key = _ref6[0],
|
|
487
|
-
value = _ref6[1];
|
|
458
|
+
Object.entries(block.props).forEach(([key, value]) => {
|
|
488
459
|
// Convert kebab-case to camelCase for data attributes
|
|
489
|
-
|
|
490
|
-
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
491
|
-
}).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
|
|
460
|
+
const camelKey = key.includes('-') ? `data${key.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('')}` : `data${key.charAt(0).toUpperCase() + key.slice(1)}`;
|
|
492
461
|
codeHProperties[camelKey] = value;
|
|
493
462
|
});
|
|
494
463
|
|
|
495
464
|
// Add data-variant to track the variant
|
|
496
465
|
codeHProperties.dataVariant = block.variant;
|
|
497
|
-
|
|
466
|
+
const fileName = getFileName(block.props);
|
|
498
467
|
return {
|
|
499
468
|
type: 'element',
|
|
500
469
|
tagName: 'figure',
|
|
@@ -511,7 +480,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
511
480
|
},
|
|
512
481
|
children: [{
|
|
513
482
|
type: 'text',
|
|
514
|
-
value:
|
|
483
|
+
value: `${block.variant} variant`
|
|
515
484
|
}]
|
|
516
485
|
}, {
|
|
517
486
|
type: 'element',
|
|
@@ -520,7 +489,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
520
489
|
hName: 'dl',
|
|
521
490
|
hProperties: {}
|
|
522
491
|
},
|
|
523
|
-
children: [
|
|
492
|
+
children: [...(fileName ? [{
|
|
524
493
|
type: 'element',
|
|
525
494
|
tagName: 'dt',
|
|
526
495
|
data: {
|
|
@@ -539,7 +508,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
539
508
|
value: fileName
|
|
540
509
|
}]
|
|
541
510
|
}]
|
|
542
|
-
}] : []),
|
|
511
|
+
}] : []), {
|
|
543
512
|
type: 'element',
|
|
544
513
|
tagName: 'dd',
|
|
545
514
|
data: {
|
|
@@ -559,12 +528,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
559
528
|
data: {
|
|
560
529
|
hName: 'code',
|
|
561
530
|
hProperties: codeHProperties,
|
|
562
|
-
meta:
|
|
563
|
-
var _ref8 = _slicedToArray(_ref7, 2),
|
|
564
|
-
key = _ref8[0],
|
|
565
|
-
value = _ref8[1];
|
|
566
|
-
return " ".concat(key, "=").concat(value);
|
|
567
|
-
}).join(''))
|
|
531
|
+
meta: `variant=${block.variant}${Object.entries(block.props).map(([key, value]) => ` ${key}=${value}`).join('')}`
|
|
568
532
|
},
|
|
569
533
|
children: [{
|
|
570
534
|
type: 'text',
|
|
@@ -572,7 +536,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
572
536
|
}]
|
|
573
537
|
}]
|
|
574
538
|
}]
|
|
575
|
-
}]
|
|
539
|
+
}]
|
|
576
540
|
}]
|
|
577
541
|
};
|
|
578
542
|
})
|
|
@@ -582,62 +546,48 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
582
546
|
parentNode.children[codeBlocks[0].index] = sectionElement;
|
|
583
547
|
|
|
584
548
|
// Remove all other code blocks and their labels (in reverse order to maintain indices)
|
|
585
|
-
|
|
586
|
-
|
|
549
|
+
const indicesToRemove = codeBlocks.slice(1).map(block => {
|
|
550
|
+
const indices = [block.index];
|
|
587
551
|
// Also include label paragraph if it exists
|
|
588
552
|
if (block.labelFromPrevious && block.index > 0) {
|
|
589
|
-
|
|
590
|
-
if (
|
|
553
|
+
const prevNode = parentNode.children[block.index - 1];
|
|
554
|
+
if (prevNode.type === 'paragraph') {
|
|
591
555
|
indices.push(block.index - 1);
|
|
592
556
|
}
|
|
593
557
|
}
|
|
594
558
|
return indices;
|
|
595
|
-
}).flat().sort(
|
|
596
|
-
return b - a;
|
|
597
|
-
}); // Sort in descending order
|
|
559
|
+
}).flat().sort((a, b) => b - a); // Sort in descending order
|
|
598
560
|
|
|
599
561
|
// Remove the marked indices
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
processedIndices.clear();
|
|
618
|
-
_updatedProcessedIndices.forEach(function (processedIdx) {
|
|
619
|
-
processedIndices.add(processedIdx);
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
624
|
-
_loop();
|
|
562
|
+
for (const removeIdx of indicesToRemove) {
|
|
563
|
+
if (removeIdx < parentNode.children.length) {
|
|
564
|
+
parentNode.children.splice(removeIdx, 1);
|
|
565
|
+
// Update processed indices to account for removed elements
|
|
566
|
+
const updatedProcessedIndices = new Set();
|
|
567
|
+
processedIndices.forEach(processedIdx => {
|
|
568
|
+
if (processedIdx > removeIdx) {
|
|
569
|
+
updatedProcessedIndices.add(processedIdx - 1);
|
|
570
|
+
} else if (processedIdx < removeIdx) {
|
|
571
|
+
updatedProcessedIndices.add(processedIdx);
|
|
572
|
+
}
|
|
573
|
+
// Don't add the removed index
|
|
574
|
+
});
|
|
575
|
+
processedIndices.clear();
|
|
576
|
+
updatedProcessedIndices.forEach(processedIdx => {
|
|
577
|
+
processedIndices.add(processedIdx);
|
|
578
|
+
});
|
|
625
579
|
}
|
|
626
|
-
|
|
627
|
-
// Also remove the label of the first block if it exists
|
|
628
|
-
} catch (err) {
|
|
629
|
-
_iterator2.e(err);
|
|
630
|
-
} finally {
|
|
631
|
-
_iterator2.f();
|
|
632
580
|
}
|
|
581
|
+
|
|
582
|
+
// Also remove the label of the first block if it exists
|
|
633
583
|
if (codeBlocks[0].labelFromPrevious && codeBlocks[0].index > 0) {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (
|
|
584
|
+
const labelIndex = codeBlocks[0].index - 1;
|
|
585
|
+
const prevNode = parentNode.children[labelIndex];
|
|
586
|
+
if (prevNode && prevNode.type === 'paragraph') {
|
|
637
587
|
parentNode.children.splice(labelIndex, 1);
|
|
638
588
|
// Update processed indices
|
|
639
|
-
|
|
640
|
-
processedIndices.forEach(
|
|
589
|
+
const updatedProcessedIndices = new Set();
|
|
590
|
+
processedIndices.forEach(processedIdx => {
|
|
641
591
|
if (processedIdx > labelIndex) {
|
|
642
592
|
updatedProcessedIndices.add(processedIdx - 1);
|
|
643
593
|
} else if (processedIdx < labelIndex) {
|
|
@@ -645,44 +595,39 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
645
595
|
}
|
|
646
596
|
});
|
|
647
597
|
processedIndices.clear();
|
|
648
|
-
updatedProcessedIndices.forEach(
|
|
598
|
+
updatedProcessedIndices.forEach(processedIdx => {
|
|
649
599
|
processedIndices.add(processedIdx);
|
|
650
600
|
});
|
|
651
601
|
}
|
|
652
602
|
}
|
|
653
603
|
} else if (codeBlocks.length === 1) {
|
|
654
604
|
// Single code block with variant - create a simple dl without figure wrapper
|
|
655
|
-
|
|
656
|
-
|
|
605
|
+
const block = codeBlocks[0];
|
|
606
|
+
const codeHProperties = {};
|
|
657
607
|
|
|
658
608
|
// Add normalized language as class
|
|
659
609
|
if (block.actualLang) {
|
|
660
|
-
|
|
610
|
+
codeHProperties.className = `language-${normalizeLanguage(block.actualLang)}`;
|
|
661
611
|
}
|
|
662
612
|
|
|
663
613
|
// Add additional props as data attributes (in camelCase)
|
|
664
|
-
Object.entries(block.props).forEach(
|
|
665
|
-
var _ref0 = _slicedToArray(_ref9, 2),
|
|
666
|
-
key = _ref0[0],
|
|
667
|
-
value = _ref0[1];
|
|
614
|
+
Object.entries(block.props).forEach(([key, value]) => {
|
|
668
615
|
// Convert kebab-case to camelCase for data attributes
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}).join('')) : "data".concat(key.charAt(0).toUpperCase() + key.slice(1));
|
|
672
|
-
_codeHProperties[camelKey] = value;
|
|
616
|
+
const camelKey = key.includes('-') ? `data${key.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('')}` : `data${key.charAt(0).toUpperCase() + key.slice(1)}`;
|
|
617
|
+
codeHProperties[camelKey] = value;
|
|
673
618
|
});
|
|
674
619
|
|
|
675
620
|
// Add data-variant to track the variant
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
621
|
+
codeHProperties.dataVariant = block.variant;
|
|
622
|
+
const fileName = getFileName(block.props);
|
|
623
|
+
const dlElement = {
|
|
679
624
|
type: 'element',
|
|
680
625
|
tagName: 'dl',
|
|
681
626
|
data: {
|
|
682
627
|
hName: 'dl',
|
|
683
628
|
hProperties: {}
|
|
684
629
|
},
|
|
685
|
-
children: [
|
|
630
|
+
children: [...(fileName ? [{
|
|
686
631
|
type: 'element',
|
|
687
632
|
tagName: 'dt',
|
|
688
633
|
data: {
|
|
@@ -698,10 +643,10 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
698
643
|
},
|
|
699
644
|
children: [{
|
|
700
645
|
type: 'text',
|
|
701
|
-
value:
|
|
646
|
+
value: fileName
|
|
702
647
|
}]
|
|
703
648
|
}]
|
|
704
|
-
}] : []),
|
|
649
|
+
}] : []), {
|
|
705
650
|
type: 'element',
|
|
706
651
|
tagName: 'dd',
|
|
707
652
|
data: {
|
|
@@ -720,13 +665,8 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
720
665
|
tagName: 'code',
|
|
721
666
|
data: {
|
|
722
667
|
hName: 'code',
|
|
723
|
-
hProperties:
|
|
724
|
-
meta:
|
|
725
|
-
var _ref10 = _slicedToArray(_ref1, 2),
|
|
726
|
-
key = _ref10[0],
|
|
727
|
-
value = _ref10[1];
|
|
728
|
-
return " ".concat(key, "=").concat(value);
|
|
729
|
-
}).join(''))
|
|
668
|
+
hProperties: codeHProperties,
|
|
669
|
+
meta: `variant=${block.variant}${Object.entries(block.props).map(([key, value]) => ` ${key}=${value}`).join('')}`
|
|
730
670
|
},
|
|
731
671
|
children: [{
|
|
732
672
|
type: 'text',
|
|
@@ -734,7 +674,7 @@ export var transformMarkdownCode = function transformMarkdownCode() {
|
|
|
734
674
|
}]
|
|
735
675
|
}]
|
|
736
676
|
}]
|
|
737
|
-
}]
|
|
677
|
+
}]
|
|
738
678
|
};
|
|
739
679
|
|
|
740
680
|
// Replace this single code block
|