@wrikka/create-docs 0.1.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/README.md +137 -0
- package/bin/cli.js +408 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +475 -0
- package/dist/index.d.ts +475 -0
- package/dist/index.js +20 -0
- package/docs/_dir.yml +2 -0
- package/docs/config.md +75 -0
- package/docs/data-sources.md +88 -0
- package/docs/deploy.md +38 -0
- package/docs/features.md +51 -0
- package/docs/getting-started.md +42 -0
- package/docs/index.md +34 -0
- package/docs/markdown.md +154 -0
- package/docs/theming.md +53 -0
- package/package.json +142 -0
- package/scripts/generate-docs-index.ts +111 -0
- package/scripts/github-pull.ts +124 -0
- package/src/adapters/config/index.ts +1 -0
- package/src/adapters/config/node-config-loader.ts +36 -0
- package/src/adapters/fs/fs-docs-loader.ts +31 -0
- package/src/adapters/fs/index.ts +12 -0
- package/src/adapters/fs/memory-fs.ts +60 -0
- package/src/adapters/fs/node-fs.ts +116 -0
- package/src/adapters/git/index.ts +164 -0
- package/src/adapters/github/github-pull.ts +340 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/velite.ts +112 -0
- package/src/adapters/vite/docs-watcher.ts +36 -0
- package/src/adapters/vite/index.ts +2 -0
- package/src/adapters/vite/polling-watcher.ts +89 -0
- package/src/code-block-enhancements/index.ts +3 -0
- package/src/config/index.ts +15 -0
- package/src/content/index.ts +11 -0
- package/src/content-validation/index.ts +5 -0
- package/src/index.ts +174 -0
- package/src/live-editor/index.ts +7 -0
- package/src/modules/analytics/application/plausible-adapter.ts +103 -0
- package/src/modules/analytics/application/umami-adapter.ts +109 -0
- package/src/modules/analytics/domain/events/index.ts +37 -0
- package/src/modules/analytics/domain/models/index.ts +35 -0
- package/src/modules/analytics/domain/operations/analytics-operations.ts +67 -0
- package/src/modules/analytics/domain/validators/index.ts +50 -0
- package/src/modules/analytics/index.ts +9 -0
- package/src/modules/analytics/ports/analytics-port.ts +17 -0
- package/src/modules/analytics/types/analytics.ts +16 -0
- package/src/modules/api-docs/application/type-docs-adapter.ts +34 -0
- package/src/modules/api-docs/domain/events/index.ts +42 -0
- package/src/modules/api-docs/domain/models/index.ts +40 -0
- package/src/modules/api-docs/domain/operations/api-docs-operations.ts +59 -0
- package/src/modules/api-docs/domain/validators/index.ts +56 -0
- package/src/modules/api-docs/index.ts +8 -0
- package/src/modules/api-docs/ports/api-docs-port.ts +21 -0
- package/src/modules/api-docs/types/api-docs.ts +15 -0
- package/src/modules/api-reference/openapi.ts +166 -0
- package/src/modules/api-reference/orpc.ts +94 -0
- package/src/modules/code-block-enhancements/application/usecases/index.ts +39 -0
- package/src/modules/code-block-enhancements/domain/code-operations.ts +72 -0
- package/src/modules/code-block-enhancements/domain/events/index.ts +58 -0
- package/src/modules/code-block-enhancements/domain/index.ts +11 -0
- package/src/modules/code-block-enhancements/domain/models/index.ts +36 -0
- package/src/modules/code-block-enhancements/domain/validators/index.ts +50 -0
- package/src/modules/code-block-enhancements/index.ts +10 -0
- package/src/modules/code-block-enhancements/ports/index.ts +18 -0
- package/src/modules/code-block-enhancements/types/index.ts +37 -0
- package/src/modules/code-execution/application/sandbox-adapter.ts +44 -0
- package/src/modules/code-execution/domain/events/index.ts +58 -0
- package/src/modules/code-execution/domain/models/index.ts +33 -0
- package/src/modules/code-execution/domain/operations/execution-operations.ts +60 -0
- package/src/modules/code-execution/domain/validators/index.ts +50 -0
- package/src/modules/code-execution/index.ts +8 -0
- package/src/modules/code-execution/ports/execution-port.ts +15 -0
- package/src/modules/code-execution/types/execution.ts +15 -0
- package/src/modules/comments/application/giscus-adapter.ts +55 -0
- package/src/modules/comments/domain/events/index.ts +55 -0
- package/src/modules/comments/domain/models/index.ts +30 -0
- package/src/modules/comments/domain/operations/comment-operations.ts +46 -0
- package/src/modules/comments/domain/validators/index.ts +50 -0
- package/src/modules/comments/index.ts +8 -0
- package/src/modules/comments/ports/comment-port.ts +18 -0
- package/src/modules/comments/types/comments.ts +19 -0
- package/src/modules/config/application/usecases/index.ts +1 -0
- package/src/modules/config/application/usecases/loadConfig.ts +38 -0
- package/src/modules/config/application/workflows/index.ts +1 -0
- package/src/modules/config/application/workflows/validateConfig.ts +14 -0
- package/src/modules/config/domain/events/index.ts +50 -0
- package/src/modules/config/domain/models/index.ts +9 -0
- package/src/modules/config/domain/operations/defaults.ts +74 -0
- package/src/modules/config/domain/operations/index.ts +2 -0
- package/src/modules/config/domain/operations/resolve.ts +40 -0
- package/src/modules/config/domain/validators/index.ts +152 -0
- package/src/modules/config/index.ts +23 -0
- package/src/modules/config/ports/index.ts +15 -0
- package/src/modules/config/types/index.ts +113 -0
- package/src/modules/config/types/public.ts +19 -0
- package/src/modules/content/application/cache/index.ts +6 -0
- package/src/modules/content/application/cache/parse-cache.ts +6 -0
- package/src/modules/content/application/cache/parseCache.ts +56 -0
- package/src/modules/content/application/usecases/index.ts +2 -0
- package/src/modules/content/application/usecases/load-doc-page.ts +1 -0
- package/src/modules/content/application/usecases/loadDocPage.ts +111 -0
- package/src/modules/content/application/usecases/scanDocsDir.ts +105 -0
- package/src/modules/content/application/workflows/index.ts +1 -0
- package/src/modules/content/application/workflows/processDocs.ts +51 -0
- package/src/modules/content/domain/events/index.ts +61 -0
- package/src/modules/content/domain/models/index.ts +13 -0
- package/src/modules/content/domain/operations/build-page.ts +146 -0
- package/src/modules/content/domain/operations/buildPage.ts +93 -0
- package/src/modules/content/domain/operations/index.ts +17 -0
- package/src/modules/content/domain/operations/parse.ts +241 -0
- package/src/modules/content/domain/validators/frontmatter.ts +82 -0
- package/src/modules/content/domain/validators/index.ts +6 -0
- package/src/modules/content/index.ts +27 -0
- package/src/modules/content/ports/index.ts +45 -0
- package/src/modules/content/ports/velite.ts +134 -0
- package/src/modules/content/types/index.ts +76 -0
- package/src/modules/content/types/public.ts +1 -0
- package/src/modules/content-linting/application/builtin-linting-adapter.ts +82 -0
- package/src/modules/content-linting/domain/events/index.ts +58 -0
- package/src/modules/content-linting/domain/models/index.ts +46 -0
- package/src/modules/content-linting/domain/operations/linting-operations.ts +82 -0
- package/src/modules/content-linting/domain/validators/index.ts +50 -0
- package/src/modules/content-linting/index.ts +8 -0
- package/src/modules/content-linting/ports/linting-port.ts +21 -0
- package/src/modules/content-linting/types/linting.ts +18 -0
- package/src/modules/content-validation/application/usecases/index.ts +18 -0
- package/src/modules/content-validation/domain/events/index.ts +7 -0
- package/src/modules/content-validation/domain/index.ts +16 -0
- package/src/modules/content-validation/domain/models/index.ts +33 -0
- package/src/modules/content-validation/domain/operations/index.ts +157 -0
- package/src/modules/content-validation/domain/types/index.ts +17 -0
- package/src/modules/content-validation/domain/validators/index.ts +8 -0
- package/src/modules/content-validation/index.ts +9 -0
- package/src/modules/content-validation/ports/index.ts +15 -0
- package/src/modules/content-validation/types/index.ts +5 -0
- package/src/modules/export/application/puppeteer-export-adapter.ts +63 -0
- package/src/modules/export/domain/events/index.ts +55 -0
- package/src/modules/export/domain/models/index.ts +38 -0
- package/src/modules/export/domain/operations/export-operations.ts +56 -0
- package/src/modules/export/domain/validators/index.ts +52 -0
- package/src/modules/export/index.ts +8 -0
- package/src/modules/export/ports/export-port.ts +15 -0
- package/src/modules/export/types/export.ts +15 -0
- package/src/modules/external-search/application/algolia-adapter.ts +182 -0
- package/src/modules/external-search/application/meilisearch-adapter.ts +161 -0
- package/src/modules/external-search/domain/events/index.ts +42 -0
- package/src/modules/external-search/domain/models/index.ts +42 -0
- package/src/modules/external-search/domain/operations/search-operations.ts +53 -0
- package/src/modules/external-search/domain/validators/index.ts +55 -0
- package/src/modules/external-search/index.ts +9 -0
- package/src/modules/external-search/ports/external-search-port.ts +23 -0
- package/src/modules/external-search/types/search.ts +19 -0
- package/src/modules/git-history/application/simple-git-adapter.ts +46 -0
- package/src/modules/git-history/domain/events/index.ts +34 -0
- package/src/modules/git-history/domain/models/index.ts +25 -0
- package/src/modules/git-history/domain/operations/git-history-operations.ts +56 -0
- package/src/modules/git-history/domain/validators/index.ts +52 -0
- package/src/modules/git-history/index.ts +8 -0
- package/src/modules/git-history/ports/git-history-port.ts +21 -0
- package/src/modules/git-history/types/git-history.ts +15 -0
- package/src/modules/i18n/application/fs-locale-loader.ts +39 -0
- package/src/modules/i18n/domain/events/index.ts +34 -0
- package/src/modules/i18n/domain/models/index.ts +34 -0
- package/src/modules/i18n/domain/operations/locale-operations.ts +74 -0
- package/src/modules/i18n/domain/validators/index.ts +52 -0
- package/src/modules/i18n/index.ts +8 -0
- package/src/modules/i18n/ports/locale-loader-port.ts +18 -0
- package/src/modules/i18n/types/locale.ts +17 -0
- package/src/modules/image-optimization/application/sharp-adapter.ts +58 -0
- package/src/modules/image-optimization/domain/events/index.ts +39 -0
- package/src/modules/image-optimization/domain/models/index.ts +27 -0
- package/src/modules/image-optimization/domain/operations/image-operations.ts +65 -0
- package/src/modules/image-optimization/domain/validators/index.ts +52 -0
- package/src/modules/image-optimization/index.ts +8 -0
- package/src/modules/image-optimization/ports/image-optimizer-port.ts +15 -0
- package/src/modules/image-optimization/types/image.ts +17 -0
- package/src/modules/live-editor/application/usecases/index.ts +60 -0
- package/src/modules/live-editor/domain/events/index.ts +37 -0
- package/src/modules/live-editor/domain/gitOperations.ts +110 -0
- package/src/modules/live-editor/domain/index.ts +15 -0
- package/src/modules/live-editor/domain/models/index.ts +21 -0
- package/src/modules/live-editor/domain/validators/index.ts +55 -0
- package/src/modules/live-editor/index.ts +14 -0
- package/src/modules/live-editor/ports/index.ts +49 -0
- package/src/modules/live-editor/types/index.ts +80 -0
- package/src/modules/live-preview/application/vite-preview-adapter.ts +20 -0
- package/src/modules/live-preview/domain/operations/preview-operations.ts +56 -0
- package/src/modules/live-preview/index.ts +8 -0
- package/src/modules/live-preview/ports/preview-port.ts +20 -0
- package/src/modules/live-preview/types/preview.ts +16 -0
- package/src/modules/mdx/application/mdx-js-adapter.ts +38 -0
- package/src/modules/mdx/domain/operations/parse-mdx.ts +43 -0
- package/src/modules/mdx/index.ts +8 -0
- package/src/modules/mdx/ports/mdx-parser-port.ts +15 -0
- package/src/modules/mdx/types/mdx.ts +14 -0
- package/src/modules/navigation/application/usecases/buildNav.ts +15 -0
- package/src/modules/navigation/application/usecases/buildSidebar.ts +45 -0
- package/src/modules/navigation/application/usecases/index.ts +2 -0
- package/src/modules/navigation/domain/events/index.ts +30 -0
- package/src/modules/navigation/domain/models/index.ts +7 -0
- package/src/modules/navigation/domain/operations/group.ts +79 -0
- package/src/modules/navigation/domain/operations/index.ts +10 -0
- package/src/modules/navigation/domain/operations/sort.ts +27 -0
- package/src/modules/navigation/domain/shared/utils/array.ts +39 -0
- package/src/modules/navigation/domain/validators/index.ts +88 -0
- package/src/modules/navigation/index.ts +15 -0
- package/src/modules/navigation/ports/index.ts +9 -0
- package/src/modules/navigation/types/index.ts +38 -0
- package/src/modules/navigation/types/public.ts +9 -0
- package/src/modules/openapi/application/swagger-parser-adapter.ts +178 -0
- package/src/modules/openapi/domain/operations/parse-openapi.ts +46 -0
- package/src/modules/openapi/index.ts +8 -0
- package/src/modules/openapi/ports/openapi-parser-port.ts +15 -0
- package/src/modules/openapi/types/openapi.ts +37 -0
- package/src/modules/plugin/application/usecases/build-virtual-modules.ts +53 -0
- package/src/modules/plugin/application/usecases/index.ts +1 -0
- package/src/modules/plugin/application/workflows/build-docs.ts +79 -0
- package/src/modules/plugin/application/workflows/index.ts +1 -0
- package/src/modules/plugin/domain/events/index.ts +62 -0
- package/src/modules/plugin/domain/models/index.ts +1 -0
- package/src/modules/plugin/domain/operations/build-virtual.ts +76 -0
- package/src/modules/plugin/domain/operations/index.ts +11 -0
- package/src/modules/plugin/domain/validators/index.ts +30 -0
- package/src/modules/plugin/index.ts +14 -0
- package/src/modules/plugin/ports/index.ts +21 -0
- package/src/modules/plugin/types/index.ts +27 -0
- package/src/modules/plugin/types/public.ts +1 -0
- package/src/modules/search/application/usecases/index.ts +1 -0
- package/src/modules/search/application/usecases/indexPages.ts +15 -0
- package/src/modules/search/domain/events/index.ts +32 -0
- package/src/modules/search/domain/models/index.ts +1 -0
- package/src/modules/search/domain/operations/build-index.ts +6 -0
- package/src/modules/search/domain/operations/buildIndex.ts +70 -0
- package/src/modules/search/domain/operations/index.ts +7 -0
- package/src/modules/search/domain/operations/query.ts +186 -0
- package/src/modules/search/domain/validators/index.ts +32 -0
- package/src/modules/search/index.ts +9 -0
- package/src/modules/search/types/index.ts +22 -0
- package/src/modules/search/types/public.ts +1 -0
- package/src/modules/search-analytics/application/local-storage-adapter.ts +68 -0
- package/src/modules/search-analytics/domain/operations/search-analytics-operations.ts +74 -0
- package/src/modules/search-analytics/index.ts +8 -0
- package/src/modules/search-analytics/ports/search-analytics-port.ts +20 -0
- package/src/modules/search-analytics/types/search-analytics.ts +16 -0
- package/src/modules/search-highlighting/application/dom-highlighting-adapter.ts +36 -0
- package/src/modules/search-highlighting/domain/operations/highlighting-operations.ts +72 -0
- package/src/modules/search-highlighting/index.ts +8 -0
- package/src/modules/search-highlighting/ports/highlighting-port.ts +14 -0
- package/src/modules/search-highlighting/types/highlighting.ts +15 -0
- package/src/modules/seo-optimization/application/usecases/index.ts +18 -0
- package/src/modules/seo-optimization/domain/index.ts +12 -0
- package/src/modules/seo-optimization/domain/seoOperations.ts +92 -0
- package/src/modules/seo-optimization/index.ts +8 -0
- package/src/modules/seo-optimization/ports/index.ts +18 -0
- package/src/modules/seo-optimization/types/index.ts +41 -0
- package/src/modules/theme/application/css-theme-adapter.ts +50 -0
- package/src/modules/theme/domain/operations/theme-operations.ts +68 -0
- package/src/modules/theme/index.ts +8 -0
- package/src/modules/theme/ports/theme-port.ts +8 -0
- package/src/modules/theme/types/theme.ts +12 -0
- package/src/modules/toc/application/markdown-toc-adapter.ts +106 -0
- package/src/modules/toc/domain/operations/toc-operations.ts +92 -0
- package/src/modules/toc/index.ts +8 -0
- package/src/modules/toc/ports/toc-port.ts +21 -0
- package/src/modules/toc/types/toc.ts +17 -0
- package/src/modules/toc-generator/application/usecases/index.ts +30 -0
- package/src/modules/toc-generator/domain/index.ts +12 -0
- package/src/modules/toc-generator/domain/tocOperations.ts +104 -0
- package/src/modules/toc-generator/index.ts +9 -0
- package/src/modules/toc-generator/ports/index.ts +20 -0
- package/src/modules/toc-generator/types/index.ts +50 -0
- package/src/modules/version-control/domain/events/index.ts +39 -0
- package/src/modules/version-control/domain/models/index.ts +25 -0
- package/src/modules/version-control/domain/validators/index.ts +50 -0
- package/src/modules/versioning/application/fs-version-loader.ts +44 -0
- package/src/modules/versioning/domain/operations/versioning-operations.ts +80 -0
- package/src/modules/versioning/index.ts +8 -0
- package/src/modules/versioning/ports/version-loader-port.ts +18 -0
- package/src/modules/versioning/types/versioning.ts +17 -0
- package/src/modules/workflow/domain/events/index.ts +55 -0
- package/src/modules/workflow/domain/models/index.ts +40 -0
- package/src/modules/workflow/domain/validators/index.ts +50 -0
- package/src/modules/yaml-parser/application/js-yaml-adapter.ts +34 -0
- package/src/modules/yaml-parser/domain/operations/parse-yaml.ts +58 -0
- package/src/modules/yaml-parser/index.ts +7 -0
- package/src/modules/yaml-parser/ports/yaml-parser-port.ts +18 -0
- package/src/navigation/index.ts +9 -0
- package/src/plugin/index.ts +4 -0
- package/src/presentation/index.ts +1 -0
- package/src/presentation/live-editor/index.ts +22 -0
- package/src/presentation/live-editor/live-editor-component.ts +219 -0
- package/src/presentation/live-editor/virtual-module.ts +16 -0
- package/src/presentation/solid/CodeBlock.tsx +120 -0
- package/src/presentation/solid/Toc.tsx +58 -0
- package/src/presentation/solid/index.ts +11 -0
- package/src/presentation/vite-plugin/docs-plugin.ts +212 -0
- package/src/presentation/vite-plugin/index.ts +9 -0
- package/src/presentation/vite-plugin/transform-markdown.ts +26 -0
- package/src/runtime/analytics.ts +59 -0
- package/src/runtime/api-diff.ts +115 -0
- package/src/runtime/app.tsx +32 -0
- package/src/runtime/components/AccentPicker.tsx +114 -0
- package/src/runtime/components/ApiPlayground.tsx +332 -0
- package/src/runtime/components/AskAiDialog.tsx +127 -0
- package/src/runtime/components/BackToTop.tsx +38 -0
- package/src/runtime/components/Banner.tsx +75 -0
- package/src/runtime/components/Breadcrumbs.tsx +42 -0
- package/src/runtime/components/CollectionDropdown.tsx +85 -0
- package/src/runtime/components/CustomizeDrawer.tsx +195 -0
- package/src/runtime/components/DocMarkdown.tsx +579 -0
- package/src/runtime/components/DocPrevNext.tsx +54 -0
- package/src/runtime/components/DocToc.tsx +147 -0
- package/src/runtime/components/DocsDropdown.tsx +184 -0
- package/src/runtime/components/Footer.tsx +52 -0
- package/src/runtime/components/GitHubAuth.tsx +82 -0
- package/src/runtime/components/GitHubStats.tsx +73 -0
- package/src/runtime/components/Head.tsx +225 -0
- package/src/runtime/components/LocaleDropdown.tsx +75 -0
- package/src/runtime/components/MobileBottomNav.tsx +111 -0
- package/src/runtime/components/NotFound.tsx +139 -0
- package/src/runtime/components/PageActions.tsx +144 -0
- package/src/runtime/components/RelatedDocs.tsx +50 -0
- package/src/runtime/components/ScrollProgress.tsx +32 -0
- package/src/runtime/components/SearchPalette.tsx +333 -0
- package/src/runtime/components/ShowcaseCard.tsx +87 -0
- package/src/runtime/components/SidebarNav.tsx +237 -0
- package/src/runtime/components/Skeleton.tsx +39 -0
- package/src/runtime/components/ThemeToggle.tsx +26 -0
- package/src/runtime/components/TopNav.tsx +270 -0
- package/src/runtime/components/VersionDropdown.tsx +189 -0
- package/src/runtime/components/markdown/components.ts +280 -0
- package/src/runtime/config.ts +225 -0
- package/src/runtime/content.ts +451 -0
- package/src/runtime/context.tsx +30 -0
- package/src/runtime/data.ts +93 -0
- package/src/runtime/github.ts +226 -0
- package/src/runtime/icons.ts +32 -0
- package/src/runtime/index.ts +153 -0
- package/src/runtime/layouts/DocsLayout.tsx +144 -0
- package/src/runtime/markdown-content.css +996 -0
- package/src/runtime/pages/AbTestPage.tsx +88 -0
- package/src/runtime/pages/AnalyticsPage.tsx +90 -0
- package/src/runtime/pages/ApiDiffPage.tsx +86 -0
- package/src/runtime/pages/ApiEndpointPage.tsx +248 -0
- package/src/runtime/pages/BuilderPage.tsx +150 -0
- package/src/runtime/pages/ChangelogPage.tsx +210 -0
- package/src/runtime/pages/CollectionPage.tsx +140 -0
- package/src/runtime/pages/CommunityPage.tsx +384 -0
- package/src/runtime/pages/CreatePage.tsx +448 -0
- package/src/runtime/pages/DocPage.tsx +193 -0
- package/src/runtime/pages/EditPage.tsx +201 -0
- package/src/runtime/pages/HomePage.tsx +187 -0
- package/src/runtime/pages/IssuesPage.tsx +140 -0
- package/src/runtime/pages/OAuthCallbackPage.tsx +80 -0
- package/src/runtime/pages/PluginsPage.tsx +249 -0
- package/src/runtime/pages/ShowcasePage.tsx +202 -0
- package/src/runtime/pwa.ts +39 -0
- package/src/runtime/router.tsx +192 -0
- package/src/runtime/seo.ts +192 -0
- package/src/runtime/theme.css +175 -0
- package/src/runtime/theme.ts +224 -0
- package/src/runtime/types.ts +217 -0
- package/src/search/index.ts +6 -0
- package/src/seo-optimization/index.ts +4 -0
- package/src/shared/constants/index.ts +26 -0
- package/src/shared/errors/index.ts +195 -0
- package/src/shared/index.ts +27 -0
- package/src/shared/types/brand.ts +14 -0
- package/src/shared/types/client.d.ts +45 -0
- package/src/shared/types/either.ts +38 -0
- package/src/shared/types/index.ts +42 -0
- package/src/shared/types/option.ts +52 -0
- package/src/shared/types/result.ts +81 -0
- package/src/shared/utils/array.ts +97 -0
- package/src/shared/utils/index.ts +46 -0
- package/src/shared/utils/object.ts +47 -0
- package/src/shared/utils/string.ts +74 -0
- package/src/toc-generator/index.ts +1 -0
- package/src/types/js-yaml.d.ts +42 -0
- package/src/worker.ts +462 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
import type { ElementNode, NodeHandler } from "comark";
|
|
2
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
3
|
+
import { useDocs } from "../context";
|
|
4
|
+
import "katex/dist/katex.min.css";
|
|
5
|
+
import "../markdown-content.css";
|
|
6
|
+
import {
|
|
7
|
+
accordionComponent,
|
|
8
|
+
badgeComponent,
|
|
9
|
+
cardComponent,
|
|
10
|
+
cardGridComponent,
|
|
11
|
+
codePreviewComponent,
|
|
12
|
+
copyComponent,
|
|
13
|
+
fileTreeComponent,
|
|
14
|
+
kbdComponent,
|
|
15
|
+
tabsComponent,
|
|
16
|
+
timelineComponent,
|
|
17
|
+
tooltipComponent,
|
|
18
|
+
videoComponent,
|
|
19
|
+
youtubeComponent,
|
|
20
|
+
} from "./markdown/components";
|
|
21
|
+
|
|
22
|
+
const alertMap: Record<string, string> = {
|
|
23
|
+
info: "rt-alert--info",
|
|
24
|
+
note: "rt-alert--note",
|
|
25
|
+
success: "rt-alert--success",
|
|
26
|
+
tip: "rt-alert--tip",
|
|
27
|
+
important: "rt-alert--important",
|
|
28
|
+
warning: "rt-alert--warning",
|
|
29
|
+
caution: "rt-alert--caution",
|
|
30
|
+
danger: "rt-alert--danger",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type RenderFn = (source: string) => Promise<string>;
|
|
34
|
+
type FeatureKey = "base" | "base:math" | "base:mermaid" | "base:math:mermaid";
|
|
35
|
+
|
|
36
|
+
const renderers: Partial<Record<FeatureKey, RenderFn>> = {};
|
|
37
|
+
|
|
38
|
+
function detectFeatures(source: string): { math: boolean; mermaid: boolean } {
|
|
39
|
+
const mermaid = source.includes("```mermaid");
|
|
40
|
+
const math =
|
|
41
|
+
/\$\$/.test(source) ||
|
|
42
|
+
/(?:^|[^$\d])\$[^$\s\d][^$\n]*\$(?:[^$]|$)/.test(source);
|
|
43
|
+
return { math, mermaid };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const blockquoteComponent: NodeHandler = async (node, state) => {
|
|
47
|
+
const [, attrs, ...children] = node;
|
|
48
|
+
const as = attrs.as as string | undefined;
|
|
49
|
+
if (!as) return `<blockquote>${await state.render(children)}</blockquote>`;
|
|
50
|
+
const cls = alertMap[as] ?? `rt-alert rt-alert--${as}`;
|
|
51
|
+
const title = as.charAt(0).toUpperCase() + as.slice(1);
|
|
52
|
+
return `<div class="rt-alert ${cls}" role="alert"><p class="rt-alert__title">${title}</p>${await state.render(children)}</div>`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const codeGroupComponent: NodeHandler = async (node, state) => {
|
|
56
|
+
const [, , ...children] = node;
|
|
57
|
+
if (!children.length) return "";
|
|
58
|
+
|
|
59
|
+
const tabs = await Promise.all(
|
|
60
|
+
children.map(async (child, i) => {
|
|
61
|
+
const el = child as ElementNode;
|
|
62
|
+
const [tag, cAttrs] = el;
|
|
63
|
+
if (tag !== "pre") return null;
|
|
64
|
+
const label =
|
|
65
|
+
(cAttrs["data-language"] as string) ||
|
|
66
|
+
(cAttrs.class as string) ||
|
|
67
|
+
`tab-${i + 1}`;
|
|
68
|
+
const html = await state.render(el);
|
|
69
|
+
const id = `cg-${Math.random().toString(36).slice(2, 8)}-${i}`;
|
|
70
|
+
return { id, label, html };
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const valid = tabs.filter(Boolean) as {
|
|
75
|
+
id: string;
|
|
76
|
+
label: string;
|
|
77
|
+
html: string;
|
|
78
|
+
}[];
|
|
79
|
+
if (!valid.length) return "";
|
|
80
|
+
|
|
81
|
+
return `<div class="rt-code-group">
|
|
82
|
+
<div class="rt-code-group__tabs" role="tablist">
|
|
83
|
+
${valid
|
|
84
|
+
.map(
|
|
85
|
+
(t, i) =>
|
|
86
|
+
`<button type="button" class="rt-code-group__tab${i === 0 ? " rt-code-group__tab--active" : ""}" data-target="${t.id}" role="tab" aria-selected="${i === 0 ? "true" : "false"}">${t.label}</button>`,
|
|
87
|
+
)
|
|
88
|
+
.join("")}
|
|
89
|
+
</div>
|
|
90
|
+
${valid
|
|
91
|
+
.map(
|
|
92
|
+
(t, i) =>
|
|
93
|
+
`<div class="rt-code-group__panel${i === 0 ? " rt-code-group__panel--active" : ""}" id="${t.id}" role="tabpanel">${t.html}</div>`,
|
|
94
|
+
)
|
|
95
|
+
.join("")}
|
|
96
|
+
</div>`;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const playgroundComponent: NodeHandler = async (node, state) => {
|
|
100
|
+
const [, , ...children] = node;
|
|
101
|
+
if (!children.length) return "";
|
|
102
|
+
const el = children[0] as ElementNode;
|
|
103
|
+
if (el[0] !== "pre") return await state.render(children);
|
|
104
|
+
const html = await state.render(el);
|
|
105
|
+
const id = `pg-${Math.random().toString(36).slice(2, 8)}`;
|
|
106
|
+
return `<div class="rt-playground" data-playground="${id}">
|
|
107
|
+
<div class="rt-playground__preview" data-preview="${id}"></div>
|
|
108
|
+
<details class="rt-playground__source" open>
|
|
109
|
+
<summary>Source</summary>
|
|
110
|
+
${html}
|
|
111
|
+
</details>
|
|
112
|
+
</div>`;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const stepsComponent: NodeHandler = async (node, state) => {
|
|
116
|
+
const [, , ...children] = node;
|
|
117
|
+
const items: string[] = [];
|
|
118
|
+
for (const child of children) {
|
|
119
|
+
const el = child as ElementNode;
|
|
120
|
+
if (el[0] === "ol" || el[0] === "ul") {
|
|
121
|
+
const [, , ...listItems] = el;
|
|
122
|
+
for (const li of listItems) {
|
|
123
|
+
const liEl = li as ElementNode;
|
|
124
|
+
if (liEl[0] !== "li") continue;
|
|
125
|
+
const [, , ...liChildren] = liEl;
|
|
126
|
+
items.push(await state.render(liChildren));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!items.length) return await state.render(children);
|
|
131
|
+
const id = `steps-${Math.random().toString(36).slice(2, 8)}`;
|
|
132
|
+
return `<ol class="rt-steps" data-steps="${id}">
|
|
133
|
+
${items
|
|
134
|
+
.map(
|
|
135
|
+
(body, i) => `<li class="rt-steps__item" data-step="${i}">
|
|
136
|
+
<span class="rt-steps__marker" aria-hidden="true">${i + 1}</span>
|
|
137
|
+
<div class="rt-steps__body">${body}</div>
|
|
138
|
+
</li>`,
|
|
139
|
+
)
|
|
140
|
+
.join("")}
|
|
141
|
+
</ol>`;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
async function buildRenderer(features: {
|
|
145
|
+
math: boolean;
|
|
146
|
+
mermaid: boolean;
|
|
147
|
+
}): Promise<RenderFn> {
|
|
148
|
+
const [
|
|
149
|
+
{ createHtmlRenderer },
|
|
150
|
+
{ default: security },
|
|
151
|
+
{ default: rangi },
|
|
152
|
+
{ default: taskList },
|
|
153
|
+
{ github },
|
|
154
|
+
] = await Promise.all([
|
|
155
|
+
import("@comark/html"),
|
|
156
|
+
import("@comark/html/plugins/security"),
|
|
157
|
+
import("@comark/html/plugins/rangi"),
|
|
158
|
+
import("@comark/html/plugins/task-list"),
|
|
159
|
+
import("rangi/themes"),
|
|
160
|
+
]);
|
|
161
|
+
|
|
162
|
+
const plugins = [
|
|
163
|
+
security({
|
|
164
|
+
blockedTags: ["script", "iframe", "object", "embed", "link", "style"],
|
|
165
|
+
allowedProtocols: ["https", "http", "mailto"],
|
|
166
|
+
}),
|
|
167
|
+
rangi({ theme: github }),
|
|
168
|
+
taskList(),
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const components: Record<string, NodeHandler> = {
|
|
172
|
+
blockquote: blockquoteComponent,
|
|
173
|
+
"code-group": codeGroupComponent,
|
|
174
|
+
playground: playgroundComponent,
|
|
175
|
+
steps: stepsComponent,
|
|
176
|
+
card: cardComponent,
|
|
177
|
+
"card-grid": cardGridComponent,
|
|
178
|
+
tabs: tabsComponent,
|
|
179
|
+
"file-tree": fileTreeComponent,
|
|
180
|
+
kbd: kbdComponent,
|
|
181
|
+
badge: badgeComponent,
|
|
182
|
+
accordion: accordionComponent,
|
|
183
|
+
youtube: youtubeComponent,
|
|
184
|
+
video: videoComponent,
|
|
185
|
+
timeline: timelineComponent,
|
|
186
|
+
tooltip: tooltipComponent,
|
|
187
|
+
copy: copyComponent,
|
|
188
|
+
"code-preview": codePreviewComponent,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
if (features.mermaid) {
|
|
192
|
+
const mermaidModule = await import("@comark/html/plugins/mermaid");
|
|
193
|
+
plugins.push(mermaidModule.default());
|
|
194
|
+
components.mermaid = mermaidModule.Mermaid as NodeHandler;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (features.math) {
|
|
198
|
+
const mathModule = await import("@comark/html/plugins/math");
|
|
199
|
+
plugins.push(mathModule.default());
|
|
200
|
+
components.math = mathModule.Math as NodeHandler;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return createHtmlRenderer({ plugins, components });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function getRendererKey(features: {
|
|
207
|
+
math: boolean;
|
|
208
|
+
mermaid: boolean;
|
|
209
|
+
}): FeatureKey {
|
|
210
|
+
if (features.math && features.mermaid) return "base:math:mermaid";
|
|
211
|
+
if (features.math) return "base:math";
|
|
212
|
+
if (features.mermaid) return "base:mermaid";
|
|
213
|
+
return "base";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function getComarkRender(source: string): Promise<RenderFn> {
|
|
217
|
+
const features = detectFeatures(source);
|
|
218
|
+
const key = getRendererKey(features);
|
|
219
|
+
if (!renderers[key]) {
|
|
220
|
+
renderers[key] = await buildRenderer(features);
|
|
221
|
+
}
|
|
222
|
+
return renderers[key] as RenderFn;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function slugify(text: string): string {
|
|
226
|
+
return text
|
|
227
|
+
.trim()
|
|
228
|
+
.toLowerCase()
|
|
229
|
+
.replace(/[^\p{L}\p{N}\s-]/gu, "")
|
|
230
|
+
.replace(/\s+/gu, "-")
|
|
231
|
+
.replace(/-+/g, "-")
|
|
232
|
+
.substring(0, 80);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function enhanceMarkdown(el: HTMLDivElement) {
|
|
236
|
+
const headings = el.querySelectorAll("h1, h2, h3, h4, h5, h6");
|
|
237
|
+
for (const h of headings) {
|
|
238
|
+
if (h.id) continue;
|
|
239
|
+
const id = slugify(h.textContent ?? "");
|
|
240
|
+
if (id) h.id = id;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const escapeHtml = (s: string) =>
|
|
244
|
+
s.replace(/&/g, "&").replace(/</g, "<").replace(/"/g, """);
|
|
245
|
+
|
|
246
|
+
const pres = el.querySelectorAll("pre");
|
|
247
|
+
for (const pre of pres) {
|
|
248
|
+
if (pre.querySelector(".rt-code-copy")) continue;
|
|
249
|
+
const code = pre.querySelector("code");
|
|
250
|
+
const text = code?.textContent ?? pre.textContent ?? "";
|
|
251
|
+
const btn = document.createElement("button");
|
|
252
|
+
btn.type = "button";
|
|
253
|
+
btn.className = "rt-code-copy";
|
|
254
|
+
btn.textContent = "Copy";
|
|
255
|
+
btn.setAttribute("aria-label", "Copy code");
|
|
256
|
+
btn.title = "Copy code";
|
|
257
|
+
btn.addEventListener("click", () => {
|
|
258
|
+
navigator.clipboard.writeText(text).catch(() => {});
|
|
259
|
+
const original = btn.textContent;
|
|
260
|
+
btn.textContent = "Copied!";
|
|
261
|
+
setTimeout(() => (btn.textContent = original), 1500);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Standalone blocks get a header bar (language + filename + copy) and a
|
|
265
|
+
// collapse toggle when long. Blocks inside code-groups/playgrounds keep
|
|
266
|
+
// their own chrome.
|
|
267
|
+
if (
|
|
268
|
+
!pre.closest(".rt-code-group") &&
|
|
269
|
+
!pre.closest(".rt-playground") &&
|
|
270
|
+
!pre.closest(".rt-codeblock")
|
|
271
|
+
) {
|
|
272
|
+
const lang =
|
|
273
|
+
pre.dataset.language ??
|
|
274
|
+
code?.className.match(/language-(\w+)/)?.[1] ??
|
|
275
|
+
"text";
|
|
276
|
+
const filename = pre.dataset.filename ?? pre.getAttribute("title") ?? "";
|
|
277
|
+
const lines = text.trimEnd().split("\n").length;
|
|
278
|
+
|
|
279
|
+
const wrap = document.createElement("div");
|
|
280
|
+
wrap.className = "rt-codeblock";
|
|
281
|
+
pre.parentNode?.insertBefore(wrap, pre);
|
|
282
|
+
|
|
283
|
+
const header = document.createElement("div");
|
|
284
|
+
header.className = "rt-codeblock__header";
|
|
285
|
+
header.innerHTML =
|
|
286
|
+
'<span class="i-mdi:code-tags rt-codeblock__icon" aria-hidden="true"></span>' +
|
|
287
|
+
(filename
|
|
288
|
+
? `<span class="rt-codeblock__filename">${escapeHtml(filename)}</span>`
|
|
289
|
+
: "") +
|
|
290
|
+
`<span class="rt-codeblock__lang">${escapeHtml(lang)}</span>`;
|
|
291
|
+
header.appendChild(btn);
|
|
292
|
+
wrap.appendChild(header);
|
|
293
|
+
wrap.appendChild(pre);
|
|
294
|
+
|
|
295
|
+
if (lines > 24) {
|
|
296
|
+
wrap.classList.add("rt-codeblock--collapsed");
|
|
297
|
+
const toggle = document.createElement("button");
|
|
298
|
+
toggle.type = "button";
|
|
299
|
+
toggle.className = "rt-codeblock__expand";
|
|
300
|
+
toggle.textContent = `Expand (${lines} lines)`;
|
|
301
|
+
toggle.addEventListener("click", () => {
|
|
302
|
+
const collapsedNow = wrap.classList.toggle("rt-codeblock--collapsed");
|
|
303
|
+
toggle.textContent = collapsedNow
|
|
304
|
+
? `Expand (${lines} lines)`
|
|
305
|
+
: "Collapse";
|
|
306
|
+
});
|
|
307
|
+
wrap.appendChild(toggle);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Diff-friendly line coloring for unified diffs.
|
|
311
|
+
if (lang === "diff") {
|
|
312
|
+
const codeEl = pre.querySelector("code");
|
|
313
|
+
if (codeEl) {
|
|
314
|
+
const diffLines = (codeEl.textContent ?? "").split("\n");
|
|
315
|
+
codeEl.innerHTML = diffLines
|
|
316
|
+
.map((ln) => {
|
|
317
|
+
if (ln.startsWith("+++") || ln.startsWith("---"))
|
|
318
|
+
return `<span class="rt-diff-line rt-diff-meta">${escapeHtml(ln)}</span>`;
|
|
319
|
+
if (ln.startsWith("+"))
|
|
320
|
+
return `<span class="rt-diff-line rt-diff-add">${escapeHtml(ln)}</span>`;
|
|
321
|
+
if (ln.startsWith("-"))
|
|
322
|
+
return `<span class="rt-diff-line rt-diff-del">${escapeHtml(ln)}</span>`;
|
|
323
|
+
if (ln.startsWith("@@"))
|
|
324
|
+
return `<span class="rt-diff-line rt-diff-hunk">${escapeHtml(ln)}</span>`;
|
|
325
|
+
return `<span class="rt-diff-line rt-diff-ctx">${escapeHtml(ln)}</span>`;
|
|
326
|
+
})
|
|
327
|
+
.join("\n");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
pre.appendChild(btn);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const tabLists = el.querySelectorAll<HTMLDivElement>(
|
|
336
|
+
".rt-code-group, .rt-tabs",
|
|
337
|
+
);
|
|
338
|
+
for (const group of tabLists) {
|
|
339
|
+
const isCodeGroup = group.classList.contains("rt-code-group");
|
|
340
|
+
const tabSelector = isCodeGroup ? ".rt-code-group__tab" : ".rt-tabs__tab";
|
|
341
|
+
const panelSelector = isCodeGroup
|
|
342
|
+
? ".rt-code-group__panel"
|
|
343
|
+
: ".rt-tabs__panel";
|
|
344
|
+
const activeTabClass = isCodeGroup
|
|
345
|
+
? "rt-code-group__tab--active"
|
|
346
|
+
: "rt-tabs__tab--active";
|
|
347
|
+
const activePanelClass = isCodeGroup
|
|
348
|
+
? "rt-code-group__panel--active"
|
|
349
|
+
: "rt-tabs__panel--active";
|
|
350
|
+
|
|
351
|
+
const tabs = group.querySelectorAll<HTMLButtonElement>(tabSelector);
|
|
352
|
+
const panels = group.querySelectorAll<HTMLDivElement>(panelSelector);
|
|
353
|
+
for (const tab of tabs) {
|
|
354
|
+
tab.addEventListener("click", () => {
|
|
355
|
+
const target = isCodeGroup ? tab.dataset.target : tab.dataset.tab;
|
|
356
|
+
for (const t of tabs) {
|
|
357
|
+
const active = isCodeGroup
|
|
358
|
+
? t.dataset.target === target
|
|
359
|
+
: t.dataset.tab === target;
|
|
360
|
+
t.classList.toggle(activeTabClass, active);
|
|
361
|
+
t.setAttribute("aria-selected", String(active));
|
|
362
|
+
}
|
|
363
|
+
for (const p of panels) {
|
|
364
|
+
p.classList.toggle(activePanelClass, p.id === target);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const playgrounds = el.querySelectorAll<HTMLDivElement>(".rt-playground");
|
|
371
|
+
for (const pg of playgrounds) {
|
|
372
|
+
if (pg.dataset.enhanced) continue;
|
|
373
|
+
pg.dataset.enhanced = "1";
|
|
374
|
+
const previewEl = pg.querySelector<HTMLDivElement>("[data-preview]");
|
|
375
|
+
const pre = pg.querySelector("pre");
|
|
376
|
+
const code = pre?.querySelector("code");
|
|
377
|
+
if (!previewEl || !pre || !code) continue;
|
|
378
|
+
|
|
379
|
+
const iframe = document.createElement("iframe");
|
|
380
|
+
iframe.setAttribute("sandbox", "allow-scripts");
|
|
381
|
+
iframe.setAttribute("title", "Playground preview");
|
|
382
|
+
iframe.className = "rt-playground__frame";
|
|
383
|
+
iframe.srcdoc = code.textContent ?? "";
|
|
384
|
+
previewEl.appendChild(iframe);
|
|
385
|
+
|
|
386
|
+
const source = pre;
|
|
387
|
+
source.setAttribute("contenteditable", "true");
|
|
388
|
+
source.setAttribute("spellcheck", "false");
|
|
389
|
+
source.addEventListener("input", () => {
|
|
390
|
+
iframe.srcdoc = source.textContent ?? "";
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const stepsKey = `create-docs:steps:${location.pathname}`;
|
|
395
|
+
let savedSteps: number[] = [];
|
|
396
|
+
try {
|
|
397
|
+
savedSteps = JSON.parse(localStorage.getItem(stepsKey) ?? "[]");
|
|
398
|
+
} catch {
|
|
399
|
+
savedSteps = [];
|
|
400
|
+
}
|
|
401
|
+
const stepLists = el.querySelectorAll<HTMLOListElement>(".rt-steps");
|
|
402
|
+
for (const list of stepLists) {
|
|
403
|
+
if (list.dataset.enhanced) continue;
|
|
404
|
+
list.dataset.enhanced = "1";
|
|
405
|
+
const items = list.querySelectorAll<HTMLLIElement>(".rt-steps__item");
|
|
406
|
+
for (const item of items) {
|
|
407
|
+
const idx = Number(item.dataset.step);
|
|
408
|
+
const box = document.createElement("input");
|
|
409
|
+
box.type = "checkbox";
|
|
410
|
+
box.className = "rt-steps__check";
|
|
411
|
+
box.checked = savedSteps.includes(idx);
|
|
412
|
+
box.setAttribute("aria-label", `Mark step ${idx + 1} complete`);
|
|
413
|
+
item.classList.toggle("rt-steps__item--done", box.checked);
|
|
414
|
+
box.addEventListener("change", () => {
|
|
415
|
+
item.classList.toggle("rt-steps__item--done", box.checked);
|
|
416
|
+
const done = Array.from(items)
|
|
417
|
+
.filter((it) => it.classList.contains("rt-steps__item--done"))
|
|
418
|
+
.map((it) => Number(it.dataset.step));
|
|
419
|
+
try {
|
|
420
|
+
localStorage.setItem(stepsKey, JSON.stringify(done));
|
|
421
|
+
} catch {
|
|
422
|
+
// storage unavailable — progress not persisted
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
item.insertBefore(box, item.firstChild);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const youtubeEls = el.querySelectorAll<HTMLDivElement>(".rt-youtube");
|
|
430
|
+
for (const y of youtubeEls) {
|
|
431
|
+
if (y.dataset.enhanced) continue;
|
|
432
|
+
y.dataset.enhanced = "1";
|
|
433
|
+
const id = y.dataset.id;
|
|
434
|
+
if (!id) continue;
|
|
435
|
+
const play = y.querySelector<HTMLButtonElement>(".rt-youtube__play");
|
|
436
|
+
play?.addEventListener("click", () => {
|
|
437
|
+
const iframe = document.createElement("iframe");
|
|
438
|
+
iframe.src = `https://www.youtube-nocookie.com/embed/${id}`;
|
|
439
|
+
iframe.title = "YouTube video";
|
|
440
|
+
iframe.allow =
|
|
441
|
+
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
|
|
442
|
+
iframe.allowFullscreen = true;
|
|
443
|
+
iframe.className = "w-full h-full border-0";
|
|
444
|
+
y.innerHTML = "";
|
|
445
|
+
y.appendChild(iframe);
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const tooltips = el.querySelectorAll<HTMLSpanElement>(".rt-tooltip");
|
|
450
|
+
for (const tip of tooltips) {
|
|
451
|
+
if (tip.dataset.enhanced) continue;
|
|
452
|
+
tip.dataset.enhanced = "1";
|
|
453
|
+
tip.addEventListener("mouseenter", () => {
|
|
454
|
+
const text = tip.dataset.tip;
|
|
455
|
+
if (!text) return;
|
|
456
|
+
let overlay = tip.querySelector(
|
|
457
|
+
".rt-tooltip__tip",
|
|
458
|
+
) as HTMLDivElement | null;
|
|
459
|
+
if (!overlay) {
|
|
460
|
+
overlay = document.createElement("div");
|
|
461
|
+
overlay.className = "rt-tooltip__tip";
|
|
462
|
+
overlay.textContent = text;
|
|
463
|
+
tip.appendChild(overlay);
|
|
464
|
+
}
|
|
465
|
+
overlay.classList.add("rt-tooltip__tip--visible");
|
|
466
|
+
});
|
|
467
|
+
tip.addEventListener("mouseleave", () => {
|
|
468
|
+
tip
|
|
469
|
+
.querySelector(".rt-tooltip__tip")
|
|
470
|
+
?.classList.remove("rt-tooltip__tip--visible");
|
|
471
|
+
});
|
|
472
|
+
tip.addEventListener("focus", () =>
|
|
473
|
+
tip.dispatchEvent(new MouseEvent("mouseenter")),
|
|
474
|
+
);
|
|
475
|
+
tip.addEventListener("blur", () =>
|
|
476
|
+
tip.dispatchEvent(new MouseEvent("mouseleave")),
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const copies = el.querySelectorAll<HTMLButtonElement>(".rt-copy");
|
|
481
|
+
for (const btn of copies) {
|
|
482
|
+
if (btn.dataset.enhanced) continue;
|
|
483
|
+
btn.dataset.enhanced = "1";
|
|
484
|
+
btn.addEventListener("click", async () => {
|
|
485
|
+
const value = btn.dataset.copy;
|
|
486
|
+
if (!value) return;
|
|
487
|
+
try {
|
|
488
|
+
await navigator.clipboard.writeText(value);
|
|
489
|
+
const original = btn.textContent;
|
|
490
|
+
btn.textContent = "Copied!";
|
|
491
|
+
setTimeout(() => (btn.textContent = original), 1200);
|
|
492
|
+
} catch {
|
|
493
|
+
// ignore
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const previews = el.querySelectorAll<HTMLDivElement>(".rt-code-preview");
|
|
499
|
+
for (const p of previews) {
|
|
500
|
+
if (p.dataset.enhanced) continue;
|
|
501
|
+
p.dataset.enhanced = "1";
|
|
502
|
+
const code = p.dataset.code;
|
|
503
|
+
if (!code) continue;
|
|
504
|
+
const result = p.querySelector<HTMLDivElement>(".rt-code-preview__result");
|
|
505
|
+
if (!result) continue;
|
|
506
|
+
try {
|
|
507
|
+
const sandbox = document.createElement("div");
|
|
508
|
+
sandbox.innerHTML = code;
|
|
509
|
+
result.appendChild(sandbox);
|
|
510
|
+
} catch {
|
|
511
|
+
result.textContent = "Preview unavailable";
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const images = el.querySelectorAll<HTMLImageElement>("img");
|
|
516
|
+
for (const img of images) {
|
|
517
|
+
if (img.closest("a") || img.classList.contains("rt-image-zoomed")) continue;
|
|
518
|
+
img.classList.add("rt-image-zoom");
|
|
519
|
+
img.addEventListener("click", () => {
|
|
520
|
+
const overlay = document.createElement("div");
|
|
521
|
+
overlay.className = "rt-image-zoom-overlay";
|
|
522
|
+
overlay.setAttribute("role", "dialog");
|
|
523
|
+
overlay.setAttribute("aria-modal", "true");
|
|
524
|
+
overlay.setAttribute("aria-label", "Image preview");
|
|
525
|
+
const zoomed = document.createElement("img");
|
|
526
|
+
zoomed.src = img.src;
|
|
527
|
+
zoomed.alt = img.alt;
|
|
528
|
+
zoomed.className = "rt-image-zoomed";
|
|
529
|
+
overlay.appendChild(zoomed);
|
|
530
|
+
document.body.appendChild(overlay);
|
|
531
|
+
const close = () => overlay.remove();
|
|
532
|
+
overlay.addEventListener("click", close);
|
|
533
|
+
document.addEventListener("keydown", (e) => {
|
|
534
|
+
if (e.key === "Escape") close();
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function applyMarked(source: string) {
|
|
541
|
+
return import("marked").then(({ marked }) => marked.parse(source) as string);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export function DocMarkdown(props: { source: string }) {
|
|
545
|
+
let el: HTMLDivElement | undefined;
|
|
546
|
+
const config = useDocs();
|
|
547
|
+
|
|
548
|
+
const renderMarkdown = async () => {
|
|
549
|
+
if (!el) return;
|
|
550
|
+
try {
|
|
551
|
+
const engine = config.markdown?.engine ?? "comark";
|
|
552
|
+
const str =
|
|
553
|
+
engine === "marked"
|
|
554
|
+
? await applyMarked(props.source)
|
|
555
|
+
: await (await getComarkRender(props.source))(props.source);
|
|
556
|
+
el.innerHTML = str;
|
|
557
|
+
queueMicrotask(() => enhanceMarkdown(el as HTMLDivElement));
|
|
558
|
+
} catch (err) {
|
|
559
|
+
el.innerHTML = `<p class="rt-markdown__error">Failed to render docs: ${err}</p>`;
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
createEffect(() => {
|
|
564
|
+
renderMarkdown();
|
|
565
|
+
});
|
|
566
|
+
onCleanup(() => {
|
|
567
|
+
el = undefined;
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
return (
|
|
571
|
+
<div
|
|
572
|
+
ref={(node) => {
|
|
573
|
+
el = node;
|
|
574
|
+
renderMarkdown();
|
|
575
|
+
}}
|
|
576
|
+
class="rt-markdown"
|
|
577
|
+
/>
|
|
578
|
+
);
|
|
579
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Link } from "@tanstack/solid-router";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import type { DocEntry } from "../types";
|
|
4
|
+
|
|
5
|
+
export function DocPrevNext(props: {
|
|
6
|
+
collection: string;
|
|
7
|
+
docs: DocEntry[];
|
|
8
|
+
currentId: string;
|
|
9
|
+
}) {
|
|
10
|
+
const index = () => props.docs.findIndex((d) => d.id === props.currentId);
|
|
11
|
+
const prev = () => (index() > 0 ? props.docs[index() - 1] : undefined);
|
|
12
|
+
const next = () =>
|
|
13
|
+
index() >= 0 && index() < props.docs.length - 1
|
|
14
|
+
? props.docs[index() + 1]
|
|
15
|
+
: undefined;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<nav
|
|
19
|
+
aria-label="Previous and next pages"
|
|
20
|
+
class="flex items-stretch gap-3 mt-10 pt-6 border-t border-border"
|
|
21
|
+
>
|
|
22
|
+
<Show when={prev()}>
|
|
23
|
+
{(p) => (
|
|
24
|
+
<Link
|
|
25
|
+
to="/$collection/$docId"
|
|
26
|
+
params={{ collection: props.collection, docId: p().id }}
|
|
27
|
+
class="flex-1 flex flex-col gap-1 p-3 rounded-lg border border-border no-underline hover:border-focus transition-colors"
|
|
28
|
+
>
|
|
29
|
+
<span class="flex items-center gap-1 text-xs text-muted">
|
|
30
|
+
<span class="i-mdi:chevron-left" aria-hidden="true" />
|
|
31
|
+
Previous
|
|
32
|
+
</span>
|
|
33
|
+
<span class="text-sm font-medium text-foreground">{p().label}</span>
|
|
34
|
+
</Link>
|
|
35
|
+
)}
|
|
36
|
+
</Show>
|
|
37
|
+
<Show when={next()}>
|
|
38
|
+
{(n) => (
|
|
39
|
+
<Link
|
|
40
|
+
to="/$collection/$docId"
|
|
41
|
+
params={{ collection: props.collection, docId: n().id }}
|
|
42
|
+
class="flex-1 flex flex-col gap-1 p-3 rounded-lg border border-border no-underline text-right hover:border-focus transition-colors ml-auto"
|
|
43
|
+
>
|
|
44
|
+
<span class="flex items-center justify-end gap-1 text-xs text-muted">
|
|
45
|
+
Next
|
|
46
|
+
<span class="i-mdi:chevron-right" aria-hidden="true" />
|
|
47
|
+
</span>
|
|
48
|
+
<span class="text-sm font-medium text-foreground">{n().label}</span>
|
|
49
|
+
</Link>
|
|
50
|
+
)}
|
|
51
|
+
</Show>
|
|
52
|
+
</nav>
|
|
53
|
+
);
|
|
54
|
+
}
|