@astrojs/starlight 0.41.10 → 0.42.0
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/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/MobileMenuToggle.astro +65 -0
- package/{components → dist/components}/PageFrame.astro +32 -8
- package/dist/components-internals/Icons.d.ts +415 -0
- package/dist/components-internals/Icons.js +140 -0
- package/dist/components-internals/SidebarPersistState.d.ts +1 -0
- package/dist/components-internals/SidebarPersistState.js +53 -0
- package/dist/components-internals/TableOfContents/starlight-toc.d.ts +18 -0
- package/dist/components-internals/TableOfContents/starlight-toc.js +88 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/{expressive-code.d.ts → dist/expressive-code.d.ts} +6 -13
- package/dist/expressive-code.js +31 -0
- package/dist/global.d.ts +62 -0
- package/dist/global.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +109 -0
- package/dist/integrations/aside-utils.d.ts +9 -0
- package/dist/integrations/aside-utils.js +35 -0
- package/dist/integrations/expressive-code/hast.d.ts +1 -0
- package/dist/integrations/expressive-code/hast.js +2 -0
- package/dist/integrations/expressive-code/index.d.ts +60 -0
- package/dist/integrations/expressive-code/index.js +48 -0
- package/dist/integrations/expressive-code/preprocessor.d.ts +17 -0
- package/dist/integrations/expressive-code/preprocessor.js +76 -0
- package/dist/integrations/expressive-code/themes/night-owl-dark.js +4 -0
- package/dist/integrations/expressive-code/themes/night-owl-light.js +4 -0
- package/dist/integrations/expressive-code/theming.d.ts +16 -0
- package/dist/integrations/expressive-code/theming.js +71 -0
- package/dist/integrations/expressive-code/translations.d.ts +8 -0
- package/dist/integrations/expressive-code/translations.js +26 -0
- package/dist/integrations/markdown-icon.d.ts +8 -0
- package/dist/integrations/markdown-icon.js +14 -0
- package/dist/integrations/markdown-plugins.d.ts +18 -0
- package/dist/integrations/markdown-plugins.js +36 -0
- package/dist/integrations/markdown-processor.d.ts +29 -0
- package/dist/integrations/markdown-processor.js +44 -0
- package/dist/integrations/pagefind.d.ts +7 -0
- package/dist/integrations/pagefind.js +34 -0
- package/dist/integrations/rehype-code-rtl-support.d.ts +21 -0
- package/dist/integrations/rehype-code-rtl-support.js +36 -0
- package/dist/integrations/rehype-heading-links.d.ts +10 -0
- package/dist/integrations/rehype-heading-links.js +57 -0
- package/dist/integrations/remark-asides.d.ts +32 -0
- package/dist/integrations/remark-asides.js +166 -0
- package/dist/integrations/remark-rehype.d.ts +17 -0
- package/dist/integrations/remark-rehype.js +51 -0
- package/dist/integrations/satteri.d.ts +13 -0
- package/dist/integrations/satteri.js +209 -0
- package/dist/integrations/shared/absolutePathToLang.d.ts +10 -0
- package/dist/integrations/shared/absolutePathToLang.js +13 -0
- package/dist/integrations/shared/localeToLang.d.ts +10 -0
- package/dist/integrations/shared/localeToLang.js +13 -0
- package/dist/integrations/shared/slugToLocale.d.ts +12 -0
- package/dist/integrations/shared/slugToLocale.js +15 -0
- package/dist/integrations/sitemap.d.ts +12 -0
- package/dist/integrations/sitemap.js +19 -0
- package/dist/integrations/vite-layer-order.d.ts +15 -0
- package/dist/integrations/vite-layer-order.js +56 -0
- package/dist/integrations/vite-lazy-barrel-optimization.d.ts +12 -0
- package/dist/integrations/vite-lazy-barrel-optimization.js +33 -0
- package/dist/integrations/vite-virtual-modules.d.ts +14 -0
- package/dist/integrations/vite-virtual-modules.js +108 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +3 -0
- package/dist/loaders.d.ts +20 -0
- package/dist/loaders.js +49 -0
- package/dist/locals.d.ts +15 -0
- package/dist/locals.js +33 -0
- package/dist/package.js +4 -0
- package/{props.ts → dist/props.d.ts} +6 -4
- package/dist/props.js +1 -0
- package/dist/route-data.d.ts +7 -0
- package/dist/route-data.js +6 -0
- package/dist/schema.d.ts +426 -0
- package/dist/schema.js +103 -0
- package/dist/schemas/badge.d.ts +86 -0
- package/dist/schemas/badge.js +39 -0
- package/dist/schemas/components.d.ts +236 -0
- package/dist/schemas/components.js +36 -0
- package/dist/schemas/expressiveCode.d.ts +7 -0
- package/dist/schemas/expressiveCode.js +5 -0
- package/dist/schemas/favicon.d.ts +9 -0
- package/dist/schemas/favicon.js +32 -0
- package/dist/schemas/head.d.ts +33 -0
- package/dist/schemas/head.js +41 -0
- package/dist/schemas/hero.d.ts +319 -0
- package/dist/schemas/hero.js +73 -0
- package/dist/schemas/i18n.d.ts +125 -0
- package/dist/schemas/i18n.js +76 -0
- package/dist/schemas/icon.d.ts +284 -0
- package/dist/schemas/icon.js +7 -0
- package/dist/schemas/locale.d.ts +20 -0
- package/dist/schemas/locale.js +11 -0
- package/dist/schemas/logo.d.ts +32 -0
- package/dist/schemas/logo.js +14 -0
- package/dist/schemas/pagefind.d.ts +166 -0
- package/dist/schemas/pagefind.js +31 -0
- package/dist/schemas/prevNextLink.d.ts +10 -0
- package/dist/schemas/prevNextLink.js +14 -0
- package/dist/schemas/sidebar.d.ts +205 -0
- package/dist/schemas/sidebar.js +71 -0
- package/dist/schemas/site-title.d.ts +7 -0
- package/dist/schemas/site-title.js +17 -0
- package/dist/schemas/social.d.ts +292 -0
- package/dist/schemas/social.js +18 -0
- package/dist/schemas/tableOfContents.d.ts +24 -0
- package/dist/schemas/tableOfContents.js +16 -0
- package/{style → dist/style}/anchor-links.css +13 -1
- package/dist/translations/ar.js +36 -0
- package/dist/translations/ca.js +46 -0
- package/dist/translations/cs.js +46 -0
- package/dist/translations/da.js +33 -0
- package/dist/translations/de.js +33 -0
- package/dist/translations/el.js +33 -0
- package/dist/translations/en.js +33 -0
- package/dist/translations/es.js +46 -0
- package/dist/translations/fa.js +33 -0
- package/dist/translations/fi.js +33 -0
- package/dist/translations/fr.js +36 -0
- package/dist/translations/gl.js +46 -0
- package/dist/translations/he.js +33 -0
- package/dist/translations/hi.js +36 -0
- package/dist/translations/hu.js +46 -0
- package/dist/translations/id.js +33 -0
- package/dist/translations/index.d.ts +48 -0
- package/dist/translations/index.js +75 -0
- package/dist/translations/it.js +36 -0
- package/dist/translations/ja.js +36 -0
- package/dist/translations/ko.js +36 -0
- package/dist/translations/lv.js +33 -0
- package/dist/translations/nb.js +33 -0
- package/dist/translations/nl.js +33 -0
- package/dist/translations/pl.js +36 -0
- package/dist/translations/pt.js +36 -0
- package/dist/translations/ro.js +33 -0
- package/dist/translations/ru.js +36 -0
- package/dist/translations/sk.js +33 -0
- package/dist/translations/sv.js +33 -0
- package/dist/translations/th.js +33 -0
- package/dist/translations/tr.js +33 -0
- package/dist/translations/uk.js +33 -0
- package/dist/translations/vi.js +33 -0
- package/dist/translations/zh-CN.js +36 -0
- package/dist/translations/zh-TW.js +36 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/{user-components → dist/user-components}/FileTree.astro +1 -1
- package/{user-components → dist/user-components}/Steps.astro +1 -1
- package/{user-components → dist/user-components}/TabItem.astro +1 -1
- package/{user-components → dist/user-components}/Tabs.astro +1 -1
- package/dist/user-components/file-tree-icons.d.ts +178 -0
- package/dist/user-components/file-tree-icons.js +632 -0
- package/dist/user-components/file-tree-processor.d.ts +16 -0
- package/dist/user-components/file-tree-processor.js +132 -0
- package/dist/user-components/steps-processor.d.ts +10 -0
- package/dist/user-components/steps-processor.js +39 -0
- package/dist/user-components/tabs-processor.d.ts +23 -0
- package/dist/user-components/tabs-processor.js +70 -0
- package/dist/utils/base.d.ts +7 -0
- package/dist/utils/base.js +15 -0
- package/dist/utils/canonical.d.ts +10 -0
- package/dist/utils/canonical.js +14 -0
- package/dist/utils/collection-fs.d.ts +13 -0
- package/dist/utils/collection-fs.js +19 -0
- package/{utils/collection.ts → dist/utils/collection.d.ts} +9 -20
- package/dist/utils/collection.js +26 -0
- package/dist/utils/createPathFormatter.d.ts +9 -0
- package/dist/utils/createPathFormatter.js +35 -0
- package/dist/utils/createTranslationSystem.d.ts +23 -0
- package/dist/utils/createTranslationSystem.js +84 -0
- package/dist/utils/error-map.d.ts +23 -0
- package/dist/utils/error-map.js +125 -0
- package/dist/utils/format-path.d.ts +4 -0
- package/dist/utils/format-path.js +9 -0
- package/dist/utils/generateToC.d.ts +14 -0
- package/dist/utils/generateToC.js +25 -0
- package/dist/utils/git.d.ts +12 -0
- package/dist/utils/git.js +71 -0
- package/dist/utils/gitInlined.d.ts +6 -0
- package/dist/utils/gitInlined.js +11 -0
- package/dist/utils/head.d.ts +7 -0
- package/dist/utils/head.js +233 -0
- package/dist/utils/i18n.d.ts +50 -0
- package/dist/utils/i18n.js +141 -0
- package/dist/utils/localizedUrl.d.ts +8 -0
- package/dist/utils/localizedUrl.js +28 -0
- package/dist/utils/navigation.d.ts +19 -0
- package/dist/utils/navigation.js +353 -0
- package/dist/utils/path.d.ts +21 -0
- package/dist/utils/path.js +51 -0
- package/dist/utils/plugins.d.ts +721 -0
- package/dist/utils/plugins.js +174 -0
- package/dist/utils/routing/data.d.ts +20 -0
- package/dist/utils/routing/data.js +127 -0
- package/dist/utils/routing/index.d.ts +21 -0
- package/dist/utils/routing/index.js +106 -0
- package/dist/utils/routing/middleware.d.ts +11 -0
- package/dist/utils/routing/middleware.js +65 -0
- package/dist/utils/routing/types.d.ts +93 -0
- package/dist/utils/routing/types.js +1 -0
- package/dist/utils/slugs.d.ts +45 -0
- package/dist/utils/slugs.js +104 -0
- package/dist/utils/starlight-page.d.ts +36 -0
- package/dist/utils/starlight-page.js +120 -0
- package/dist/utils/translations-fs.d.ts +15 -0
- package/dist/utils/translations-fs.js +39 -0
- package/dist/utils/translations.d.ts +20 -0
- package/dist/utils/translations.js +29 -0
- package/dist/utils/types.d.ts +5 -0
- package/dist/utils/types.js +1 -0
- package/dist/utils/url.d.ts +7 -0
- package/{utils/url.ts → dist/utils/url.js} +5 -4
- package/dist/utils/user-config.d.ts +2055 -0
- package/dist/utils/user-config.js +136 -0
- package/dist/utils/validateLogoImports.d.ts +5 -0
- package/dist/utils/validateLogoImports.js +16 -0
- package/dist/utils/zodDeepMerge.d.ts +16 -0
- package/dist/utils/zodDeepMerge.js +53 -0
- package/package.json +62 -33
- package/CHANGELOG.md +0 -3043
- package/components/MobileMenuToggle.astro +0 -114
- package/components-internals/Icons.ts +0 -248
- package/components-internals/SidebarPersistState.ts +0 -71
- package/components-internals/TableOfContents/starlight-toc.ts +0 -127
- package/constants.ts +0 -4
- package/expressive-code.mjs +0 -23
- package/global.d.ts +0 -11
- package/i18n.d.ts +0 -18
- package/index.ts +0 -200
- package/integrations/aside-utils.ts +0 -41
- package/integrations/expressive-code/hast.d.ts +0 -5
- package/integrations/expressive-code/hast.mjs +0 -9
- package/integrations/expressive-code/index.ts +0 -125
- package/integrations/expressive-code/preprocessor.ts +0 -126
- package/integrations/expressive-code/themes/night-owl-dark.jsonc +0 -1796
- package/integrations/expressive-code/themes/night-owl-light.jsonc +0 -1695
- package/integrations/expressive-code/theming.ts +0 -105
- package/integrations/expressive-code/translations.ts +0 -36
- package/integrations/markdown-icon.ts +0 -13
- package/integrations/markdown-plugins.ts +0 -71
- package/integrations/markdown-processor.ts +0 -64
- package/integrations/pagefind.ts +0 -60
- package/integrations/rehype-code-rtl-support.ts +0 -37
- package/integrations/rehype-heading-links.ts +0 -79
- package/integrations/remark-asides.ts +0 -219
- package/integrations/remark-rehype.ts +0 -87
- package/integrations/satteri.ts +0 -265
- package/integrations/shared/absolutePathToLang.ts +0 -26
- package/integrations/shared/localeToLang.ts +0 -15
- package/integrations/shared/slugToLocale.ts +0 -18
- package/integrations/sitemap.ts +0 -23
- package/integrations/vite-layer-order.ts +0 -69
- package/integrations/vite-lazy-barrel-optimization.ts +0 -40
- package/integrations/vite-virtual-modules.ts +0 -175
- package/internal.ts +0 -6
- package/loaders.ts +0 -63
- package/locals.d.ts +0 -43
- package/locals.ts +0 -43
- package/route-data.ts +0 -11
- package/schema.ts +0 -167
- package/schemas/badge.ts +0 -40
- package/schemas/components.ts +0 -265
- package/schemas/expressiveCode.ts +0 -12
- package/schemas/favicon.ts +0 -40
- package/schemas/head.ts +0 -50
- package/schemas/hero.ts +0 -69
- package/schemas/i18n.ts +0 -244
- package/schemas/icon.ts +0 -7
- package/schemas/logo.ts +0 -28
- package/schemas/pagefind.ts +0 -128
- package/schemas/prevNextLink.ts +0 -18
- package/schemas/sidebar.ts +0 -163
- package/schemas/site-title.ts +0 -20
- package/schemas/social.ts +0 -23
- package/schemas/tableOfContents.ts +0 -21
- package/translations/README.md +0 -14
- package/translations/ar.json +0 -33
- package/translations/ca.json +0 -43
- package/translations/cs.json +0 -43
- package/translations/da.json +0 -30
- package/translations/de.json +0 -30
- package/translations/el.json +0 -30
- package/translations/en.json +0 -30
- package/translations/es.json +0 -43
- package/translations/fa.json +0 -30
- package/translations/fi.json +0 -30
- package/translations/fr.json +0 -33
- package/translations/gl.json +0 -43
- package/translations/he.json +0 -30
- package/translations/hi.json +0 -33
- package/translations/hu.json +0 -43
- package/translations/id.json +0 -30
- package/translations/index.ts +0 -76
- package/translations/it.json +0 -33
- package/translations/ja.json +0 -33
- package/translations/ko.json +0 -33
- package/translations/lv.json +0 -30
- package/translations/nb.json +0 -30
- package/translations/nl.json +0 -30
- package/translations/pl.json +0 -33
- package/translations/pt.json +0 -33
- package/translations/ro.json +0 -30
- package/translations/ru.json +0 -33
- package/translations/sk.json +0 -30
- package/translations/sv.json +0 -30
- package/translations/th.json +0 -30
- package/translations/tr.json +0 -30
- package/translations/uk.json +0 -30
- package/translations/vi.json +0 -30
- package/translations/zh-CN.json +0 -33
- package/translations/zh-TW.json +0 -33
- package/types.ts +0 -7
- package/user-components/file-tree-icons.ts +0 -782
- package/user-components/rehype-file-tree.ts +0 -251
- package/user-components/rehype-steps.ts +0 -85
- package/user-components/rehype-tabs.ts +0 -121
- package/utils/base.ts +0 -15
- package/utils/canonical.ts +0 -19
- package/utils/collection-fs.ts +0 -20
- package/utils/createPathFormatter.ts +0 -60
- package/utils/createTranslationSystem.ts +0 -137
- package/utils/error-map.ts +0 -222
- package/utils/format-path.ts +0 -7
- package/utils/generateToC.ts +0 -33
- package/utils/git.ts +0 -121
- package/utils/gitInlined.ts +0 -20
- package/utils/head.ts +0 -235
- package/utils/i18n.ts +0 -221
- package/utils/localizedUrl.ts +0 -51
- package/utils/navigation.ts +0 -566
- package/utils/path.ts +0 -58
- package/utils/plugins.ts +0 -498
- package/utils/routing/data.ts +0 -154
- package/utils/routing/index.ts +0 -135
- package/utils/routing/middleware.ts +0 -81
- package/utils/routing/types.ts +0 -101
- package/utils/slugs.ts +0 -119
- package/utils/starlight-page.ts +0 -205
- package/utils/translations-fs.ts +0 -54
- package/utils/translations.ts +0 -57
- package/utils/types.ts +0 -15
- package/utils/user-config.ts +0 -348
- package/utils/validateLogoImports.ts +0 -21
- package/utils/zodDeepMerge.ts +0 -144
- package/virtual-internal.d.ts +0 -149
- package/virtual.d.ts +0 -27
- /package/{components → dist/components}/AnchorHeading.astro +0 -0
- /package/{components → dist/components}/Banner.astro +0 -0
- /package/{components → dist/components}/ContentNotice.astro +0 -0
- /package/{components → dist/components}/ContentPanel.astro +0 -0
- /package/{components → dist/components}/DraftContentNotice.astro +0 -0
- /package/{components → dist/components}/EditLink.astro +0 -0
- /package/{components → dist/components}/FallbackContentNotice.astro +0 -0
- /package/{components → dist/components}/Footer.astro +0 -0
- /package/{components → dist/components}/Head.astro +0 -0
- /package/{components → dist/components}/Header.astro +0 -0
- /package/{components → dist/components}/Hero.astro +0 -0
- /package/{components → dist/components}/LanguageSelect.astro +0 -0
- /package/{components → dist/components}/LastUpdated.astro +0 -0
- /package/{components → dist/components}/MarkdownContent.astro +0 -0
- /package/{components → dist/components}/MobileMenuFooter.astro +0 -0
- /package/{components → dist/components}/MobileTableOfContents.astro +0 -0
- /package/{components → dist/components}/Page.astro +0 -0
- /package/{components → dist/components}/PageSidebar.astro +0 -0
- /package/{components → dist/components}/PageTitle.astro +0 -0
- /package/{components → dist/components}/Pagination.astro +0 -0
- /package/{components → dist/components}/Search.astro +0 -0
- /package/{components → dist/components}/Select.astro +0 -0
- /package/{components → dist/components}/Sidebar.astro +0 -0
- /package/{components → dist/components}/SidebarPersister.astro +0 -0
- /package/{components → dist/components}/SidebarRestorePoint.astro +0 -0
- /package/{components → dist/components}/SidebarSublist.astro +0 -0
- /package/{components → dist/components}/SiteTitle.astro +0 -0
- /package/{components → dist/components}/SkipLink.astro +0 -0
- /package/{components → dist/components}/SocialIcons.astro +0 -0
- /package/{components → dist/components}/StarlightPage.astro +0 -0
- /package/{components → dist/components}/TableOfContents.astro +0 -0
- /package/{components → dist/components}/ThemeProvider.astro +0 -0
- /package/{components → dist/components}/ThemeSelect.astro +0 -0
- /package/{components → dist/components}/TwoColumnContent.astro +0 -0
- /package/{components-internals → dist/components-internals}/TableOfContents/TableOfContentsList.astro +0 -0
- /package/{components.ts → dist/components.ts} +0 -0
- /package/{routes → dist/routes}/common.astro +0 -0
- /package/{routes → dist/routes}/ssr/404.astro +0 -0
- /package/{routes → dist/routes}/ssr/index.astro +0 -0
- /package/{routes → dist/routes}/static/404.astro +0 -0
- /package/{routes → dist/routes}/static/index.astro +0 -0
- /package/{style → dist/style}/asides.css +0 -0
- /package/{style → dist/style}/layers.css +0 -0
- /package/{style → dist/style}/markdown.css +0 -0
- /package/{style → dist/style}/print.css +0 -0
- /package/{style → dist/style}/props.css +0 -0
- /package/{style → dist/style}/reset.css +0 -0
- /package/{style → dist/style}/util.css +0 -0
- /package/{user-components → dist/user-components}/Aside.astro +0 -0
- /package/{user-components → dist/user-components}/Badge.astro +0 -0
- /package/{user-components → dist/user-components}/Card.astro +0 -0
- /package/{user-components → dist/user-components}/CardGrid.astro +0 -0
- /package/{user-components → dist/user-components}/Icon.astro +0 -0
- /package/{user-components → dist/user-components}/LinkButton.astro +0 -0
- /package/{user-components → dist/user-components}/LinkCard.astro +0 -0
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { ExpressiveCodeTheme, type ThemeObjectOrShikiThemeName } from 'astro-expressive-code';
|
|
2
|
-
import nightOwlDark from './themes/night-owl-dark.jsonc?raw';
|
|
3
|
-
import nightOwlLight from './themes/night-owl-light.jsonc?raw';
|
|
4
|
-
|
|
5
|
-
export type BundledThemeName = 'starlight-dark' | 'starlight-light';
|
|
6
|
-
|
|
7
|
-
export type ThemeObjectOrBundledThemeName = ThemeObjectOrShikiThemeName | BundledThemeName;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Converts the Starlight `themes` config option into a format understood by Expressive Code,
|
|
11
|
-
* loading any bundled themes and using the Starlight defaults if no themes were provided.
|
|
12
|
-
*/
|
|
13
|
-
export function preprocessThemes(
|
|
14
|
-
themes: ThemeObjectOrBundledThemeName[] | undefined
|
|
15
|
-
): ThemeObjectOrShikiThemeName[] {
|
|
16
|
-
// Try to gracefully handle cases where the user forgot to use an array in the config
|
|
17
|
-
themes = themes && !Array.isArray(themes) ? [themes] : themes;
|
|
18
|
-
// If no themes were provided, use our bundled default themes
|
|
19
|
-
if (!themes || !themes.length) themes = ['starlight-dark', 'starlight-light'];
|
|
20
|
-
|
|
21
|
-
return themes.map((theme) => {
|
|
22
|
-
// If the current entry is the name of a bundled theme, load it
|
|
23
|
-
if (theme === 'starlight-dark' || theme === 'starlight-light') {
|
|
24
|
-
const bundledTheme = theme === 'starlight-dark' ? nightOwlDark : nightOwlLight;
|
|
25
|
-
return customizeBundledTheme(ExpressiveCodeTheme.fromJSONString(bundledTheme));
|
|
26
|
-
}
|
|
27
|
-
// Otherwise, just pass it through
|
|
28
|
-
return theme;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Customizes some settings of the bundled theme to make it fit better with Starlight.
|
|
34
|
-
*/
|
|
35
|
-
function customizeBundledTheme(theme: ExpressiveCodeTheme) {
|
|
36
|
-
theme.colors['titleBar.border'] = theme.colors['tab.activeBackground'];
|
|
37
|
-
theme.colors['editorGroupHeader.tabsBorder'] = theme.colors['tab.activeBackground'];
|
|
38
|
-
|
|
39
|
-
// Add underline font style to link syntax highlighting tokens
|
|
40
|
-
// to match the new GitHub theme link style
|
|
41
|
-
theme.settings.forEach((s) => {
|
|
42
|
-
if (s.name?.includes('Link')) s.settings.fontStyle = 'underline';
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return theme;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Modifies the given theme by applying Starlight's CSS variables to the colors of UI elements
|
|
50
|
-
* (backgrounds, buttons, shadows etc.). This ensures that code blocks match the site's theme.
|
|
51
|
-
*/
|
|
52
|
-
export function applyStarlightUiThemeColors(theme: ExpressiveCodeTheme) {
|
|
53
|
-
const isDark = theme.type === 'dark';
|
|
54
|
-
const neutralMinimal = isDark ? '#ffffff17' : '#0000001a';
|
|
55
|
-
const neutralDimmed = isDark ? '#ffffff40' : '#00000055';
|
|
56
|
-
|
|
57
|
-
// Make borders slightly transparent
|
|
58
|
-
const borderColor = 'color-mix(in srgb, var(--sl-color-gray-5), transparent 25%)';
|
|
59
|
-
theme.colors['titleBar.border'] = borderColor;
|
|
60
|
-
theme.colors['editorGroupHeader.tabsBorder'] = borderColor;
|
|
61
|
-
|
|
62
|
-
// Use the same color for terminal title bar background and editor tab bar background
|
|
63
|
-
const backgroundColor = isDark ? 'var(--sl-color-black)' : 'var(--sl-color-gray-6)';
|
|
64
|
-
theme.colors['titleBar.activeBackground'] = backgroundColor;
|
|
65
|
-
theme.colors['editorGroupHeader.tabsBackground'] = backgroundColor;
|
|
66
|
-
|
|
67
|
-
// Use the same color for terminal titles and tab titles
|
|
68
|
-
theme.colors['titleBar.activeForeground'] = 'var(--sl-color-text)';
|
|
69
|
-
theme.colors['tab.activeForeground'] = 'var(--sl-color-text)';
|
|
70
|
-
|
|
71
|
-
// Set tab border colors
|
|
72
|
-
const activeBorderColor = isDark ? 'var(--sl-color-accent-high)' : 'var(--sl-color-accent)';
|
|
73
|
-
theme.colors['tab.activeBorder'] = 'transparent';
|
|
74
|
-
theme.colors['tab.activeBorderTop'] = activeBorderColor;
|
|
75
|
-
|
|
76
|
-
// Use neutral colors for scrollbars
|
|
77
|
-
theme.colors['scrollbarSlider.background'] = neutralMinimal;
|
|
78
|
-
theme.colors['scrollbarSlider.hoverBackground'] = neutralDimmed;
|
|
79
|
-
|
|
80
|
-
// Set theme `bg` color property for contrast calculations
|
|
81
|
-
theme.bg = isDark ? '#23262f' : '#f6f7f9';
|
|
82
|
-
theme.colors['editor.background'] = theme.bg;
|
|
83
|
-
// Set actual background color to the appropriate Starlight CSS variable
|
|
84
|
-
const editorBackgroundColor = isDark ? 'var(--sl-color-gray-6)' : 'var(--sl-color-gray-7)';
|
|
85
|
-
|
|
86
|
-
theme.styleOverrides.frames = {
|
|
87
|
-
// Use the same color for editor background, terminal background and active tab background
|
|
88
|
-
editorBackground: editorBackgroundColor,
|
|
89
|
-
terminalBackground: editorBackgroundColor,
|
|
90
|
-
editorActiveTabBackground: editorBackgroundColor,
|
|
91
|
-
terminalTitlebarDotsForeground: borderColor,
|
|
92
|
-
terminalTitlebarDotsOpacity: '0.75',
|
|
93
|
-
inlineButtonForeground: 'var(--sl-color-text)',
|
|
94
|
-
frameBoxShadowCssValue: 'none',
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// Use neutral, semi-transparent colors for default text markers
|
|
98
|
-
// to avoid conflicts with the user's chosen background color
|
|
99
|
-
theme.styleOverrides.textMarkers = {
|
|
100
|
-
markBackground: neutralMinimal,
|
|
101
|
-
markBorderColor: neutralDimmed,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return theme;
|
|
105
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { pluginFramesTexts } from 'astro-expressive-code';
|
|
2
|
-
import type { StarlightConfig } from '../../types';
|
|
3
|
-
import type { createTranslationSystemFromFs } from '../../utils/translations-fs';
|
|
4
|
-
import { localeToLang } from '../shared/localeToLang';
|
|
5
|
-
|
|
6
|
-
export function addTranslations(config: StarlightConfig, useTranslations: UseTranslations) {
|
|
7
|
-
addTranslationsForLocale(config.defaultLocale.locale, config, useTranslations);
|
|
8
|
-
if (config.isMultilingual) {
|
|
9
|
-
for (const locale in config.locales) {
|
|
10
|
-
if (locale === config.defaultLocale.locale || locale === 'root') continue;
|
|
11
|
-
addTranslationsForLocale(locale, config, useTranslations);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function addTranslationsForLocale(
|
|
17
|
-
locale: string | undefined,
|
|
18
|
-
config: StarlightConfig,
|
|
19
|
-
useTranslations: UseTranslations
|
|
20
|
-
) {
|
|
21
|
-
const lang = localeToLang(config, locale);
|
|
22
|
-
const t = useTranslations(lang);
|
|
23
|
-
const translationKeys = [
|
|
24
|
-
'expressiveCode.copyButtonCopied',
|
|
25
|
-
'expressiveCode.copyButtonTooltip',
|
|
26
|
-
'expressiveCode.terminalWindowFallbackTitle',
|
|
27
|
-
] as const;
|
|
28
|
-
translationKeys.forEach((key) => {
|
|
29
|
-
const translation = t.exists(key) ? t(key) : undefined;
|
|
30
|
-
if (!translation) return;
|
|
31
|
-
const ecId = key.replace(/^expressiveCode\./, '');
|
|
32
|
-
pluginFramesTexts.overrideTexts(lang, { [ecId]: translation });
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type UseTranslations = Awaited<ReturnType<typeof createTranslationSystemFromFs>>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Element, ElementContent } from 'hast';
|
|
2
|
-
import { fromHtml } from 'hast-util-from-html';
|
|
3
|
-
import { Icons } from '../components-internals/Icons';
|
|
4
|
-
|
|
5
|
-
export const headingLinkIconSvgChildrenHtml = Icons['link-alt'];
|
|
6
|
-
export const headingLinkIconChildren = parseIconChildren(headingLinkIconSvgChildrenHtml);
|
|
7
|
-
|
|
8
|
-
/** Parse a Starlight icon SVG fragment as children of an `<svg>` element. */
|
|
9
|
-
export function parseIconChildren(icon: string): ElementContent[] {
|
|
10
|
-
const svg = fromHtml(`<svg>${icon}</svg>`, { fragment: true, space: 'svg' })
|
|
11
|
-
.children[0] as Element;
|
|
12
|
-
return svg.children;
|
|
13
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { isSatteriProcessor } from '@astrojs/markdown-satteri';
|
|
2
|
-
import type { AstroConfig, AstroIntegration, AstroIntegrationLogger } from 'astro';
|
|
3
|
-
import type { MarkdownProcessorPluginOptions } from './markdown-processor';
|
|
4
|
-
import { satteriDirectivesRestoration, starlightSatteriPlugins } from './satteri';
|
|
5
|
-
|
|
6
|
-
// This file is imported by the Starlight integration that is used in Astro configuration files.
|
|
7
|
-
// When using Starlight, Astro loads its configuration using a temporary Vite module runner and
|
|
8
|
-
// closes it before running integration hooks. If this dynamic import is started later from an
|
|
9
|
-
// integration hook, Vite tries to resolve it through that closed runner and throw "Vite module
|
|
10
|
-
// runner has been closed".
|
|
11
|
-
// We start loading `./remark-rehype` at the top level so Vite waits for it to resolve or fail
|
|
12
|
-
// while the config runner is still running. This keeps the Unified integration optional as when
|
|
13
|
-
// `@astrojs/markdown-remark` is not installed, importing `./remark-rehype` rejects and we resolve
|
|
14
|
-
// it to `null`, which is later used to detect if Unified support is available or not.
|
|
15
|
-
export const unifiedIntegration = import('./remark-rehype').catch(() => null);
|
|
16
|
-
|
|
17
|
-
type UnifiedIntegration = Awaited<typeof unifiedIntegration>;
|
|
18
|
-
type MarkdownProcessor = NonNullable<AstroConfig['markdown']['processor']>;
|
|
19
|
-
|
|
20
|
-
/** Registers Starlight's Markdown transforms, picking the plugin set for the configured engine. */
|
|
21
|
-
export function applyStarlightMarkdownPlugins(
|
|
22
|
-
processor: MarkdownProcessor,
|
|
23
|
-
options: MarkdownProcessorPluginOptions,
|
|
24
|
-
unified: UnifiedIntegration,
|
|
25
|
-
logger: Pick<AstroIntegrationLogger, 'warn'>
|
|
26
|
-
) {
|
|
27
|
-
if (isSatteriProcessor(processor)) {
|
|
28
|
-
// Starlight's asides are built on container directives, which Sätteri disables by default.
|
|
29
|
-
processor.options.features.directive = true;
|
|
30
|
-
const { mdastPlugins, hastPlugins } = starlightSatteriPlugins(options);
|
|
31
|
-
processor.options.mdastPlugins.push(...mdastPlugins);
|
|
32
|
-
processor.options.hastPlugins.push(...hastPlugins);
|
|
33
|
-
} else if (unified?.isUnifiedProcessor(processor)) {
|
|
34
|
-
processor.options.remarkPlugins.push(...unified.starlightRemarkPlugins(options));
|
|
35
|
-
processor.options.rehypePlugins.push(...unified.starlightRehypePlugins(options));
|
|
36
|
-
} else {
|
|
37
|
-
logger.warn(
|
|
38
|
-
`The configured \`markdown.processor\` ("${processor.name}") is not supported by Starlight. ` +
|
|
39
|
-
"Starlight's Markdown transforms (asides, heading anchor links, RTL code support) won't run on your content. " +
|
|
40
|
-
'Switch to `satteri()` from `@astrojs/markdown-satteri` or `unified()` from `@astrojs/markdown-remark`.'
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Registers the directive-restoration plugin. */
|
|
46
|
-
export function registerDirectivesRestoration(
|
|
47
|
-
processor: MarkdownProcessor,
|
|
48
|
-
unified: UnifiedIntegration
|
|
49
|
-
) {
|
|
50
|
-
if (isSatteriProcessor(processor)) {
|
|
51
|
-
processor.options.mdastPlugins.push(satteriDirectivesRestoration());
|
|
52
|
-
} else if (unified?.isUnifiedProcessor(processor)) {
|
|
53
|
-
processor.options.remarkPlugins.push(unified.remarkDirectivesRestoration);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Run directive-restoration last so plugins added by Starlight plugins (via their own Astro
|
|
59
|
-
* integrations) get to handle text/leaf directives first.
|
|
60
|
-
*/
|
|
61
|
-
export function starlightDirectivesRestorationIntegration(): AstroIntegration {
|
|
62
|
-
return {
|
|
63
|
-
name: 'starlight-directives-restoration',
|
|
64
|
-
hooks: {
|
|
65
|
-
'astro:config:setup': async ({ config }) => {
|
|
66
|
-
const unified = await unifiedIntegration;
|
|
67
|
-
registerDirectivesRestoration(config.markdown?.processor, unified);
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import type { AstroConfig } from 'astro';
|
|
4
|
-
import { resolveCollectionPath } from '../utils/collection-fs';
|
|
5
|
-
import { ensureTrailingSlash } from '../utils/path';
|
|
6
|
-
import type { HookParameters, StarlightConfig } from '../types';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Options shared by the plugin factories of both Markdown processors Starlight supports (the unified
|
|
10
|
-
* `remark`/`rehype` pipeline and Sätteri).
|
|
11
|
-
*/
|
|
12
|
-
export interface MarkdownProcessorPluginOptions {
|
|
13
|
-
starlightConfig: Pick<StarlightConfig, 'defaultLocale' | 'locales' | 'markdown'>;
|
|
14
|
-
astroConfig: Pick<AstroConfig, 'root' | 'srcDir'>;
|
|
15
|
-
useTranslations: HookParameters<'config:setup'>['useTranslations'];
|
|
16
|
-
absolutePathToLang: HookParameters<'config:setup'>['absolutePathToLang'];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the paths to the Starlight docs collection and any additional paths defined in the
|
|
21
|
-
* `starlightConfig.markdown.processedDirs` option that can be used with the {@link shouldTransformPath}
|
|
22
|
-
* utility to determine if a file should be transformed by a plugin or not.
|
|
23
|
-
*/
|
|
24
|
-
export function getMarkdownProcessorPaths(options: MarkdownProcessorPluginOptions): string[] {
|
|
25
|
-
const paths = [normalizeDirectoryPath(resolveCollectionPath('docs', options.astroConfig.srcDir))];
|
|
26
|
-
|
|
27
|
-
for (const processedDir of options.starlightConfig.markdown.processedDirs) {
|
|
28
|
-
paths.push(
|
|
29
|
-
normalizeDirectoryPath(resolve(fileURLToPath(options.astroConfig.root), processedDir))
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return paths;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Determines if a file should be transformed by a Markdown plugin, e.g. files without a known path
|
|
38
|
-
* or files that are not part of the allowed paths are skipped. Accepts a path string (as the unified
|
|
39
|
-
* pipeline exposes via `VFile`) or a `URL` (as Sätteri exposes via `ctx.fileURL`).
|
|
40
|
-
*/
|
|
41
|
-
export function shouldTransformPath(path: string | URL | undefined, allowedPaths: string[]) {
|
|
42
|
-
if (!path) return false;
|
|
43
|
-
const normalizedPath = normalizePath(path instanceof URL ? fileURLToPath(path) : path);
|
|
44
|
-
return allowedPaths.some((p) => normalizedPath.startsWith(p));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* File path separators seems to be inconsistent on Windows between remark/rehype plugins used on
|
|
49
|
-
* Markdown vs MDX files.
|
|
50
|
-
* For the time being, we normalize all paths to unix style paths.
|
|
51
|
-
*/
|
|
52
|
-
const backSlashRegex = /\\/g;
|
|
53
|
-
function normalizePath(path: string) {
|
|
54
|
-
return path.replace(backSlashRegex, '/');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Allowed paths are directory prefixes compared with `startsWith()` in {@link shouldTransformPath},
|
|
59
|
-
* so we ensure they have a trailing slash to avoid matching sibling directories with the same
|
|
60
|
-
* prefix.
|
|
61
|
-
*/
|
|
62
|
-
function normalizeDirectoryPath(path: string) {
|
|
63
|
-
return ensureTrailingSlash(normalizePath(path));
|
|
64
|
-
}
|
package/integrations/pagefind.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { HookParameters } from 'astro';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import * as pagefind from 'pagefind';
|
|
4
|
-
|
|
5
|
-
/** Run Pagefind to generate search index files based on the build output directory. */
|
|
6
|
-
export async function starlightPagefind({
|
|
7
|
-
dir,
|
|
8
|
-
logger: starlightLogger,
|
|
9
|
-
}: PagefindIntegrationOptions) {
|
|
10
|
-
const logger = starlightLogger.fork('starlight:pagefind');
|
|
11
|
-
const options = { dir, logger };
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const now = performance.now();
|
|
15
|
-
logger.info('Building search index with Pagefind...');
|
|
16
|
-
|
|
17
|
-
const newIndexResponse = await pagefind.createIndex();
|
|
18
|
-
|
|
19
|
-
const { index } = assertPagefindResponse<pagefind.NewIndexResponse>(newIndexResponse, options);
|
|
20
|
-
|
|
21
|
-
const indexingResponse = await index.addDirectory({ path: fileURLToPath(dir) });
|
|
22
|
-
const { page_count } = assertPagefindResponse<pagefind.IndexingResponse>(
|
|
23
|
-
indexingResponse,
|
|
24
|
-
options
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
logger.info(`Found ${page_count} HTML files.`);
|
|
28
|
-
|
|
29
|
-
const writeFilesResponse = await index.writeFiles({
|
|
30
|
-
outputPath: fileURLToPath(new URL('./pagefind/', dir)),
|
|
31
|
-
});
|
|
32
|
-
assertPagefindResponse<pagefind.WriteFilesResponse>(writeFilesResponse, options);
|
|
33
|
-
|
|
34
|
-
const pagefindTime = performance.now() - now;
|
|
35
|
-
logger.info(
|
|
36
|
-
`Finished building search index in ${pagefindTime < 750 ? `${Math.round(pagefindTime)}ms` : `${(pagefindTime / 1000).toFixed(2)}s`}.`
|
|
37
|
-
);
|
|
38
|
-
} catch (cause) {
|
|
39
|
-
throw new Error('Failed to run Pagefind.', { cause });
|
|
40
|
-
} finally {
|
|
41
|
-
await pagefind.close();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function assertPagefindResponse<T extends PagefindBaseResponse>(
|
|
46
|
-
response: T,
|
|
47
|
-
{ logger }: PagefindIntegrationOptions
|
|
48
|
-
) {
|
|
49
|
-
if (response.errors.length > 0) {
|
|
50
|
-
for (const error of response.errors) logger.error(`Pagefind error: ${error}`);
|
|
51
|
-
throw new Error('Pagefind response contained errors.');
|
|
52
|
-
}
|
|
53
|
-
return response as Required<T>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface PagefindBaseResponse {
|
|
57
|
-
errors: string[];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
type PagefindIntegrationOptions = Pick<HookParameters<'astro:build:done'>, 'dir' | 'logger'>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Root } from 'hast';
|
|
2
|
-
import { CONTINUE, SKIP, visit } from 'unist-util-visit';
|
|
3
|
-
import type { Transformer } from 'unified';
|
|
4
|
-
import type { MarkdownProcessorPluginOptions } from './markdown-processor';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* rehype plugin that adds `dir` attributes to `<code>` and `<pre>`
|
|
8
|
-
* elements that don’t already have them.
|
|
9
|
-
*
|
|
10
|
-
* `<code>` will become `<code dir="auto">`
|
|
11
|
-
* `<pre>` will become `<pre dir="ltr">`
|
|
12
|
-
*
|
|
13
|
-
* `<code>` _inside_ `<pre>` is skipped, so respects the `ltr` on its parent.
|
|
14
|
-
*
|
|
15
|
-
* Reasoning:
|
|
16
|
-
* - `<pre>` is usually a code block and code should be LTR even in an RTL document
|
|
17
|
-
* - `<code>` is often LTR, but could also be RTL. `dir="auto"` ensures the bidirectional
|
|
18
|
-
* algorithm treats the contents of `<code>` in isolation and gives its best guess.
|
|
19
|
-
*/
|
|
20
|
-
export function rehypeRtlCodeSupport(_options: MarkdownProcessorPluginOptions) {
|
|
21
|
-
const transformer: Transformer<Root> = (tree) => {
|
|
22
|
-
visit(tree, 'element', (el) => {
|
|
23
|
-
if (el.tagName === 'pre' || el.tagName === 'code') {
|
|
24
|
-
el.properties ||= {};
|
|
25
|
-
if (!('dir' in el.properties)) {
|
|
26
|
-
el.properties.dir = { pre: 'ltr', code: 'auto' }[el.tagName];
|
|
27
|
-
}
|
|
28
|
-
return SKIP;
|
|
29
|
-
}
|
|
30
|
-
return CONTINUE;
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return function attacher() {
|
|
35
|
-
return transformer;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { Nodes, Root } from 'hast';
|
|
2
|
-
import { toString } from 'hast-util-to-string';
|
|
3
|
-
import { h, s } from 'hastscript';
|
|
4
|
-
import type { Transformer } from 'unified';
|
|
5
|
-
import { SKIP, visit } from 'unist-util-visit';
|
|
6
|
-
import { headingLinkIconChildren } from './markdown-icon';
|
|
7
|
-
import type { MarkdownProcessorPluginOptions } from './markdown-processor';
|
|
8
|
-
|
|
9
|
-
const AnchorLinkIcon = h(
|
|
10
|
-
'span',
|
|
11
|
-
{ ariaHidden: 'true', class: 'sl-anchor-icon' },
|
|
12
|
-
s(
|
|
13
|
-
'svg',
|
|
14
|
-
{ width: 16, height: 16, viewBox: '0 0 24 24', fill: 'currentColor' },
|
|
15
|
-
headingLinkIconChildren
|
|
16
|
-
)
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Add anchor links to headings.
|
|
21
|
-
*/
|
|
22
|
-
export default function rehypeAutolinkHeadings({
|
|
23
|
-
absolutePathToLang,
|
|
24
|
-
useTranslations,
|
|
25
|
-
}: MarkdownProcessorPluginOptions) {
|
|
26
|
-
const transformer: Transformer<Root> = (tree, file) => {
|
|
27
|
-
const pageLang = absolutePathToLang(file.path);
|
|
28
|
-
const t = useTranslations(pageLang);
|
|
29
|
-
|
|
30
|
-
visit(tree, 'element', function (node, index, parent) {
|
|
31
|
-
if (!headingRank(node) || !node.properties.id || typeof index !== 'number' || !parent) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const accessibleLabel = t('heading.anchorLabel', {
|
|
36
|
-
title: toString(node),
|
|
37
|
-
interpolation: { escapeValue: false },
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Wrap the heading in a div and append the anchor link.
|
|
41
|
-
parent.children[index] = h(
|
|
42
|
-
'div',
|
|
43
|
-
{ class: `sl-heading-wrapper level-${node.tagName}` },
|
|
44
|
-
// Heading
|
|
45
|
-
node,
|
|
46
|
-
// Anchor link
|
|
47
|
-
{
|
|
48
|
-
type: 'element',
|
|
49
|
-
tagName: 'a',
|
|
50
|
-
properties: { class: 'sl-anchor-link', href: '#' + String(node.properties.id) },
|
|
51
|
-
children: [
|
|
52
|
-
AnchorLinkIcon,
|
|
53
|
-
h('span', { class: 'sr-only', 'data-pagefind-ignore': true }, accessibleLabel),
|
|
54
|
-
],
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return SKIP;
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
return function attacher() {
|
|
63
|
-
return transformer;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// This utility is inlined from https://github.com/syntax-tree/hast-util-heading-rank
|
|
68
|
-
// Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
|
69
|
-
// MIT License: https://github.com/syntax-tree/hast-util-heading-rank/blob/main/license
|
|
70
|
-
/**
|
|
71
|
-
* Get the rank (`1` to `6`) of headings (`h1` to `h6`).
|
|
72
|
-
* @param node Node to check.
|
|
73
|
-
* @returns Rank of the heading or `undefined` if not a heading.
|
|
74
|
-
*/
|
|
75
|
-
function headingRank(node: Nodes): number | undefined {
|
|
76
|
-
const name = node.type === 'element' ? node.tagName.toLowerCase() : '';
|
|
77
|
-
const code = name.length === 2 && name.charCodeAt(0) === 104 /* `h` */ ? name.charCodeAt(1) : 0;
|
|
78
|
-
return code > 48 /* `0` */ && code < 55 /* `7` */ ? code - 48 /* `0` */ : undefined;
|
|
79
|
-
}
|