@mui/internal-docs-infra 0.11.1-canary.9 → 0.11.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/ChunkProvider/ChunkContext.d.mts +10 -0
- package/ChunkProvider/ChunkContext.mjs +15 -0
- package/ChunkProvider/ChunkProvider.d.mts +14 -0
- package/ChunkProvider/ChunkProvider.mjs +38 -0
- package/ChunkProvider/PreloadContext.d.mts +14 -0
- package/ChunkProvider/PreloadContext.mjs +18 -0
- package/ChunkProvider/PreloadProvider.d.mts +13 -0
- package/ChunkProvider/PreloadProvider.mjs +33 -0
- package/ChunkProvider/index.d.mts +7 -0
- package/ChunkProvider/index.mjs +7 -0
- package/ChunkProvider/types.d.mts +23 -0
- package/ChunkProvider/types.mjs +1 -0
- package/ChunkProvider/usePreload.d.mts +8 -0
- package/ChunkProvider/usePreload.mjs +21 -0
- package/CodeControllerContext/CodeControllerContext.d.mts +11 -0
- package/CodeControllerContext/CodeControllerContext.mjs +2 -1
- package/CodeHighlighter/CodeHighlighter.d.mts +15 -1
- package/CodeHighlighter/CodeHighlighter.mjs +97 -319
- package/CodeHighlighter/CodeHighlighterChunk.d.mts +42 -0
- package/CodeHighlighter/CodeHighlighterChunk.mjs +77 -0
- package/CodeHighlighter/CodeHighlighterClient.mjs +597 -128
- package/CodeHighlighter/CodeHighlighterContext.d.mts +57 -1
- package/CodeHighlighter/CodeHighlighterFallbackContext.d.mts +14 -2
- package/CodeHighlighter/CodeHighlighterFallbackContext.mjs +1 -3
- package/CodeHighlighter/CodeInitialSourceLoader.d.mts +10 -0
- package/CodeHighlighter/CodeInitialSourceLoader.mjs +108 -0
- package/CodeHighlighter/CodeSourceLoader.d.mts +11 -0
- package/CodeHighlighter/CodeSourceLoader.mjs +128 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.d.mts +47 -0
- package/CodeHighlighter/buildCodeHighlighterChunkProps.mjs +61 -0
- package/CodeHighlighter/buildStringFallback.d.mts +29 -0
- package/CodeHighlighter/buildStringFallback.mjs +42 -0
- package/CodeHighlighter/codeToFallbackProps.d.mts +31 -2
- package/CodeHighlighter/codeToFallbackProps.mjs +347 -42
- package/CodeHighlighter/createClientProps.d.mts +17 -0
- package/CodeHighlighter/createClientProps.mjs +78 -0
- package/CodeHighlighter/errors.d.mts +6 -0
- package/CodeHighlighter/errors.mjs +10 -0
- package/CodeHighlighter/fallbackCompression.d.mts +96 -0
- package/CodeHighlighter/fallbackCompression.mjs +253 -0
- package/CodeHighlighter/fallbackFormat.d.mts +137 -0
- package/CodeHighlighter/fallbackFormat.mjs +422 -0
- package/CodeHighlighter/index.d.mts +4 -1
- package/CodeHighlighter/index.mjs +3 -1
- package/CodeHighlighter/mergeComments.d.mts +38 -0
- package/CodeHighlighter/mergeComments.mjs +80 -0
- package/CodeHighlighter/prepareInitialSource.d.mts +42 -0
- package/CodeHighlighter/prepareInitialSource.mjs +292 -0
- package/CodeHighlighter/resolveFallbackCritical.d.mts +23 -0
- package/CodeHighlighter/resolveFallbackCritical.mjs +44 -0
- package/CodeHighlighter/types.d.mts +272 -8
- package/CodeHighlighter/useCodeFallback.d.mts +94 -0
- package/CodeHighlighter/useCodeFallback.mjs +204 -0
- package/CodeHighlighter/useGrammarsReady.d.mts +18 -0
- package/CodeHighlighter/useGrammarsReady.mjs +45 -0
- package/CodeHighlighter/useSpeculativeCodePreload.d.mts +26 -0
- package/CodeHighlighter/useSpeculativeCodePreload.mjs +40 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.d.mts +33 -0
- package/CodeHighlighter/useSpeculativeEditingPreload.mjs +58 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.d.mts +23 -0
- package/CodeHighlighter/useSpeculativeGrammarPreload.mjs +31 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.d.mts +22 -0
- package/CodeHighlighter/useSpeculativeUseCodePreload.mjs +41 -0
- package/CodeProvider/CodeContext.d.mts +47 -12
- package/CodeProvider/CodeContext.mjs +7 -0
- package/CodeProvider/CodeProvider.d.mts +4 -2
- package/CodeProvider/CodeProvider.mjs +40 -102
- package/CodeProvider/CodeProviderLazy.d.mts +40 -0
- package/CodeProvider/CodeProviderLazy.mjs +96 -0
- package/CodeProvider/constants.d.mts +26 -0
- package/CodeProvider/constants.mjs +24 -0
- package/CodeProvider/createParseSourceWorkerClient.d.mts +6 -0
- package/CodeProvider/createParseSourceWorkerClient.mjs +22 -2
- package/CodeProvider/index.d.mts +2 -1
- package/CodeProvider/index.mjs +9 -1
- package/CodeProvider/parseSourceWorker.mjs +33 -0
- package/CodeProvider/useCodeProviderValue.d.mts +54 -0
- package/CodeProvider/useCodeProviderValue.mjs +188 -0
- package/CoordinatedLazy/ChunkServerLoader.d.mts +25 -0
- package/CoordinatedLazy/ChunkServerLoader.mjs +97 -0
- package/CoordinatedLazy/CoordinatedContentContext.d.mts +15 -0
- package/CoordinatedLazy/CoordinatedContentContext.mjs +22 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.d.mts +11 -0
- package/CoordinatedLazy/CoordinatedFallbackContext.mjs +13 -0
- package/CoordinatedLazy/CoordinatedGateContext.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedGateContext.mjs +19 -0
- package/CoordinatedLazy/CoordinatedLazy.d.mts +14 -0
- package/CoordinatedLazy/CoordinatedLazy.mjs +86 -0
- package/CoordinatedLazy/CoordinatedLazyClient.d.mts +24 -0
- package/CoordinatedLazy/CoordinatedLazyClient.mjs +65 -0
- package/CoordinatedLazy/LazyContent.d.mts +26 -0
- package/CoordinatedLazy/LazyContent.mjs +80 -0
- package/CoordinatedLazy/LazyContentServer.d.mts +18 -0
- package/CoordinatedLazy/LazyContentServer.mjs +25 -0
- package/CoordinatedLazy/buildChunkRenderInputs.d.mts +8 -0
- package/CoordinatedLazy/buildChunkRenderInputs.mjs +35 -0
- package/CoordinatedLazy/createCoordinatedLazy.d.mts +32 -0
- package/CoordinatedLazy/createCoordinatedLazy.mjs +127 -0
- package/CoordinatedLazy/index.d.mts +14 -0
- package/CoordinatedLazy/index.mjs +18 -0
- package/CoordinatedLazy/resolveChunkRender.d.mts +26 -0
- package/CoordinatedLazy/resolveChunkRender.mjs +73 -0
- package/CoordinatedLazy/types.d.mts +408 -0
- package/CoordinatedLazy/types.mjs +1 -0
- package/CoordinatedLazy/useChunk.d.mts +30 -0
- package/CoordinatedLazy/useChunk.mjs +135 -0
- package/CoordinatedLazy/useCoordinatedFallback.d.mts +12 -0
- package/CoordinatedLazy/useCoordinatedFallback.mjs +40 -0
- package/CoordinatedLazy/useCoordinatedSwap.d.mts +16 -0
- package/CoordinatedLazy/useCoordinatedSwap.mjs +124 -0
- package/LICENSE +1 -1
- package/abstractCreateDemo/abstractCreateDemo.d.mts +54 -3
- package/abstractCreateDemo/abstractCreateDemo.mjs +47 -7
- package/abstractCreateDemo/resolveDemoFlag.d.mts +20 -0
- package/abstractCreateDemo/resolveDemoFlag.mjs +25 -0
- package/abstractCreateStream/abstractCreateStream.d.mts +18 -0
- package/abstractCreateStream/abstractCreateStream.mjs +45 -0
- package/abstractCreateStream/index.d.mts +2 -0
- package/abstractCreateStream/index.mjs +1 -0
- package/abstractCreateStream/types.d.mts +34 -0
- package/abstractCreateStream/types.mjs +1 -0
- package/abstractCreateTypes/TypeCode.mjs +12 -11
- package/abstractCreateTypes/typesToJsx.mjs +30 -9
- package/cli/ensureDemoClients.mjs +4 -148
- package/cli/ensureDemoPages.d.mts +45 -0
- package/cli/ensureDemoPages.mjs +99 -0
- package/cli/fileUtils/index.d.mts +11 -0
- package/cli/fileUtils/index.mjs +48 -0
- package/cli/findDemoIndexFiles.d.mts +15 -0
- package/cli/findDemoIndexFiles.mjs +121 -0
- package/cli/index.mjs +1 -1
- package/cli/loadNextConfig.d.mts +25 -0
- package/cli/loadNextConfig.mjs +60 -1
- package/cli/runBrowser.mjs +1 -1
- package/cli/runValidate.mjs +44 -1
- package/package.json +84 -4
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasis.mjs +30 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.d.mts +17 -0
- package/pipeline/enhanceCodeEmphasis/enhanceCodeEmphasisLazy.mjs +52 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.d.mts +18 -0
- package/pipeline/hastUtils/frameFallbackFromSpans.mjs +24 -0
- package/pipeline/hastUtils/hast.d.mts +27 -0
- package/pipeline/hastUtils/hastCompression.d.mts +3 -1
- package/pipeline/hastUtils/hastCompression.mjs +9 -1
- package/pipeline/hastUtils/hastDecompress.mjs +10 -4
- package/pipeline/hastUtils/hastDictionary.mjs +9 -0
- package/pipeline/hastUtils/hastUtils.d.mts +4 -3
- package/pipeline/hastUtils/hastUtils.mjs +24 -12
- package/pipeline/hastUtils/index.d.mts +2 -1
- package/pipeline/hastUtils/index.mjs +2 -1
- package/pipeline/hastUtils/stripHighlightingSpans.d.mts +6 -2
- package/pipeline/hastUtils/stripHighlightingSpans.mjs +22 -10
- package/pipeline/lintJavascriptDemoFocus/lintJavascriptDemoFocus.mjs +10 -7
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.d.mts +31 -13
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransform.mjs +50 -55
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.d.mts +78 -0
- package/pipeline/loadIsomorphicCodeVariant/applyCodeTransformWithComments.mjs +405 -0
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.d.mts +5 -5
- package/pipeline/loadIsomorphicCodeVariant/computeHastDeltas.mjs +36 -66
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.d.mts +23 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeHastSource.mjs +92 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.d.mts +19 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSource.mjs +25 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.d.mts +17 -0
- package/pipeline/loadIsomorphicCodeVariant/decodeSourceToText.mjs +26 -0
- package/pipeline/loadIsomorphicCodeVariant/diffHast.d.mts +26 -2
- package/pipeline/loadIsomorphicCodeVariant/diffHast.mjs +563 -19
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.d.mts +49 -0
- package/pipeline/loadIsomorphicCodeVariant/embedTransforms.mjs +152 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.d.mts +51 -0
- package/pipeline/loadIsomorphicCodeVariant/findExpandingRanges.mjs +161 -0
- package/pipeline/loadIsomorphicCodeVariant/flattenCodeVariant.mjs +6 -3
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.d.mts +12 -0
- package/pipeline/loadIsomorphicCodeVariant/getAvailableTransforms.mjs +44 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.d.mts +16 -0
- package/pipeline/loadIsomorphicCodeVariant/getInitialVisibleSourceLines.mjs +74 -0
- package/pipeline/loadIsomorphicCodeVariant/loadCodeFallback.mjs +17 -5
- package/pipeline/loadIsomorphicCodeVariant/loadIsomorphicCodeVariant.mjs +229 -15
- package/pipeline/loadIsomorphicCodeVariant/transformSource.d.mts +2 -2
- package/pipeline/loadIsomorphicCodeVariant/transformSource.mjs +56 -22
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.mts +18 -0
- package/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.mjs +11 -7
- package/pipeline/loadServerTypes/hastTypeUtils.d.mts +2 -2
- package/pipeline/loadServerTypes/hastTypeUtils.mjs +4 -4
- package/pipeline/loadServerTypes/loadServerTypes.mjs +1 -1
- package/pipeline/loadServerTypesMeta/extractJSDocText.d.mts +14 -0
- package/pipeline/loadServerTypesMeta/extractJSDocText.mjs +60 -0
- package/pipeline/loadServerTypesMeta/processTypes.mjs +43 -46
- package/pipeline/loadServerTypesText/order.mjs +1 -1
- package/pipeline/loadServerTypesText/parseTypesMarkdown.mjs +3 -1
- package/pipeline/loaderUtils/index.d.mts +0 -1
- package/pipeline/loaderUtils/index.mjs +0 -1
- package/pipeline/loaderUtils/parseImportsAndComments.d.mts +5 -1
- package/pipeline/loaderUtils/parseImportsAndComments.mjs +19 -9
- package/pipeline/loaderUtils/resolveModulePath.mjs +23 -1
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.d.mts +12 -0
- package/pipeline/parseCreateFactoryCall/parseCreateFactoryCall.mjs +17 -13
- package/pipeline/parseSource/addLineGutters.mjs +45 -11
- package/pipeline/parseSource/calculateFrameRanges.d.mts +22 -0
- package/pipeline/parseSource/calculateFrameRanges.mjs +69 -25
- package/pipeline/parseSource/detectGrammarScopes.d.mts +13 -0
- package/pipeline/parseSource/detectGrammarScopes.mjs +35 -0
- package/pipeline/parseSource/extendSyntaxTokens.mjs +501 -43
- package/pipeline/parseSource/frameVisibility.d.mts +47 -0
- package/pipeline/parseSource/frameVisibility.mjs +114 -0
- package/pipeline/parseSource/grammarCache.d.mts +33 -0
- package/pipeline/parseSource/grammarCache.mjs +73 -0
- package/pipeline/parseSource/grammarLoaders.d.mts +14 -0
- package/pipeline/parseSource/grammarLoaders.mjs +24 -0
- package/pipeline/parseSource/grammarMaps.d.mts +21 -1
- package/pipeline/parseSource/grammarMaps.mjs +36 -0
- package/pipeline/parseSource/isFrameSpan.d.mts +19 -0
- package/pipeline/parseSource/isFrameSpan.mjs +24 -0
- package/pipeline/parseSource/parseSource.d.mts +41 -6
- package/pipeline/parseSource/parseSource.mjs +184 -36
- package/pipeline/parseSource/redistributeFrameFallbacks.d.mts +40 -0
- package/pipeline/parseSource/redistributeFrameFallbacks.mjs +138 -0
- package/pipeline/parseSource/restructureFrames.d.mts +5 -0
- package/pipeline/parseSource/restructureFrames.mjs +179 -16
- package/pipeline/syncPageIndex/metadataToMarkdown.mjs +6 -2
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.d.mts +26 -0
- package/pipeline/transformHtmlCodeBlock/transformHtmlCodeBlock.mjs +181 -114
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.d.mts +12 -0
- package/pipeline/transformHtmlCodeInline/removeSuffixFromHighlightedNodes.mjs +52 -0
- package/pipeline/transformHtmlCodeInline/transformHtmlCodeInline.mjs +22 -1
- package/pipeline/transformTypescriptToJavascript/removeTypes.d.mts +5 -8
- package/pipeline/transformTypescriptToJavascript/removeTypes.mjs +27 -93
- package/useCode/EditableEngine.d.mts +233 -0
- package/useCode/EditableEngine.mjs +1712 -0
- package/useCode/EditingEngine.d.mts +13 -0
- package/useCode/EditingEngine.mjs +14 -0
- package/useCode/Pre.browser.mjs +5 -1
- package/useCode/Pre.d.mts +127 -1
- package/useCode/Pre.mjs +417 -165
- package/useCode/SourceEditingEngine.d.mts +50 -0
- package/useCode/SourceEditingEngine.mjs +461 -0
- package/useCode/TransformEngine.d.mts +39 -0
- package/useCode/TransformEngine.mjs +208 -0
- package/useCode/editingEngineCache.d.mts +29 -0
- package/useCode/editingEngineCache.mjs +68 -0
- package/useCode/sourceLineCounts.d.mts +80 -0
- package/useCode/sourceLineCounts.mjs +284 -0
- package/useCode/subscribeToggleNudge.d.mts +3 -0
- package/useCode/subscribeToggleNudge.mjs +95 -0
- package/useCode/transformEngineCache.d.mts +21 -0
- package/useCode/transformEngineCache.mjs +60 -0
- package/useCode/useCode.d.mts +140 -1
- package/useCode/useCode.mjs +250 -19
- package/useCode/useCodeUtils.d.mts +131 -20
- package/useCode/useCodeUtils.mjs +267 -194
- package/useCode/useCopyFunctionality.d.mts +13 -1
- package/useCode/useCopyFunctionality.mjs +39 -9
- package/useCode/useEditable.browser.mjs +10 -2
- package/useCode/useEditable.d.mts +27 -106
- package/useCode/useEditable.integration.browser.d.mts +1 -0
- package/useCode/useEditable.integration.browser.mjs +870 -0
- package/useCode/useEditable.mjs +198 -1247
- package/useCode/useEditableUtils.d.mts +50 -1
- package/useCode/useEditableUtils.mjs +29 -0
- package/useCode/useFileNavigation.d.mts +91 -3
- package/useCode/useFileNavigation.mjs +201 -41
- package/useCode/useHighlightGate.d.mts +17 -0
- package/useCode/useHighlightGate.mjs +147 -0
- package/useCode/useSourceEditing.d.mts +8 -0
- package/useCode/useSourceEditing.mjs +158 -314
- package/useCode/useSourceEnhancing.d.mts +5 -1
- package/useCode/useSourceEnhancing.mjs +22 -36
- package/useCode/useTransformManagement.d.mts +93 -5
- package/useCode/useTransformManagement.mjs +496 -28
- package/useCode/useTransitionPhase.d.mts +24 -0
- package/useCode/useTransitionPhase.mjs +49 -0
- package/useCode/useUIState.d.mts +2 -2
- package/useCode/useUIState.mjs +8 -8
- package/useCode/useVariantSelection.d.mts +130 -6
- package/useCode/useVariantSelection.mjs +529 -93
- package/useCodeWindow/useCodeWindow.d.mts +19 -2
- package/useCodeWindow/useCodeWindow.mjs +98 -71
- package/useCoordinated/coordinatePreference.d.mts +439 -0
- package/useCoordinated/coordinatePreference.mjs +951 -0
- package/useCoordinated/coordinatePreference.testUtils.d.mts +21 -0
- package/useCoordinated/coordinatePreference.testUtils.mjs +69 -0
- package/useCoordinated/createSettleGate.d.mts +96 -0
- package/useCoordinated/createSettleGate.mjs +171 -0
- package/useCoordinated/index.d.mts +8 -0
- package/useCoordinated/index.mjs +8 -0
- package/useCoordinated/layoutShiftGate.d.mts +24 -0
- package/useCoordinated/layoutShiftGate.mjs +79 -0
- package/useCoordinated/pageSettleGate.d.mts +11 -0
- package/useCoordinated/pageSettleGate.mjs +13 -0
- package/useCoordinated/scheduleTasks.d.mts +23 -0
- package/useCoordinated/scheduleTasks.mjs +45 -0
- package/useCoordinated/useCoordinated.d.mts +193 -0
- package/useCoordinated/useCoordinated.mjs +469 -0
- package/useCoordinated/useCoordinatedLazy.d.mts +17 -0
- package/useCoordinated/useCoordinatedLazy.mjs +38 -0
- package/useCoordinated/useCoordinatedLocalStorage.d.mts +16 -0
- package/useCoordinated/useCoordinatedLocalStorage.mjs +22 -0
- package/useCoordinated/useCoordinatedPreference.d.mts +20 -0
- package/useCoordinated/useCoordinatedPreference.mjs +26 -0
- package/useCoordinated/useSettleGate.d.mts +11 -0
- package/useCoordinated/useSettleGate.mjs +34 -0
- package/useDemo/exportVariant.d.mts +12 -5
- package/useDemo/exportVariant.mjs +59 -5
- package/useDemo/useDemo.d.mts +5 -2
- package/useScrollAnchor/useScrollAnchor.mjs +28 -5
- package/useStream/index.d.mts +6 -0
- package/useStream/index.mjs +6 -0
- package/useStream/streamChunks.d.mts +23 -0
- package/useStream/streamChunks.mjs +85 -0
- package/useStream/types.d.mts +45 -0
- package/useStream/types.mjs +1 -0
- package/useStream/useStream.d.mts +57 -0
- package/useStream/useStream.mjs +119 -0
- package/useStream/useStreamController.d.mts +15 -0
- package/useStream/useStreamController.mjs +90 -0
- package/withDocsInfra/withDocsInfra.d.mts +19 -0
- package/withDocsInfra/withDocsInfra.mjs +13 -5
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.d.mts +0 -8
- package/pipeline/loaderUtils/convertCommentsToOneIndexed.mjs +0 -16
|
@@ -33,6 +33,16 @@ const RESERVED_DATA_PROPS = new Set(['dataFilename',
|
|
|
33
33
|
* Filters out reserved properties and returns remaining data-* attributes.
|
|
34
34
|
* Converts from camelCase (dataTitle) to kebab-case keys (title).
|
|
35
35
|
*/
|
|
36
|
+
|
|
37
|
+
function parseDataBoolean(value) {
|
|
38
|
+
if (value === true || value === 'true' || value === '') {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (value === false || value === 'false') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
36
46
|
function extractUserProps(codeElement) {
|
|
37
47
|
const props = codeElement.properties;
|
|
38
48
|
if (!props) {
|
|
@@ -44,6 +54,13 @@ function extractUserProps(codeElement) {
|
|
|
44
54
|
if (key.startsWith('data') && key.length > 4 && !RESERVED_DATA_PROPS.has(key)) {
|
|
45
55
|
// Convert dataTitle -> title, dataHighlight -> highlight
|
|
46
56
|
const propName = key.charAt(4).toLowerCase() + key.slice(5);
|
|
57
|
+
if (propName === 'collapseToEmpty' || propName === 'initialExpanded') {
|
|
58
|
+
const parsed = parseDataBoolean(value);
|
|
59
|
+
if (parsed !== undefined) {
|
|
60
|
+
userProps[propName] = parsed;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
47
64
|
// Convert value to string
|
|
48
65
|
userProps[propName] = String(value);
|
|
49
66
|
}
|
|
@@ -112,8 +129,20 @@ function stripJsxExpressionSemicolon(source) {
|
|
|
112
129
|
}
|
|
113
130
|
|
|
114
131
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
132
|
+
* A single code element extracted from a dl pair (dt for the filename, dd for the code).
|
|
133
|
+
* Multiple files may belong to the same variant.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* A variant extracted from the semantic structure. A variant maps to one figure
|
|
138
|
+
* inside a section (multi-variant) or to a single standalone dl/pre (single variant).
|
|
139
|
+
* The first entry in `files` is treated as the variant's main source; any
|
|
140
|
+
* subsequent entries become `extraFiles`.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Extracts variants and their files from semantic HTML structure.
|
|
145
|
+
* Handles both `<section>` (with one or more `<figure>` children) and standalone `<dl>`.
|
|
117
146
|
*/
|
|
118
147
|
function extractCodeFromSemanticStructure(element) {
|
|
119
148
|
const results = [];
|
|
@@ -121,7 +150,7 @@ function extractCodeFromSemanticStructure(element) {
|
|
|
121
150
|
// Handle section with multiple figures
|
|
122
151
|
const figures = element.children.filter(child => child.type === 'element' && child.tagName === 'figure');
|
|
123
152
|
for (const figure of figures) {
|
|
124
|
-
// Extract variant name from figcaption
|
|
153
|
+
// Extract variant name from figcaption (the literal " variant" suffix is stripped)
|
|
125
154
|
let variantName;
|
|
126
155
|
const figcaption = figure.children.find(child => child.type === 'element' && child.tagName === 'figcaption');
|
|
127
156
|
if (figcaption && figcaption.children[0] && figcaption.children[0].type === 'text') {
|
|
@@ -131,67 +160,74 @@ function extractCodeFromSemanticStructure(element) {
|
|
|
131
160
|
// Find dl element in figure
|
|
132
161
|
const dl = figure.children.find(child => child.type === 'element' && child.tagName === 'dl');
|
|
133
162
|
if (dl) {
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
163
|
+
const files = extractFromDl(dl);
|
|
164
|
+
if (files.length > 0) {
|
|
165
|
+
// figcaption takes precedence; data-variant on the first code element is a fallback.
|
|
166
|
+
const firstDataVariant = files[0].codeElement.properties?.dataVariant;
|
|
136
167
|
results.push({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
language: extracted.language,
|
|
140
|
-
variantName: variantName || extracted.variantName
|
|
168
|
+
variantName: variantName || firstDataVariant,
|
|
169
|
+
files
|
|
141
170
|
});
|
|
142
171
|
}
|
|
143
172
|
}
|
|
144
173
|
}
|
|
145
174
|
} else if (element.tagName === 'dl') {
|
|
146
175
|
// Handle standalone dl
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
|
|
176
|
+
const files = extractFromDl(element);
|
|
177
|
+
if (files.length > 0) {
|
|
178
|
+
const firstDataVariant = files[0].codeElement.properties?.dataVariant;
|
|
179
|
+
results.push({
|
|
180
|
+
variantName: firstDataVariant,
|
|
181
|
+
files
|
|
182
|
+
});
|
|
150
183
|
}
|
|
151
184
|
}
|
|
152
185
|
return results;
|
|
153
186
|
}
|
|
154
187
|
|
|
155
188
|
/**
|
|
156
|
-
* Extracts
|
|
189
|
+
* Extracts every dt/dd pair from a `<dl>` element.
|
|
190
|
+
* Pairs are matched positionally: each `<dt>` is bound to the first subsequent
|
|
191
|
+
* `<dd>` containing a `<pre><code>` element. A `<dd>` without a preceding `<dt>`
|
|
192
|
+
* is treated as a file with no explicit filename.
|
|
157
193
|
*/
|
|
158
194
|
function extractFromDl(dl) {
|
|
159
|
-
|
|
160
|
-
let
|
|
161
|
-
let
|
|
195
|
+
const files = [];
|
|
196
|
+
let pendingFilename;
|
|
197
|
+
let hasPendingFilename = false;
|
|
162
198
|
for (const child of dl.children) {
|
|
163
|
-
if (child.type
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
199
|
+
if (child.type !== 'element') {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (child.tagName === 'dt') {
|
|
203
|
+
// Extract filename from dt > code
|
|
204
|
+
const codeInDt = child.children.find(dtChild => dtChild.type === 'element' && dtChild.tagName === 'code');
|
|
205
|
+
if (codeInDt && codeInDt.children[0] && codeInDt.children[0].type === 'text') {
|
|
206
|
+
pendingFilename = codeInDt.children[0].value;
|
|
207
|
+
} else {
|
|
208
|
+
pendingFilename = undefined;
|
|
209
|
+
}
|
|
210
|
+
hasPendingFilename = true;
|
|
211
|
+
} else if (child.tagName === 'dd') {
|
|
212
|
+
// Extract code from dd > pre > code
|
|
213
|
+
const pre = child.children.find(ddChild => ddChild.type === 'element' && ddChild.tagName === 'pre');
|
|
214
|
+
if (!pre) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const codeElement = pre.children.find(preChild => preChild.type === 'element' && preChild.tagName === 'code');
|
|
218
|
+
if (!codeElement) {
|
|
219
|
+
continue;
|
|
179
220
|
}
|
|
221
|
+
files.push({
|
|
222
|
+
codeElement,
|
|
223
|
+
filename: hasPendingFilename ? pendingFilename : undefined,
|
|
224
|
+
language: getLanguage(codeElement)
|
|
225
|
+
});
|
|
226
|
+
pendingFilename = undefined;
|
|
227
|
+
hasPendingFilename = false;
|
|
180
228
|
}
|
|
181
229
|
}
|
|
182
|
-
|
|
183
|
-
// Extract variant name from data-variant if available
|
|
184
|
-
const variantName = codeElement.properties?.dataVariant;
|
|
185
|
-
// Extract language from className
|
|
186
|
-
const language = getLanguage(codeElement);
|
|
187
|
-
return {
|
|
188
|
-
codeElement,
|
|
189
|
-
filename,
|
|
190
|
-
language,
|
|
191
|
-
variantName
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
230
|
+
return files;
|
|
195
231
|
}
|
|
196
232
|
|
|
197
233
|
/**
|
|
@@ -214,10 +250,11 @@ export const transformHtmlCodeBlock = (options = {}) => {
|
|
|
214
250
|
const sourceTransformers = [TypescriptToJavascriptTransformer];
|
|
215
251
|
const sourceEnhancers = [createEnhanceCodeEmphasis({
|
|
216
252
|
paddingFrameMaxSize: options.paddingFrameMaxSize ?? DEFAULT_PADDING_FRAME_MAX_SIZE,
|
|
217
|
-
focusFramesMaxSize: options.focusFramesMaxSize ?? DEFAULT_FOCUS_FRAMES_MAX_SIZE
|
|
253
|
+
focusFramesMaxSize: options.focusFramesMaxSize ?? DEFAULT_FOCUS_FRAMES_MAX_SIZE,
|
|
254
|
+
oversizedFocus: options.oversizedFocus
|
|
218
255
|
})];
|
|
219
256
|
visit(tree, 'element', node => {
|
|
220
|
-
let
|
|
257
|
+
let extractedVariants = [];
|
|
221
258
|
|
|
222
259
|
// Handle basic pre > code structure from standard markdown
|
|
223
260
|
if (node.tagName === 'pre' && node.children && node.children.length > 0 && !node.properties?.dataPrecompute // Don't process if already processed
|
|
@@ -229,37 +266,38 @@ export const transformHtmlCodeBlock = (options = {}) => {
|
|
|
229
266
|
const filename = getFileName(codeElement);
|
|
230
267
|
// Extract language from className
|
|
231
268
|
const language = getLanguage(codeElement);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
269
|
+
extractedVariants = [{
|
|
270
|
+
variantName: undefined,
|
|
271
|
+
// Basic pre > code doesn't have variants
|
|
272
|
+
files: [{
|
|
273
|
+
codeElement,
|
|
274
|
+
filename,
|
|
275
|
+
language
|
|
276
|
+
}]
|
|
237
277
|
}];
|
|
238
278
|
}
|
|
239
279
|
}
|
|
240
280
|
// Look for section elements (multi-variant) or dl elements (single variant)
|
|
241
281
|
else if ((node.tagName === 'section' || node.tagName === 'dl') && node.children && node.children.length > 0) {
|
|
242
|
-
// Extract
|
|
243
|
-
|
|
282
|
+
// Extract variants (each with one or more files) from semantic structure
|
|
283
|
+
extractedVariants = extractCodeFromSemanticStructure(node);
|
|
244
284
|
}
|
|
245
|
-
if (
|
|
285
|
+
if (extractedVariants.length > 0) {
|
|
246
286
|
const transformPromise = (async () => {
|
|
247
287
|
try {
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
let sourceCode = getHastTextContent(codeElement);
|
|
254
|
-
const derivedFilename = filename || getFileName(codeElement);
|
|
288
|
+
// Process a single file (dt/dd pair or bare pre>code) into the fields
|
|
289
|
+
// needed to populate a VariantCode `source` or `extraFiles` entry.
|
|
290
|
+
const processFile = async file => {
|
|
291
|
+
let sourceCode = getHastTextContent(file.codeElement);
|
|
292
|
+
const derivedFilename = file.filename || getFileName(file.codeElement);
|
|
255
293
|
|
|
256
294
|
// Strip trailing semicolon from JSX expressions
|
|
257
|
-
if (language && JSX_LANGUAGES.has(language)) {
|
|
295
|
+
if (file.language && JSX_LANGUAGES.has(file.language)) {
|
|
258
296
|
sourceCode = stripJsxExpressionSemicolon(sourceCode);
|
|
259
297
|
}
|
|
260
298
|
|
|
261
299
|
// Check if displayComments is enabled - if so, don't strip comments
|
|
262
|
-
const displayComments = codeElement.properties?.dataDisplayComments === 'true';
|
|
300
|
+
const displayComments = file.codeElement.properties?.dataDisplayComments === 'true';
|
|
263
301
|
|
|
264
302
|
// Parse the source to extract @highlight comments
|
|
265
303
|
// When displayComments is true, we only collect comments but don't strip them
|
|
@@ -267,58 +305,68 @@ export const transformHtmlCodeBlock = (options = {}) => {
|
|
|
267
305
|
removeCommentsWithPrefix: displayComments ? undefined : [EMPHASIS_COMMENT_PREFIX, FOCUS_COMMENT_PREFIX, ...IGNORE_COMMENT_PREFIXES],
|
|
268
306
|
notableCommentsPrefix: [EMPHASIS_COMMENT_PREFIX, FOCUS_COMMENT_PREFIX]
|
|
269
307
|
});
|
|
308
|
+
return {
|
|
309
|
+
fileName: derivedFilename,
|
|
310
|
+
language: file.language,
|
|
311
|
+
source: parseResult.code ?? sourceCode,
|
|
312
|
+
comments: parseResult.comments,
|
|
313
|
+
skipTransforms: !file.codeElement.properties?.dataTransform
|
|
314
|
+
};
|
|
315
|
+
};
|
|
270
316
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
317
|
+
// Build a VariantCode for each extracted variant. The first file
|
|
318
|
+
// populates `source`/`fileName`/`language`/`comments`; any additional
|
|
319
|
+
// files become `extraFiles` entries on the same variant.
|
|
320
|
+
const buildVariant = async (extracted, index) => {
|
|
321
|
+
const processedFiles = await Promise.all(extracted.files.map(processFile));
|
|
322
|
+
const [mainFile, ...restFiles] = processedFiles;
|
|
275
323
|
const variant = {
|
|
276
|
-
source:
|
|
277
|
-
skipTransforms:
|
|
278
|
-
comments
|
|
324
|
+
source: mainFile.source,
|
|
325
|
+
skipTransforms: mainFile.skipTransforms,
|
|
326
|
+
comments: mainFile.comments
|
|
279
327
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (derivedFilename) {
|
|
283
|
-
variant.fileName = derivedFilename;
|
|
328
|
+
if (mainFile.fileName) {
|
|
329
|
+
variant.fileName = mainFile.fileName;
|
|
284
330
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (language) {
|
|
288
|
-
variant.language = language;
|
|
331
|
+
if (mainFile.language) {
|
|
332
|
+
variant.language = mainFile.language;
|
|
289
333
|
}
|
|
290
|
-
|
|
334
|
+
if (restFiles.length > 0) {
|
|
335
|
+
const extraFiles = {};
|
|
336
|
+
for (const extra of restFiles) {
|
|
337
|
+
// Files without an explicit filename can't be addressed as extra files; skip.
|
|
338
|
+
if (!extra.fileName) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
const entry = {
|
|
342
|
+
source: extra.source,
|
|
343
|
+
skipTransforms: extra.skipTransforms
|
|
344
|
+
};
|
|
345
|
+
if (extra.language) {
|
|
346
|
+
entry.language = extra.language;
|
|
347
|
+
}
|
|
348
|
+
if (extra.comments) {
|
|
349
|
+
entry.comments = extra.comments;
|
|
350
|
+
}
|
|
351
|
+
extraFiles[extra.fileName] = entry;
|
|
352
|
+
}
|
|
353
|
+
if (Object.keys(extraFiles).length > 0) {
|
|
354
|
+
variant.extraFiles = extraFiles;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const variantName = extracted.variantName || (index === 0 ? 'Default' : `Variant ${index + 1}`);
|
|
291
358
|
return {
|
|
292
359
|
variantName,
|
|
293
360
|
variant
|
|
294
361
|
};
|
|
295
362
|
};
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
} = extractedElements[0];
|
|
303
|
-
const {
|
|
304
|
-
variantName,
|
|
305
|
-
variant
|
|
306
|
-
} = await processElementForVariant(codeElement, filename, language, undefined, 0);
|
|
363
|
+
const builtVariants = await Promise.all(extractedVariants.map(buildVariant));
|
|
364
|
+
const variants = {};
|
|
365
|
+
for (const {
|
|
366
|
+
variantName,
|
|
367
|
+
variant
|
|
368
|
+
} of builtVariants) {
|
|
307
369
|
variants[variantName] = variant;
|
|
308
|
-
} else {
|
|
309
|
-
// Multiple elements - use variant names
|
|
310
|
-
const results = await Promise.all(extractedElements.map(({
|
|
311
|
-
codeElement,
|
|
312
|
-
filename,
|
|
313
|
-
language,
|
|
314
|
-
variantName
|
|
315
|
-
}, index) => processElementForVariant(codeElement, filename, language, variantName, index)));
|
|
316
|
-
for (const {
|
|
317
|
-
variantName,
|
|
318
|
-
variant
|
|
319
|
-
} of results) {
|
|
320
|
-
variants[variantName] = variant;
|
|
321
|
-
}
|
|
322
370
|
}
|
|
323
371
|
|
|
324
372
|
// Process each variant with loadIsomorphicCodeVariant
|
|
@@ -354,15 +402,35 @@ export const transformHtmlCodeBlock = (options = {}) => {
|
|
|
354
402
|
}
|
|
355
403
|
}
|
|
356
404
|
|
|
357
|
-
//
|
|
358
|
-
|
|
405
|
+
// The first code element of the first variant carries the
|
|
406
|
+
// top-level metadata (user props, name, slug) for the demo.
|
|
407
|
+
const firstCodeElement = extractedVariants[0].files[0].codeElement;
|
|
359
408
|
|
|
360
|
-
//
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
409
|
+
// Extract user props from the first code element. Per-block render
|
|
410
|
+
// flags (e.g. ` ```ts collapseToEmpty ` / ` ```ts initialExpanded `)
|
|
411
|
+
// arrive as `data-*` attributes and flow through here as content
|
|
412
|
+
// props. When the block sets no flag, fall back to the transform's
|
|
413
|
+
// matching option so it can default every block.
|
|
414
|
+
let userProps = extractUserProps(firstCodeElement);
|
|
415
|
+
if (firstCodeElement.properties?.dataCollapseToEmpty === undefined && options.collapseToEmpty) {
|
|
416
|
+
userProps = {
|
|
417
|
+
...(userProps ?? {}),
|
|
418
|
+
collapseToEmpty: true
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
if (firstCodeElement.properties?.dataInitialExpanded === undefined && options.initialExpanded) {
|
|
422
|
+
userProps = {
|
|
423
|
+
...(userProps ?? {}),
|
|
424
|
+
initialExpanded: true
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Clear all code element contents (across every variant and every file)
|
|
429
|
+
for (const extracted of extractedVariants) {
|
|
430
|
+
for (const file of extracted.files) {
|
|
431
|
+
file.codeElement.children = [];
|
|
432
|
+
}
|
|
433
|
+
}
|
|
366
434
|
|
|
367
435
|
// Replace the semantic structure with a <pre> element
|
|
368
436
|
node.tagName = 'pre';
|
|
@@ -378,7 +446,6 @@ export const transformHtmlCodeBlock = (options = {}) => {
|
|
|
378
446
|
node.properties.dataPrecompute = JSON.stringify(processedCode);
|
|
379
447
|
|
|
380
448
|
// Pass through name and slug if provided on the code element
|
|
381
|
-
const firstCodeElement = extractedElements[0].codeElement;
|
|
382
449
|
if (firstCodeElement.properties?.dataName) {
|
|
383
450
|
node.properties.dataName = firstCodeElement.properties.dataName;
|
|
384
451
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElementContent } from 'hast';
|
|
2
|
+
/**
|
|
3
|
+
* Removes a suffix from the end of highlighted HAST nodes.
|
|
4
|
+
*
|
|
5
|
+
* Mirror of `removePrefixFromHighlightedNodes`: used to strip temporary
|
|
6
|
+
* trailing characters that were appended to the source before highlighting
|
|
7
|
+
* (e.g., closing `)` for object-literal wrapping).
|
|
8
|
+
*
|
|
9
|
+
* @param children - The array of HAST nodes to modify
|
|
10
|
+
* @param suffixLength - The number of characters to remove from the end
|
|
11
|
+
*/
|
|
12
|
+
export declare function removeSuffixFromHighlightedNodes(children: ElementContent[], suffixLength: number): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes a suffix from the end of highlighted HAST nodes.
|
|
3
|
+
*
|
|
4
|
+
* Mirror of `removePrefixFromHighlightedNodes`: used to strip temporary
|
|
5
|
+
* trailing characters that were appended to the source before highlighting
|
|
6
|
+
* (e.g., closing `)` for object-literal wrapping).
|
|
7
|
+
*
|
|
8
|
+
* @param children - The array of HAST nodes to modify
|
|
9
|
+
* @param suffixLength - The number of characters to remove from the end
|
|
10
|
+
*/
|
|
11
|
+
export function removeSuffixFromHighlightedNodes(children, suffixLength) {
|
|
12
|
+
let removedLength = 0;
|
|
13
|
+
while (removedLength < suffixLength && children.length > 0) {
|
|
14
|
+
const lastChild = children[children.length - 1];
|
|
15
|
+
if (lastChild.type === 'text') {
|
|
16
|
+
const textLength = lastChild.value.length;
|
|
17
|
+
if (removedLength + textLength <= suffixLength) {
|
|
18
|
+
children.pop();
|
|
19
|
+
removedLength += textLength;
|
|
20
|
+
} else {
|
|
21
|
+
const charsToRemove = suffixLength - removedLength;
|
|
22
|
+
lastChild.value = lastChild.value.slice(0, textLength - charsToRemove);
|
|
23
|
+
removedLength = suffixLength;
|
|
24
|
+
}
|
|
25
|
+
} else if (lastChild.type === 'element') {
|
|
26
|
+
const element = lastChild;
|
|
27
|
+
if (element.children && element.children.length > 0) {
|
|
28
|
+
const lastElementChild = element.children[element.children.length - 1];
|
|
29
|
+
if (lastElementChild.type === 'text') {
|
|
30
|
+
const textLength = lastElementChild.value.length;
|
|
31
|
+
if (removedLength + textLength <= suffixLength) {
|
|
32
|
+
element.children.pop();
|
|
33
|
+
removedLength += textLength;
|
|
34
|
+
if (element.children.length === 0) {
|
|
35
|
+
children.pop();
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
const charsToRemove = suffixLength - removedLength;
|
|
39
|
+
lastElementChild.value = lastElementChild.value.slice(0, textLength - charsToRemove);
|
|
40
|
+
removedLength = suffixLength;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
children.pop();
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -3,8 +3,10 @@ import { visit } from 'unist-util-visit';
|
|
|
3
3
|
import { grammars } from "../parseSource/grammars.mjs";
|
|
4
4
|
import { extensionMap } from "../parseSource/grammarMaps.mjs";
|
|
5
5
|
import { extendSyntaxTokens } from "../parseSource/extendSyntaxTokens.mjs";
|
|
6
|
+
import { getLanguageCapabilitiesFromScope } from "../parseSource/languageCapabilities.mjs";
|
|
6
7
|
import { getHastTextContent } from "../hastUtils/index.mjs";
|
|
7
8
|
import { removePrefixFromHighlightedNodes } from "./removePrefixFromHighlightedNodes.mjs";
|
|
9
|
+
import { removeSuffixFromHighlightedNodes } from "./removeSuffixFromHighlightedNodes.mjs";
|
|
8
10
|
const STARRY_NIGHT_KEY = '__docs_infra_starry_night_instance__';
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -67,7 +69,14 @@ export default function transformHtmlCodeInline(options = {}) {
|
|
|
67
69
|
const highlightingPrefix = typeof node.properties?.dataHighlightingPrefix === 'string' ? node.properties.dataHighlightingPrefix : undefined;
|
|
68
70
|
|
|
69
71
|
// Temporarily prepend the prefix for proper syntax highlighting
|
|
70
|
-
|
|
72
|
+
let sourceToHighlight = highlightingPrefix ? `${highlightingPrefix}${source}` : source;
|
|
73
|
+
|
|
74
|
+
// Inline JS-family snippets that look like a bare object literal (e.g. `{ height: 400 }`)
|
|
75
|
+
// are tokenized by starry-night as a block statement with labeled statements, which makes
|
|
76
|
+
// the keys appear as `pl-en` (entity name) tokens rather than property names. Wrap them
|
|
77
|
+
// in `(...)` so the snippet parses as an expression and `extendSyntaxTokens` can split
|
|
78
|
+
// out the keys via `splitObjectKeys`. The wrapping characters are stripped after highlighting.
|
|
79
|
+
let objectWrap = false;
|
|
71
80
|
|
|
72
81
|
// Determine language from className (e.g., 'language-ts')
|
|
73
82
|
const className = node.properties?.className;
|
|
@@ -103,6 +112,14 @@ export default function transformHtmlCodeInline(options = {}) {
|
|
|
103
112
|
if (!fileType || !extensionMap[fileType]) {
|
|
104
113
|
return;
|
|
105
114
|
}
|
|
115
|
+
const grammarScope = extensionMap[fileType];
|
|
116
|
+
if (!highlightingPrefix && getLanguageCapabilitiesFromScope(grammarScope).semantics === 'js') {
|
|
117
|
+
const trimmed = sourceToHighlight.trim();
|
|
118
|
+
if (trimmed.length >= 2 && trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
119
|
+
sourceToHighlight = `(${sourceToHighlight})`;
|
|
120
|
+
objectWrap = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
106
123
|
|
|
107
124
|
// Apply syntax highlighting
|
|
108
125
|
const highlighted = starryNight.highlight(sourceToHighlight, extensionMap[fileType]);
|
|
@@ -116,6 +133,10 @@ export default function transformHtmlCodeInline(options = {}) {
|
|
|
116
133
|
if (highlightingPrefix && node.children.length > 0) {
|
|
117
134
|
removePrefixFromHighlightedNodes(node.children, highlightingPrefix.length);
|
|
118
135
|
}
|
|
136
|
+
if (objectWrap && node.children.length > 0) {
|
|
137
|
+
removePrefixFromHighlightedNodes(node.children, 1);
|
|
138
|
+
removeSuffixFromHighlightedNodes(node.children, 1);
|
|
139
|
+
}
|
|
119
140
|
}
|
|
120
141
|
|
|
121
142
|
// Mark this code element as inline highlighted (only for inline code, not pre>code)
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type { Options as PrettierOptions } from 'prettier';
|
|
2
1
|
/**
|
|
3
|
-
* Strips TypeScript types and decorators from code (including
|
|
4
|
-
* preserving
|
|
2
|
+
* Strips TypeScript types and decorators from code (including JSX in TSX),
|
|
3
|
+
* preserving line numbers so source maps and diff tooling stay aligned.
|
|
5
4
|
*
|
|
6
5
|
* @param code - The source code string to transform.
|
|
7
6
|
* @param filename - The name of the file (e.g. "foo.ts" or "Foo.tsx").
|
|
8
|
-
* Determines whether TSX parsing is enabled.
|
|
9
|
-
* @
|
|
10
|
-
* or a Prettier options object to customize.
|
|
11
|
-
* @returns The transformed (and optionally formatted) code.
|
|
7
|
+
* Determines whether TSX/JSX parsing is enabled.
|
|
8
|
+
* @returns The transformed code with TypeScript syntax removed.
|
|
12
9
|
*/
|
|
13
|
-
export declare function removeTypes(code: string, filename?: string
|
|
10
|
+
export declare function removeTypes(code: string, filename?: string): Promise<string>;
|