@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
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
3
|
import { createStarryNight } from '@wooorm/starry-night';
|
|
4
|
-
import { grammars, extensionMap } from "./grammars.js";
|
|
4
|
+
import { grammars, extensionMap, getGrammarFromLanguage } from "./grammars.js";
|
|
5
5
|
import { starryNightGutter } from "./addLineGutters.js";
|
|
6
6
|
var STARRY_NIGHT_KEY = '__docs_infra_starry_night_instance__';
|
|
7
|
-
export var parseSource = function parseSource(source, fileName) {
|
|
7
|
+
export var parseSource = function parseSource(source, fileName, language) {
|
|
8
8
|
var starryNight = globalThis[STARRY_NIGHT_KEY];
|
|
9
9
|
if (!starryNight) {
|
|
10
10
|
throw new Error('Starry Night not initialized. Use createParseSource to create an initialized parseSource function.');
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
// Determine the grammar scope: prefer explicit language, then fall back to file extension
|
|
14
|
+
var grammarScope;
|
|
15
|
+
if (language) {
|
|
16
|
+
grammarScope = getGrammarFromLanguage(language);
|
|
17
|
+
}
|
|
18
|
+
if (!grammarScope && fileName) {
|
|
19
|
+
var fileType = fileName.slice(fileName.lastIndexOf('.'));
|
|
20
|
+
grammarScope = extensionMap[fileType];
|
|
21
|
+
}
|
|
22
|
+
if (!grammarScope) {
|
|
14
23
|
// Return a basic HAST root node with the source text for unsupported file types
|
|
15
24
|
// TODO: should we split and add line gutters?
|
|
16
25
|
return {
|
|
@@ -21,7 +30,7 @@ export var parseSource = function parseSource(source, fileName) {
|
|
|
21
30
|
}]
|
|
22
31
|
};
|
|
23
32
|
}
|
|
24
|
-
var highlighted = starryNight.highlight(source,
|
|
33
|
+
var highlighted = starryNight.highlight(source, grammarScope);
|
|
25
34
|
var sourceLines = source.split(/\r?\n|\r/);
|
|
26
35
|
starryNightGutter(highlighted, sourceLines); // mutates the tree to add line gutters
|
|
27
36
|
|
|
@@ -68,7 +68,6 @@ function _mergeMetadataMarkdown() {
|
|
|
68
68
|
_step2,
|
|
69
69
|
existingPage,
|
|
70
70
|
newPage,
|
|
71
|
-
_newPage$openGraph,
|
|
72
71
|
descriptionMarkdown,
|
|
73
72
|
existingPageWithoutDescriptionMarkdown,
|
|
74
73
|
merged,
|
|
@@ -148,11 +147,7 @@ function _mergeMetadataMarkdown() {
|
|
|
148
147
|
// Preserve skipDetailSection from existing (user-managed for external links)
|
|
149
148
|
skipDetailSection: existingPage.skipDetailSection,
|
|
150
149
|
// Preserve sections from existing if new doesn't have them
|
|
151
|
-
sections: newPage.sections || existingPage.sections
|
|
152
|
-
// Merge openGraph, but ensure description comes from newPage if it has one
|
|
153
|
-
openGraph: (_newPage$openGraph = newPage.openGraph) != null ? _newPage$openGraph : newPage.description ? _extends(_extends({}, existingPage.openGraph), {}, {
|
|
154
|
-
description: newPage.description
|
|
155
|
-
}) : existingPage.openGraph
|
|
150
|
+
sections: newPage.sections || existingPage.sections
|
|
156
151
|
});
|
|
157
152
|
pages.push(merged);
|
|
158
153
|
addedPaths.add(newPage.path);
|
|
@@ -429,9 +429,8 @@ export function metadataToMarkdownAst(data) {
|
|
|
429
429
|
_step5;
|
|
430
430
|
try {
|
|
431
431
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
432
|
-
var _page$openGraph;
|
|
433
432
|
var page = _step5.value;
|
|
434
|
-
var pageTitle =
|
|
433
|
+
var pageTitle = page.title || page.slug;
|
|
435
434
|
|
|
436
435
|
// Check if this is a single-link entry (external link or no detail section)
|
|
437
436
|
var isSingleLink = page.skipDetailSection || false;
|
|
@@ -511,13 +510,12 @@ export function metadataToMarkdownAst(data) {
|
|
|
511
510
|
_step6;
|
|
512
511
|
try {
|
|
513
512
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
514
|
-
var _page$openGraph2, _page$openGraph3, _page$openGraph4;
|
|
515
513
|
var _page = _step6.value;
|
|
516
|
-
var _pageTitle =
|
|
514
|
+
var _pageTitle = _page.title || _page.slug;
|
|
517
515
|
// Note: We don't replace newlines here to allow natural line breaks in detailed sections
|
|
518
|
-
var description =
|
|
516
|
+
var description = _page.description || 'No description available';
|
|
519
517
|
var keywords = _page.keywords || [];
|
|
520
|
-
var image =
|
|
518
|
+
var image = _page.image;
|
|
521
519
|
|
|
522
520
|
// Add page heading
|
|
523
521
|
children.push(heading(2, _pageTitle));
|
|
@@ -800,9 +798,8 @@ export function metadataToMarkdown(data) {
|
|
|
800
798
|
_step9;
|
|
801
799
|
try {
|
|
802
800
|
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
803
|
-
var _page$openGraph5;
|
|
804
801
|
var page = _step9.value;
|
|
805
|
-
var pageTitle =
|
|
802
|
+
var pageTitle = page.title || page.slug;
|
|
806
803
|
|
|
807
804
|
// Check if this is a single-link entry (external link or no detail section)
|
|
808
805
|
var isSingleLink = page.skipDetailSection || false;
|
|
@@ -871,24 +868,22 @@ export function metadataToMarkdown(data) {
|
|
|
871
868
|
_step0;
|
|
872
869
|
try {
|
|
873
870
|
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
874
|
-
var _page2$openGraph, _page2$openGraph3;
|
|
875
871
|
var _page2 = _step0.value;
|
|
876
872
|
// Skip detail section for single-link entries (external links)
|
|
877
873
|
if (_page2.skipDetailSection) {
|
|
878
874
|
continue;
|
|
879
875
|
}
|
|
880
|
-
var _pageTitle2 =
|
|
876
|
+
var _pageTitle2 = _page2.title || _page2.slug;
|
|
881
877
|
// Use descriptionMarkdown to preserve formatting if available
|
|
882
878
|
// Note: We don't replace newlines here to allow natural line breaks in detailed sections
|
|
883
879
|
var pageDescription = void 0;
|
|
884
880
|
if (_page2.descriptionMarkdown && _page2.descriptionMarkdown.length > 0) {
|
|
885
881
|
pageDescription = astNodesToMarkdown(_page2.descriptionMarkdown);
|
|
886
882
|
} else {
|
|
887
|
-
|
|
888
|
-
pageDescription = ((_page2$openGraph2 = _page2.openGraph) == null ? void 0 : _page2$openGraph2.description) || _page2.description || 'No description available';
|
|
883
|
+
pageDescription = _page2.description || 'No description available';
|
|
889
884
|
}
|
|
890
885
|
var keywords = _page2.keywords || [];
|
|
891
|
-
var image =
|
|
886
|
+
var image = _page2.image;
|
|
892
887
|
|
|
893
888
|
// Add page heading
|
|
894
889
|
lines.push("## ".concat(_pageTitle2));
|
|
@@ -1164,12 +1159,7 @@ function _markdownToMetadata() {
|
|
|
1164
1159
|
title: pageTitle,
|
|
1165
1160
|
description: 'No description available',
|
|
1166
1161
|
tags: tags.length > 0 ? tags : undefined,
|
|
1167
|
-
skipDetailSection: true
|
|
1168
|
-
// Mark as external/single-link entry
|
|
1169
|
-
openGraph: {
|
|
1170
|
-
title: pageTitle,
|
|
1171
|
-
description: 'No description available'
|
|
1172
|
-
}
|
|
1162
|
+
skipDetailSection: true // Mark as external/single-link entry
|
|
1173
1163
|
});
|
|
1174
1164
|
} else if (links.length >= 2) {
|
|
1175
1165
|
// Two-link format: - [Title](#slug) [Tag1] [Tag2] - [Full Docs](./path/page.mdx)
|
|
@@ -1221,11 +1211,7 @@ function _markdownToMetadata() {
|
|
|
1221
1211
|
title: _pageTitle3,
|
|
1222
1212
|
description: 'No description available',
|
|
1223
1213
|
// Will be updated from details section
|
|
1224
|
-
tags: _tags.length > 0 ? _tags : undefined
|
|
1225
|
-
openGraph: {
|
|
1226
|
-
title: _pageTitle3,
|
|
1227
|
-
description: 'No description available' // Will be updated from details section
|
|
1228
|
-
}
|
|
1214
|
+
tags: _tags.length > 0 ? _tags : undefined
|
|
1229
1215
|
});
|
|
1230
1216
|
}
|
|
1231
1217
|
}
|
|
@@ -1329,10 +1315,6 @@ function _markdownToMetadata() {
|
|
|
1329
1315
|
if (_paragraphNode2.children) {
|
|
1330
1316
|
currentPage.descriptionMarkdown = stripPositions(_paragraphNode2.children);
|
|
1331
1317
|
}
|
|
1332
|
-
if (!currentPage.openGraph) {
|
|
1333
|
-
currentPage.openGraph = {};
|
|
1334
|
-
}
|
|
1335
|
-
currentPage.openGraph.description = _paragraphText;
|
|
1336
1318
|
return;
|
|
1337
1319
|
}
|
|
1338
1320
|
}
|
|
@@ -1340,15 +1322,10 @@ function _markdownToMetadata() {
|
|
|
1340
1322
|
// Parse image
|
|
1341
1323
|
if (currentPage && node.type === 'image') {
|
|
1342
1324
|
var imageNode = node;
|
|
1343
|
-
|
|
1344
|
-
currentPage.openGraph = {};
|
|
1345
|
-
}
|
|
1346
|
-
currentPage.openGraph.images = [{
|
|
1325
|
+
currentPage.image = {
|
|
1347
1326
|
url: imageNode.url,
|
|
1348
|
-
width: 800,
|
|
1349
|
-
height: 600,
|
|
1350
1327
|
alt: imageNode.alt || currentPage.title || currentPage.slug || ''
|
|
1351
|
-
}
|
|
1328
|
+
};
|
|
1352
1329
|
return;
|
|
1353
1330
|
}
|
|
1354
1331
|
}
|
|
@@ -1,85 +1,106 @@
|
|
|
1
1
|
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
2
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
3
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
4
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
5
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import { visit } from 'unist-util-visit';
|
|
7
7
|
import { loadCodeVariant } from "../loadCodeVariant/loadCodeVariant.js";
|
|
8
8
|
import { createParseSource } from "../parseSource/index.js";
|
|
9
9
|
import { TypescriptToJavascriptTransformer } from "../transformTypescriptToJavascript/index.js";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Reserved data properties that are handled internally and should not be passed to userProps.
|
|
12
|
+
* These are either processed by the transform pipeline or have special meaning.
|
|
13
13
|
*/
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
};
|
|
14
|
+
var RESERVED_DATA_PROPS = new Set(['dataFilename',
|
|
15
|
+
// Used for fileName
|
|
16
|
+
'dataVariant',
|
|
17
|
+
// Used for variant name
|
|
18
|
+
'dataTransform',
|
|
19
|
+
// Used for skipTransforms
|
|
20
|
+
'dataPrecompute',
|
|
21
|
+
// The precomputed output itself
|
|
22
|
+
'dataContentProps',
|
|
23
|
+
// The serialized user props output
|
|
24
|
+
'dataName',
|
|
25
|
+
// Used for demo name
|
|
26
|
+
'dataSlug' // Used for demo slug/URL
|
|
27
|
+
]);
|
|
45
28
|
|
|
46
29
|
/**
|
|
47
|
-
* Extracts
|
|
30
|
+
* Extracts user-defined data properties from a code element.
|
|
31
|
+
* Filters out reserved properties and returns remaining data-* attributes.
|
|
32
|
+
* Converts from camelCase (dataTitle) to kebab-case keys (title).
|
|
48
33
|
*/
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
function extractUserProps(codeElement) {
|
|
35
|
+
var props = codeElement.properties;
|
|
36
|
+
if (!props) {
|
|
37
|
+
return undefined;
|
|
52
38
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
var userProps = {};
|
|
40
|
+
for (var _i = 0, _Object$entries = Object.entries(props); _i < _Object$entries.length; _i++) {
|
|
41
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
42
|
+
key = _Object$entries$_i[0],
|
|
43
|
+
value = _Object$entries$_i[1];
|
|
44
|
+
// Only process data-* attributes (in camelCase form: dataXxx)
|
|
45
|
+
if (key.startsWith('data') && key.length > 4 && !RESERVED_DATA_PROPS.has(key)) {
|
|
46
|
+
// Convert dataTitle -> title, dataHighlight -> highlight
|
|
47
|
+
var propName = key.charAt(4).toLowerCase() + key.slice(5);
|
|
48
|
+
// Convert value to string
|
|
49
|
+
userProps[propName] = String(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return Object.keys(userProps).length > 0 ? userProps : undefined;
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
/**
|
|
61
|
-
* Gets the filename from data-filename attribute
|
|
62
|
-
* Returns undefined if no explicit filename
|
|
56
|
+
* Gets the filename from data-filename attribute only
|
|
57
|
+
* Returns undefined if no explicit filename is provided
|
|
63
58
|
*/
|
|
64
59
|
function getFileName(codeElement) {
|
|
65
|
-
var _codeElement$properti
|
|
60
|
+
var _codeElement$properti;
|
|
66
61
|
// Check for explicit data-filename attribute
|
|
67
62
|
var dataFilename = (_codeElement$properti = codeElement.properties) == null ? void 0 : _codeElement$properti.dataFilename;
|
|
68
63
|
if (dataFilename && typeof dataFilename === 'string') {
|
|
69
64
|
return dataFilename;
|
|
70
65
|
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
71
68
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Extracts language from a className like "language-typescript" or "language-js"
|
|
71
|
+
* Returns the language portion after "language-" prefix
|
|
72
|
+
*/
|
|
73
|
+
function extractLanguageFromClassName(className) {
|
|
74
|
+
if (!className) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
var classes = Array.isArray(className) ? className : [className];
|
|
78
|
+
var _iterator = _createForOfIteratorHelper(classes),
|
|
79
|
+
_step;
|
|
80
|
+
try {
|
|
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
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
_iterator.e(err);
|
|
89
|
+
} finally {
|
|
90
|
+
_iterator.f();
|
|
77
91
|
}
|
|
78
|
-
|
|
79
|
-
// Return undefined instead of a fallback - let the system handle gracefully
|
|
80
92
|
return undefined;
|
|
81
93
|
}
|
|
82
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Gets the language from class="language-*" attribute
|
|
97
|
+
*/
|
|
98
|
+
function getLanguage(codeElement) {
|
|
99
|
+
var _codeElement$properti2;
|
|
100
|
+
var className = (_codeElement$properti2 = codeElement.properties) == null ? void 0 : _codeElement$properti2.className;
|
|
101
|
+
return extractLanguageFromClassName(className);
|
|
102
|
+
}
|
|
103
|
+
|
|
83
104
|
/**
|
|
84
105
|
* Extracts text content from HAST nodes
|
|
85
106
|
*/
|
|
@@ -106,11 +127,11 @@ function extractCodeFromSemanticStructure(element) {
|
|
|
106
127
|
var figures = element.children.filter(function (child) {
|
|
107
128
|
return child.type === 'element' && child.tagName === 'figure';
|
|
108
129
|
});
|
|
109
|
-
var
|
|
110
|
-
|
|
130
|
+
var _iterator2 = _createForOfIteratorHelper(figures),
|
|
131
|
+
_step2;
|
|
111
132
|
try {
|
|
112
|
-
for (
|
|
113
|
-
var figure =
|
|
133
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
134
|
+
var figure = _step2.value;
|
|
114
135
|
// Extract variant name from figcaption
|
|
115
136
|
var variantName = void 0;
|
|
116
137
|
var figcaption = figure.children.find(function (child) {
|
|
@@ -130,15 +151,16 @@ function extractCodeFromSemanticStructure(element) {
|
|
|
130
151
|
results.push({
|
|
131
152
|
codeElement: extracted.codeElement,
|
|
132
153
|
filename: extracted.filename,
|
|
154
|
+
language: extracted.language,
|
|
133
155
|
variantName: variantName || extracted.variantName
|
|
134
156
|
});
|
|
135
157
|
}
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
160
|
} catch (err) {
|
|
139
|
-
|
|
161
|
+
_iterator2.e(err);
|
|
140
162
|
} finally {
|
|
141
|
-
|
|
163
|
+
_iterator2.f();
|
|
142
164
|
}
|
|
143
165
|
} else if (element.tagName === 'dl') {
|
|
144
166
|
// Handle standalone dl
|
|
@@ -157,11 +179,11 @@ function extractFromDl(dl) {
|
|
|
157
179
|
// Find dt for filename and dd for code
|
|
158
180
|
var filename;
|
|
159
181
|
var codeElement;
|
|
160
|
-
var
|
|
161
|
-
|
|
182
|
+
var _iterator3 = _createForOfIteratorHelper(dl.children),
|
|
183
|
+
_step3;
|
|
162
184
|
try {
|
|
163
|
-
for (
|
|
164
|
-
var child =
|
|
185
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
186
|
+
var child = _step3.value;
|
|
165
187
|
if (child.type === 'element') {
|
|
166
188
|
if (child.tagName === 'dt') {
|
|
167
189
|
// Extract filename from dt > code
|
|
@@ -188,17 +210,20 @@ function extractFromDl(dl) {
|
|
|
188
210
|
}
|
|
189
211
|
}
|
|
190
212
|
} catch (err) {
|
|
191
|
-
|
|
213
|
+
_iterator3.e(err);
|
|
192
214
|
} finally {
|
|
193
|
-
|
|
215
|
+
_iterator3.f();
|
|
194
216
|
}
|
|
195
217
|
if (codeElement) {
|
|
196
218
|
var _codeElement$properti3;
|
|
197
219
|
// Extract variant name from data-variant if available
|
|
198
220
|
var variantName = (_codeElement$properti3 = codeElement.properties) == null ? void 0 : _codeElement$properti3.dataVariant;
|
|
221
|
+
// Extract language from className
|
|
222
|
+
var language = getLanguage(codeElement);
|
|
199
223
|
return {
|
|
200
224
|
codeElement: codeElement,
|
|
201
225
|
filename: filename,
|
|
226
|
+
language: language,
|
|
202
227
|
variantName: variantName
|
|
203
228
|
};
|
|
204
229
|
}
|
|
@@ -238,11 +263,14 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
238
263
|
return child.type === 'element' && child.tagName === 'code';
|
|
239
264
|
});
|
|
240
265
|
if (codeElement) {
|
|
241
|
-
// Extract filename from data-filename
|
|
266
|
+
// Extract filename from data-filename attribute (explicit only)
|
|
242
267
|
var filename = getFileName(codeElement);
|
|
268
|
+
// Extract language from className
|
|
269
|
+
var language = getLanguage(codeElement);
|
|
243
270
|
extractedElements = [{
|
|
244
271
|
codeElement: codeElement,
|
|
245
272
|
filename: filename,
|
|
273
|
+
language: language,
|
|
246
274
|
variantName: undefined // Basic pre > code doesn't have variants
|
|
247
275
|
}];
|
|
248
276
|
}
|
|
@@ -254,7 +282,7 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
254
282
|
}
|
|
255
283
|
if (extractedElements.length > 0) {
|
|
256
284
|
var transformPromise = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
257
|
-
var variants, _codeElement$properti4, _extractedElements$, _codeElement, _filename, sourceCode, variant,
|
|
285
|
+
var _firstCodeElement$pro, _firstCodeElement$pro2, variants, _codeElement$properti4, _extractedElements$, _codeElement, _filename, _language, sourceCode, variant, processedCode, variantPromises, variantResults, _iterator4, _step4, result, userProps, firstCodeElement, _t;
|
|
258
286
|
return _regenerator().w(function (_context2) {
|
|
259
287
|
while (1) switch (_context2.p = _context2.n) {
|
|
260
288
|
case 0:
|
|
@@ -263,19 +291,19 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
263
291
|
variants = {};
|
|
264
292
|
if (extractedElements.length === 1) {
|
|
265
293
|
// Single element - use "Default" as variant name
|
|
266
|
-
_extractedElements$ = extractedElements[0], _codeElement = _extractedElements$.codeElement, _filename = _extractedElements$.filename;
|
|
294
|
+
_extractedElements$ = extractedElements[0], _codeElement = _extractedElements$.codeElement, _filename = _extractedElements$.filename, _language = _extractedElements$.language;
|
|
267
295
|
sourceCode = extractTextContent(_codeElement);
|
|
268
296
|
variant = {
|
|
269
297
|
source: sourceCode,
|
|
270
298
|
skipTransforms: !((_codeElement$properti4 = _codeElement.properties) != null && _codeElement$properti4.dataTransform)
|
|
271
|
-
}; // Add filename if
|
|
299
|
+
}; // Add filename if explicitly provided
|
|
272
300
|
if (_filename) {
|
|
273
301
|
variant.fileName = _filename;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Add language if available (from className)
|
|
305
|
+
if (_language) {
|
|
306
|
+
variant.language = _language;
|
|
279
307
|
}
|
|
280
308
|
variants.Default = variant;
|
|
281
309
|
} else {
|
|
@@ -284,6 +312,7 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
284
312
|
var _codeElement$properti5;
|
|
285
313
|
var codeElement = _ref3.codeElement,
|
|
286
314
|
filename = _ref3.filename,
|
|
315
|
+
language = _ref3.language,
|
|
287
316
|
variantName = _ref3.variantName;
|
|
288
317
|
var sourceCode = extractTextContent(codeElement);
|
|
289
318
|
|
|
@@ -294,14 +323,14 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
294
323
|
skipTransforms: !((_codeElement$properti5 = codeElement.properties) != null && _codeElement$properti5.dataTransform)
|
|
295
324
|
};
|
|
296
325
|
|
|
297
|
-
// Add filename if
|
|
326
|
+
// Add filename if explicitly provided
|
|
298
327
|
if (filename) {
|
|
299
328
|
variant.fileName = filename;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Add language if available (from className)
|
|
332
|
+
if (language) {
|
|
333
|
+
variant.language = language;
|
|
305
334
|
}
|
|
306
335
|
variants[finalVariantName] = variant;
|
|
307
336
|
});
|
|
@@ -353,21 +382,22 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
353
382
|
return Promise.all(variantPromises);
|
|
354
383
|
case 1:
|
|
355
384
|
variantResults = _context2.v;
|
|
356
|
-
|
|
385
|
+
_iterator4 = _createForOfIteratorHelper(variantResults);
|
|
357
386
|
try {
|
|
358
|
-
for (
|
|
359
|
-
result =
|
|
387
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
388
|
+
result = _step4.value;
|
|
360
389
|
if (result) {
|
|
361
390
|
processedCode[result.variantName] = result.processedVariant;
|
|
362
391
|
}
|
|
363
392
|
}
|
|
364
393
|
|
|
365
|
-
//
|
|
394
|
+
// Extract user props from the first code element (they should be the same for all variants)
|
|
366
395
|
} catch (err) {
|
|
367
|
-
|
|
396
|
+
_iterator4.e(err);
|
|
368
397
|
} finally {
|
|
369
|
-
|
|
398
|
+
_iterator4.f();
|
|
370
399
|
}
|
|
400
|
+
userProps = extractUserProps(extractedElements[0].codeElement); // Clear all code element contents
|
|
371
401
|
extractedElements.forEach(function (_ref7) {
|
|
372
402
|
var codeElement = _ref7.codeElement;
|
|
373
403
|
codeElement.children = [];
|
|
@@ -385,6 +415,20 @@ export var transformHtmlCodePrecomputed = function transformHtmlCodePrecomputed(
|
|
|
385
415
|
node.properties = {};
|
|
386
416
|
}
|
|
387
417
|
node.properties.dataPrecompute = JSON.stringify(processedCode);
|
|
418
|
+
|
|
419
|
+
// Pass through name and slug if provided on the code element
|
|
420
|
+
firstCodeElement = extractedElements[0].codeElement;
|
|
421
|
+
if ((_firstCodeElement$pro = firstCodeElement.properties) != null && _firstCodeElement$pro.dataName) {
|
|
422
|
+
node.properties.dataName = firstCodeElement.properties.dataName;
|
|
423
|
+
}
|
|
424
|
+
if ((_firstCodeElement$pro2 = firstCodeElement.properties) != null && _firstCodeElement$pro2.dataSlug) {
|
|
425
|
+
node.properties.dataSlug = firstCodeElement.properties.dataSlug;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Set user props if any exist
|
|
429
|
+
if (userProps) {
|
|
430
|
+
node.properties.dataContentProps = JSON.stringify(userProps);
|
|
431
|
+
}
|
|
388
432
|
_context2.n = 3;
|
|
389
433
|
break;
|
|
390
434
|
case 2:
|