@docusaurus/theme-common 2.0.0-beta.16 → 2.0.0-beta.19
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/Details.d.ts +14 -0
- package/lib/components/Collapsible/index.d.ts +32 -4
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +18 -10
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +6 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +11 -6
- package/lib/components/Details/index.js.map +1 -1
- package/lib/components/Details/styles.module.css +4 -0
- package/lib/{utils/announcementBarUtils.d.ts → contexts/announcementBar.d.ts} +7 -3
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +15 -14
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/contexts/colorMode.d.ts +27 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +132 -0
- package/lib/contexts/colorMode.js.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/{utils → contexts}/docSidebarItemsExpandedState.js +10 -4
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +31 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +128 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +26 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +30 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
- package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.d.ts → contexts/tabGroupChoice.d.ts} +5 -3
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.js → contexts/tabGroupChoice.js} +15 -20
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/hooks/useBackToTopButton.d.ts +27 -0
- package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
- package/lib/hooks/useBackToTopButton.js +50 -0
- package/lib/hooks/useBackToTopButton.js.map +1 -0
- package/lib/hooks/useCodeWordWrap.d.ts +14 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +41 -0
- package/lib/hooks/useCodeWordWrap.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +7 -3
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +10 -9
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/useKeyboardNavigation.d.ts +11 -1
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -1
- package/lib/hooks/useKeyboardNavigation.js +11 -3
- package/lib/hooks/useKeyboardNavigation.js.map +1 -1
- package/lib/hooks/useLockBodyScroll.d.ts +5 -1
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -1
- package/lib/hooks/useLockBodyScroll.js +5 -1
- package/lib/hooks/useLockBodyScroll.js.map +1 -1
- package/lib/hooks/usePrismTheme.d.ts +6 -2
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +9 -6
- package/lib/hooks/usePrismTheme.js.map +1 -1
- package/lib/hooks/useSearchPage.d.ts +15 -4
- package/lib/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +4 -4
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/hooks/useSkipToContent.d.ts +25 -0
- package/lib/hooks/useSkipToContent.d.ts.map +1 -0
- package/lib/hooks/useSkipToContent.js +35 -0
- package/lib/hooks/useSkipToContent.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/{utils → hooks}/useTOCHighlight.js +18 -16
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +14 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.js +14 -11
- package/lib/hooks/useWindowSize.js.map +1 -1
- package/lib/index.d.ts +31 -32
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +31 -26
- package/lib/index.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +7 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +7 -4
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +57 -4
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +111 -80
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +83 -18
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +143 -62
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +4 -1
- package/lib/utils/generalUtils.d.ts.map +1 -1
- package/lib/utils/generalUtils.js +6 -3
- package/lib/utils/generalUtils.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +1 -7
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +10 -13
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/jsUtils.d.ts +1 -1
- package/lib/utils/jsUtils.js +1 -1
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +61 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +32 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +21 -7
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +34 -6
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +2 -1
- package/lib/utils/regexpUtils.d.ts.map +1 -1
- package/lib/utils/regexpUtils.js +2 -1
- package/lib/utils/regexpUtils.js.map +1 -1
- package/lib/utils/routesUtils.d.ts +19 -4
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js +40 -19
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +55 -25
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +85 -21
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/searchUtils.d.ts +12 -0
- package/lib/utils/searchUtils.d.ts.map +1 -1
- package/lib/utils/searchUtils.js +36 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +12 -9
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +21 -13
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +7 -8
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +8 -6
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +17 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +20 -9
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useAlternatePageUtils.d.ts +20 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +6 -3
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useLocalPathname.d.ts +5 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -1
- package/lib/utils/useLocalPathname.js +6 -4
- package/lib/utils/useLocalPathname.js.map +1 -1
- package/lib/utils/useLocationChange.d.ts +7 -5
- package/lib/utils/useLocationChange.d.ts.map +1 -1
- package/lib/utils/useLocationChange.js +6 -2
- package/lib/utils/useLocationChange.js.map +1 -1
- package/lib/utils/usePluralForm.d.ts +11 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -1
- package/lib/utils/usePluralForm.js +19 -24
- package/lib/utils/usePluralForm.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +28 -22
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js +3 -0
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +18 -11
- package/src/components/Collapsible/index.tsx +42 -24
- package/src/components/Details/index.tsx +15 -8
- package/src/components/Details/styles.module.css +4 -0
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +20 -22
- package/src/contexts/colorMode.tsx +199 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +253 -0
- package/src/contexts/docsSidebar.tsx +50 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +28 -33
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +12 -14
- package/src/hooks/useKeyboardNavigation.ts +11 -3
- package/src/hooks/useLockBodyScroll.ts +5 -2
- package/src/hooks/usePrismTheme.ts +10 -6
- package/src/hooks/useSearchPage.ts +18 -5
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/{utils → hooks}/useTOCHighlight.ts +24 -15
- package/src/hooks/useWindowSize.ts +14 -12
- package/src/index.ts +77 -57
- package/src/utils/ThemeClassNames.ts +10 -6
- package/src/utils/codeBlockUtils.ts +178 -92
- package/src/utils/docsUtils.tsx +205 -101
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +6 -3
- package/src/utils/historyUtils.ts +11 -17
- package/src/utils/jsUtils.ts +1 -1
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +40 -7
- package/src/utils/regexpUtils.ts +2 -1
- package/src/utils/routesUtils.ts +58 -22
- package/src/utils/scrollUtils.tsx +120 -49
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +23 -15
- package/src/utils/tagsUtils.ts +12 -10
- package/src/utils/tocUtils.ts +22 -11
- package/src/utils/useAlternatePageUtils.ts +17 -5
- package/src/utils/useLocalPathname.ts +6 -4
- package/src/utils/useLocationChange.ts +12 -10
- package/src/utils/usePluralForm.ts +27 -24
- package/src/utils/useThemeConfig.ts +23 -22
- package/yarn-error.log +20199 -0
- package/lib/utils/announcementBarUtils.d.ts.map +0 -1
- package/lib/utils/announcementBarUtils.js.map +0 -1
- package/lib/utils/colorModeUtils.d.ts +0 -18
- package/lib/utils/colorModeUtils.d.ts.map +0 -1
- package/lib/utils/colorModeUtils.js +0 -106
- package/lib/utils/colorModeUtils.js.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.d.ts +0 -17
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -22
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -91
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -19
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +0 -1
- package/lib/utils/mobileSecondaryMenu.d.ts +0 -21
- package/lib/utils/mobileSecondaryMenu.d.ts.map +0 -1
- package/lib/utils/mobileSecondaryMenu.js +0 -50
- package/lib/utils/mobileSecondaryMenu.js.map +0 -1
- package/lib/utils/pathUtils.d.ts +0 -8
- package/lib/utils/pathUtils.d.ts.map +0 -1
- package/lib/utils/pathUtils.js +0 -17
- package/lib/utils/pathUtils.js.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.js.map +0 -1
- package/lib/utils/useContextualSearchFilters.d.ts +0 -12
- package/lib/utils/useContextualSearchFilters.d.ts.map +0 -1
- package/lib/utils/useContextualSearchFilters.js +0 -37
- package/lib/utils/useContextualSearchFilters.js.map +0 -1
- package/lib/utils/usePrevious.d.ts +0 -8
- package/lib/utils/usePrevious.d.ts.map +0 -1
- package/lib/utils/usePrevious.js +0 -16
- package/lib/utils/usePrevious.js.map +0 -1
- package/lib/utils/useTOCHighlight.d.ts +0 -14
- package/lib/utils/useTOCHighlight.d.ts.map +0 -1
- package/lib/utils/useTOCHighlight.js.map +0 -1
- package/src/utils/colorModeUtils.tsx +0 -156
- package/src/utils/docSidebarItemsExpandedState.tsx +0 -41
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -167
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
- package/src/utils/mobileSecondaryMenu.tsx +0 -115
- package/src/utils/pathUtils.ts +0 -19
- package/src/utils/useContextualSearchFilters.ts +0 -53
- package/src/utils/usePrevious.ts +0 -19
|
@@ -6,129 +6,160 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import rangeParser from 'parse-numeric-range';
|
|
8
8
|
const codeBlockTitleRegex = /title=(?<quote>["'])(?<title>.*?)\1/;
|
|
9
|
-
const
|
|
10
|
-
const commentTypes = ['js', 'jsBlock', 'jsx', 'python', 'html'];
|
|
9
|
+
const metastringLinesRangeRegex = /\{(?<range>[\d,-]+)\}/;
|
|
11
10
|
// Supported types of highlight comments
|
|
12
11
|
const commentPatterns = {
|
|
13
|
-
js: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
start: '\\/\\*',
|
|
19
|
-
end: '\\*\\/',
|
|
20
|
-
},
|
|
21
|
-
jsx: {
|
|
22
|
-
start: '\\{\\s*\\/\\*',
|
|
23
|
-
end: '\\*\\/\\s*\\}',
|
|
24
|
-
},
|
|
25
|
-
python: {
|
|
26
|
-
start: '#',
|
|
27
|
-
end: '',
|
|
28
|
-
},
|
|
29
|
-
html: {
|
|
30
|
-
start: '<!--',
|
|
31
|
-
end: '-->',
|
|
32
|
-
},
|
|
12
|
+
js: { start: '\\/\\/', end: '' },
|
|
13
|
+
jsBlock: { start: '\\/\\*', end: '\\*\\/' },
|
|
14
|
+
jsx: { start: '\\{\\s*\\/\\*', end: '\\*\\/\\s*\\}' },
|
|
15
|
+
bash: { start: '#', end: '' },
|
|
16
|
+
html: { start: '<!--', end: '-->' },
|
|
33
17
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'highlight-start',
|
|
37
|
-
'highlight-end',
|
|
38
|
-
];
|
|
39
|
-
const getMagicCommentDirectiveRegex = (languages = commentTypes) => {
|
|
40
|
-
// to be more reliable, the opening and closing comment must match
|
|
18
|
+
function getCommentPattern(languages, magicCommentDirectives) {
|
|
19
|
+
// To be more reliable, the opening and closing comment must match
|
|
41
20
|
const commentPattern = languages
|
|
42
21
|
.map((lang) => {
|
|
43
22
|
const { start, end } = commentPatterns[lang];
|
|
44
|
-
return `(?:${start}\\s*(${magicCommentDirectives
|
|
23
|
+
return `(?:${start}\\s*(${magicCommentDirectives
|
|
24
|
+
.flatMap((d) => [d.line, d.block?.start, d.block?.end].filter(Boolean))
|
|
25
|
+
.join('|')})\\s*${end})`;
|
|
45
26
|
})
|
|
46
27
|
.join('|');
|
|
47
|
-
//
|
|
28
|
+
// White space is allowed, but otherwise it should be on it's own line
|
|
48
29
|
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Select comment styles based on language
|
|
33
|
+
*/
|
|
34
|
+
function getAllMagicCommentDirectiveStyles(lang, magicCommentDirectives) {
|
|
52
35
|
switch (lang) {
|
|
53
36
|
case 'js':
|
|
54
37
|
case 'javascript':
|
|
55
38
|
case 'ts':
|
|
56
39
|
case 'typescript':
|
|
57
|
-
return
|
|
40
|
+
return getCommentPattern(['js', 'jsBlock'], magicCommentDirectives);
|
|
58
41
|
case 'jsx':
|
|
59
42
|
case 'tsx':
|
|
60
|
-
return
|
|
43
|
+
return getCommentPattern(['js', 'jsBlock', 'jsx'], magicCommentDirectives);
|
|
61
44
|
case 'html':
|
|
62
|
-
return
|
|
45
|
+
return getCommentPattern(['js', 'jsBlock', 'html'], magicCommentDirectives);
|
|
63
46
|
case 'python':
|
|
64
47
|
case 'py':
|
|
65
|
-
|
|
48
|
+
case 'bash':
|
|
49
|
+
return getCommentPattern(['bash'], magicCommentDirectives);
|
|
50
|
+
case 'markdown':
|
|
51
|
+
case 'md':
|
|
52
|
+
// Text uses HTML, front matter uses bash
|
|
53
|
+
return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives);
|
|
66
54
|
default:
|
|
67
|
-
//
|
|
68
|
-
return
|
|
55
|
+
// All comment types
|
|
56
|
+
return getCommentPattern(Object.keys(commentPatterns), magicCommentDirectives);
|
|
69
57
|
}
|
|
70
|
-
}
|
|
58
|
+
}
|
|
71
59
|
export function parseCodeBlockTitle(metastring) {
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
return metastring?.match(codeBlockTitleRegex)?.groups.title ?? '';
|
|
61
|
+
}
|
|
62
|
+
export function containsLineNumbers(metastring) {
|
|
63
|
+
return metastring?.includes('showLineNumbers') || false;
|
|
74
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the language name from the class name (set by MDX).
|
|
67
|
+
* e.g. `"language-javascript"` => `"javascript"`.
|
|
68
|
+
* Returns undefined if there is no language class name.
|
|
69
|
+
*/
|
|
75
70
|
export function parseLanguage(className) {
|
|
76
71
|
const languageClassName = className
|
|
77
72
|
.split(' ')
|
|
78
73
|
.find((str) => str.startsWith('language-'));
|
|
79
|
-
return languageClassName
|
|
74
|
+
return languageClassName?.replace(/language-/, '');
|
|
80
75
|
}
|
|
81
76
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
77
|
+
* Parses the code content, strips away any magic comments, and returns the
|
|
78
|
+
* clean content and the highlighted lines marked by the comments or metastring.
|
|
79
|
+
*
|
|
80
|
+
* If the metastring contains a range, the `content` will be returned as-is
|
|
81
|
+
* without any parsing. The returned `lineClassNames` will be a map from that
|
|
82
|
+
* number range to the first magic comment config entry (which _should_ be for
|
|
83
|
+
* line highlight directives.)
|
|
84
|
+
*
|
|
85
|
+
* @param content The raw code with magic comments. Trailing newline will be
|
|
86
|
+
* trimmed upfront.
|
|
87
|
+
* @param options Options for parsing behavior.
|
|
84
88
|
*/
|
|
85
|
-
export function parseLines(content,
|
|
89
|
+
export function parseLines(content, options) {
|
|
86
90
|
let code = content.replace(/\n$/, '');
|
|
91
|
+
const { language, magicComments, metastring } = options;
|
|
87
92
|
// Highlighted lines specified in props: don't parse the content
|
|
88
|
-
if (metastring &&
|
|
89
|
-
const
|
|
90
|
-
.
|
|
91
|
-
|
|
93
|
+
if (metastring && metastringLinesRangeRegex.test(metastring)) {
|
|
94
|
+
const linesRange = metastring.match(metastringLinesRangeRegex).groups
|
|
95
|
+
.range;
|
|
96
|
+
if (magicComments.length === 0) {
|
|
97
|
+
throw new Error(`A highlight range has been given in code block's metastring (\`\`\` ${metastring}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`);
|
|
98
|
+
}
|
|
99
|
+
const metastringRangeClassName = magicComments[0].className;
|
|
100
|
+
const lines = rangeParser(linesRange)
|
|
92
101
|
.filter((n) => n > 0)
|
|
93
|
-
.map((n) => n - 1);
|
|
94
|
-
return {
|
|
102
|
+
.map((n) => [n - 1, [metastringRangeClassName]]);
|
|
103
|
+
return { lineClassNames: Object.fromEntries(lines), code };
|
|
95
104
|
}
|
|
96
105
|
if (language === undefined) {
|
|
97
|
-
return {
|
|
106
|
+
return { lineClassNames: {}, code };
|
|
98
107
|
}
|
|
99
|
-
const directiveRegex =
|
|
100
|
-
//
|
|
108
|
+
const directiveRegex = getAllMagicCommentDirectiveStyles(language, magicComments);
|
|
109
|
+
// Go through line by line
|
|
101
110
|
const lines = code.split('\n');
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
const blocks = Object.fromEntries(magicComments.map((d) => [d.className, { start: 0, range: '' }]));
|
|
112
|
+
const lineToClassName = Object.fromEntries(magicComments
|
|
113
|
+
.filter((d) => d.line)
|
|
114
|
+
.map(({ className, line }) => [line, className]));
|
|
115
|
+
const blockStartToClassName = Object.fromEntries(magicComments
|
|
116
|
+
.filter((d) => d.block)
|
|
117
|
+
.map(({ className, block }) => [block.start, className]));
|
|
118
|
+
const blockEndToClassName = Object.fromEntries(magicComments
|
|
119
|
+
.filter((d) => d.block)
|
|
120
|
+
.map(({ className, block }) => [block.end, className]));
|
|
105
121
|
for (let lineNumber = 0; lineNumber < lines.length;) {
|
|
106
122
|
const line = lines[lineNumber];
|
|
107
123
|
const match = line.match(directiveRegex);
|
|
108
|
-
if (match
|
|
109
|
-
|
|
110
|
-
switch (directive) {
|
|
111
|
-
case 'highlight-next-line':
|
|
112
|
-
highlightRange += `${lineNumber},`;
|
|
113
|
-
break;
|
|
114
|
-
case 'highlight-start':
|
|
115
|
-
highlightBlockStart = lineNumber;
|
|
116
|
-
break;
|
|
117
|
-
case 'highlight-end':
|
|
118
|
-
highlightRange += `${highlightBlockStart}-${lineNumber - 1},`;
|
|
119
|
-
break;
|
|
120
|
-
default:
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
lines.splice(lineNumber, 1);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// lines without directives are unchanged
|
|
124
|
+
if (!match) {
|
|
125
|
+
// Lines without directives are unchanged
|
|
127
126
|
lineNumber += 1;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const directive = match.slice(1).find((item) => item !== undefined);
|
|
130
|
+
if (lineToClassName[directive]) {
|
|
131
|
+
blocks[lineToClassName[directive]].range += `${lineNumber},`;
|
|
128
132
|
}
|
|
133
|
+
else if (blockStartToClassName[directive]) {
|
|
134
|
+
blocks[blockStartToClassName[directive]].start = lineNumber;
|
|
135
|
+
}
|
|
136
|
+
else if (blockEndToClassName[directive]) {
|
|
137
|
+
blocks[blockEndToClassName[directive]].range += `${blocks[blockEndToClassName[directive]].start}-${lineNumber - 1},`;
|
|
138
|
+
}
|
|
139
|
+
lines.splice(lineNumber, 1);
|
|
129
140
|
}
|
|
130
|
-
const highlightLines = rangeParser(highlightRange);
|
|
131
141
|
code = lines.join('\n');
|
|
132
|
-
|
|
142
|
+
const lineClassNames = {};
|
|
143
|
+
Object.entries(blocks).forEach(([className, { range }]) => {
|
|
144
|
+
rangeParser(range).forEach((l) => {
|
|
145
|
+
lineClassNames[l] ?? (lineClassNames[l] = []);
|
|
146
|
+
lineClassNames[l].push(className);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
return { lineClassNames, code };
|
|
150
|
+
}
|
|
151
|
+
export function getPrismCssVariables(prismTheme) {
|
|
152
|
+
const mapping = {
|
|
153
|
+
color: '--prism-color',
|
|
154
|
+
backgroundColor: '--prism-background-color',
|
|
155
|
+
};
|
|
156
|
+
const properties = {};
|
|
157
|
+
Object.entries(prismTheme.plain).forEach(([key, value]) => {
|
|
158
|
+
const varName = mapping[key];
|
|
159
|
+
if (varName && typeof value === 'string') {
|
|
160
|
+
properties[varName] = value;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return properties;
|
|
133
164
|
}
|
|
134
165
|
//# sourceMappingURL=codeBlockUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeBlockUtils.js","sourceRoot":"","sources":["../../src/utils/codeBlockUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,WAAW,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{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EAAE,EAAE;YAC/B,cAAc,CAAC,CAAC,MAAhB,cAAc,CAAC,CAAC,IAAM,EAAE,EAAC;YACzB,cAAc,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,EAAC,cAAc,EAAE,IAAI,EAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,UAAsB;IACzD,MAAM,OAAO,GAAgD;QAC3D,KAAK,EAAE,eAAe;QACtB,eAAe,EAAE,0BAA0B;KAC5C,CAAC;IAEF,MAAM,UAAU,GAA4B,EAAE,CAAC;IAC/C,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACxD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,OAAO,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACxC,UAAU,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;SAC7B;IACH,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/lib/utils/docsUtils.d.ts
CHANGED
|
@@ -4,30 +4,95 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
import { type GlobalVersion, type GlobalSidebar, type GlobalDoc } from '@docusaurus/plugin-content-docs/client';
|
|
9
|
+
import type { PropSidebar, PropSidebarItem, PropSidebarItemCategory, PropVersionDoc, PropSidebarBreadcrumbsItem } from '@docusaurus/plugin-content-docs';
|
|
10
|
+
import type { Props as DocPageProps } from '@theme/DocPage';
|
|
9
11
|
export declare const isDocsPluginEnabled: boolean;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
version: PropVersionMetadata | typeof EmptyContextValue;
|
|
14
|
-
}): JSX.Element;
|
|
15
|
-
export declare function useDocsVersion(): PropVersionMetadata;
|
|
12
|
+
/**
|
|
13
|
+
* A null-safe way to access a doc's data by ID in the active version.
|
|
14
|
+
*/
|
|
16
15
|
export declare function useDocById(id: string): PropVersionDoc;
|
|
16
|
+
/**
|
|
17
|
+
* A null-safe way to access a doc's data by ID in the active version.
|
|
18
|
+
*/
|
|
17
19
|
export declare function useDocById(id: string | undefined): PropVersionDoc | undefined;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): JSX.Element;
|
|
22
|
-
export declare function useDocsSidebar(): PropSidebar | null;
|
|
20
|
+
/**
|
|
21
|
+
* Pure function, similar to `Array#find`, but works on the sidebar tree.
|
|
22
|
+
*/
|
|
23
23
|
export declare function findSidebarCategory(sidebar: PropSidebar, predicate: (category: PropSidebarItemCategory) => boolean): PropSidebarItemCategory | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Best effort to assign a link to a sidebar category. If the category doesn't
|
|
26
|
+
* have a link itself, we link to the first sub item with a link.
|
|
27
|
+
*/
|
|
24
28
|
export declare function findFirstCategoryLink(item: PropSidebarItemCategory): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the category associated with the current location. Should only be used
|
|
31
|
+
* on category index pages.
|
|
32
|
+
*/
|
|
25
33
|
export declare function useCurrentSidebarCategory(): PropSidebarItemCategory;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if a sidebar item should be active, based on the active path.
|
|
36
|
+
*/
|
|
26
37
|
export declare function isActiveSidebarItem(item: PropSidebarItem, activePath: string): boolean;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Gets the breadcrumbs of the current doc page, based on its sidebar location.
|
|
40
|
+
* Returns `null` if there's no sidebar or breadcrumbs are disabled.
|
|
41
|
+
*/
|
|
31
42
|
export declare function useSidebarBreadcrumbs(): PropSidebarBreadcrumbsItem[] | null;
|
|
32
|
-
|
|
43
|
+
/**
|
|
44
|
+
* "Version candidates" are mostly useful for the layout components, which must
|
|
45
|
+
* be able to work on all pages. For example, if a user has `{ type: "doc",
|
|
46
|
+
* docId: "intro" }` as a navbar item, which version does that refer to? We
|
|
47
|
+
* believe that it could refer to at most three version candidates:
|
|
48
|
+
*
|
|
49
|
+
* 1. The **active version**, the one that the user is currently browsing. See
|
|
50
|
+
* {@link useActiveDocContext}.
|
|
51
|
+
* 2. The **preferred version**, the one that the user last visited. See
|
|
52
|
+
* {@link useDocsPreferredVersion}.
|
|
53
|
+
* 3. The **latest version**, the "default". See {@link useLatestVersion}.
|
|
54
|
+
*
|
|
55
|
+
* @param docsPluginId The plugin ID to get versions from.
|
|
56
|
+
* @returns An array of 1~3 versions with priorities defined above, guaranteed
|
|
57
|
+
* to be unique and non-sparse. Will be memoized, hence stable for deps array.
|
|
58
|
+
*/
|
|
59
|
+
export declare function useDocsVersionCandidates(docsPluginId?: string): [GlobalVersion, ...GlobalVersion[]];
|
|
60
|
+
/**
|
|
61
|
+
* The layout components, like navbar items, must be able to work on all pages,
|
|
62
|
+
* even on non-doc ones where there's no version context, so a sidebar ID could
|
|
63
|
+
* be ambiguous. This hook would always return a sidebar to be linked to. See
|
|
64
|
+
* also {@link useDocsVersionCandidates} for how this selection is done.
|
|
65
|
+
*
|
|
66
|
+
* @throws This hook throws if a sidebar with said ID is not found.
|
|
67
|
+
*/
|
|
68
|
+
export declare function useLayoutDocsSidebar(sidebarId: string, docsPluginId?: string): GlobalSidebar;
|
|
69
|
+
/**
|
|
70
|
+
* The layout components, like navbar items, must be able to work on all pages,
|
|
71
|
+
* even on non-doc ones where there's no version context, so a doc ID could be
|
|
72
|
+
* ambiguous. This hook would always return a doc to be linked to. See also
|
|
73
|
+
* {@link useDocsVersionCandidates} for how this selection is done.
|
|
74
|
+
*
|
|
75
|
+
* @throws This hook throws if a doc with said ID is not found.
|
|
76
|
+
*/
|
|
77
|
+
export declare function useLayoutDoc(docId: string, docsPluginId?: string): GlobalDoc | null;
|
|
78
|
+
/**
|
|
79
|
+
* The docs plugin creates nested routes, with the top-level route providing the
|
|
80
|
+
* version metadata, and the subroutes creating individual doc pages. This hook
|
|
81
|
+
* will match the current location against all known sub-routes.
|
|
82
|
+
*
|
|
83
|
+
* @param props The props received by `@theme/DocPage`
|
|
84
|
+
* @returns The data of the relevant document at the current location, or `null`
|
|
85
|
+
* if no document associated with the current location can be found.
|
|
86
|
+
*/
|
|
87
|
+
export declare function useDocRouteMetadata({ route, versionMetadata, }: DocPageProps): null | {
|
|
88
|
+
/** The element that should be rendered at the current location. */
|
|
89
|
+
docElement: JSX.Element;
|
|
90
|
+
/**
|
|
91
|
+
* The name of the sidebar associated with the current doc. `sidebarName` and
|
|
92
|
+
* `sidebarItems` correspond to the value of {@link useDocsSidebar}.
|
|
93
|
+
*/
|
|
94
|
+
sidebarName: string | undefined;
|
|
95
|
+
/** The items of the sidebar associated with the current doc. */
|
|
96
|
+
sidebarItems: PropSidebar | undefined;
|
|
97
|
+
};
|
|
33
98
|
//# sourceMappingURL=docsUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/docsUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"docsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/docsUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAGH,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,0BAA0B,EAC3B,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAC,KAAK,IAAI,YAAY,EAAC,MAAM,gBAA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