@rspress/core 2.0.0-rc.1 → 2.0.0-rc.2

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.
Files changed (256) hide show
  1. package/bin/rspress.js +1 -1
  2. package/dist/0~7675.989ee664.js +1791 -0
  3. package/dist/1218.3869bad6.js +2 -0
  4. package/dist/4669.12208c6a.js +2 -0
  5. package/dist/5313.6594aba0.js +63 -0
  6. package/dist/5485.2a0273cf.js +98 -0
  7. package/dist/6289.c67fe0d5.js +5 -0
  8. package/dist/7805.cadab34e.js +4 -0
  9. package/dist/8813.9da1f210.js +2 -0
  10. package/dist/cli/config/index.js +4 -0
  11. package/dist/cli/config/loadConfigFile.js +30 -0
  12. package/dist/cli/index.cb89dbd1.js +3 -0
  13. package/dist/cli/index.js +122 -0
  14. package/dist/eject-theme/components/Banner/index.tsx +3 -4
  15. package/dist/eject-theme/components/Callout/index.scss +0 -2
  16. package/dist/eject-theme/components/CodeBlock/index.scss +4 -12
  17. package/dist/eject-theme/components/CodeBlock/index.tsx +6 -1
  18. package/dist/eject-theme/components/CodeButtonGroup/CopyCodeButton.tsx +1 -3
  19. package/dist/eject-theme/components/CodeButtonGroup/index.scss +5 -1
  20. package/dist/eject-theme/components/CodeButtonGroup/index.tsx +1 -3
  21. package/dist/eject-theme/components/DocContent/doc.scss +27 -7
  22. package/dist/eject-theme/components/DocContent/docComponents/table.tsx +10 -4
  23. package/dist/eject-theme/components/DocContent/index.tsx +3 -3
  24. package/dist/eject-theme/components/{DocContent/FallbackHeading.tsx → FallbackHeading/index.tsx} +20 -11
  25. package/dist/eject-theme/components/Link/index.tsx +13 -4
  26. package/dist/eject-theme/components/Nav/NavMenu.tsx +2 -3
  27. package/dist/eject-theme/components/NavHamburger/index.tsx +3 -4
  28. package/dist/eject-theme/components/NavScreen/NavScreenMenuItem.tsx +2 -3
  29. package/dist/eject-theme/components/Overview/OverviewGroup.tsx +1 -2
  30. package/dist/eject-theme/components/Overview/index.tsx +6 -2
  31. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +12 -0
  32. package/dist/eject-theme/components/PrevNextPage/index.tsx +6 -3
  33. package/dist/eject-theme/components/Root/index.tsx +58 -0
  34. package/dist/eject-theme/components/Search/NoSearchResult.tsx +2 -3
  35. package/dist/eject-theme/components/Search/SearchButton.tsx +3 -4
  36. package/dist/eject-theme/components/Search/SearchPanel.tsx +12 -7
  37. package/dist/eject-theme/components/Search/SuggestItem.tsx +15 -12
  38. package/dist/eject-theme/components/Sidebar/SidebarGroup.tsx +2 -3
  39. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -0
  40. package/dist/eject-theme/components/SidebarMenu/index.tsx +4 -4
  41. package/dist/eject-theme/components/SocialLinks/index.tsx +2 -3
  42. package/dist/eject-theme/components/SourceCode/index.tsx +6 -4
  43. package/dist/eject-theme/components/SwitchAppearance/index.tsx +3 -5
  44. package/dist/eject-theme/components/Tabs/index.scss +19 -22
  45. package/dist/eject-theme/components/Toc/TocItem.scss +3 -3
  46. package/dist/eject-theme/components/Toc/TocItem.tsx +1 -0
  47. package/dist/index.d.ts +6 -6
  48. package/dist/index.js +16 -3134
  49. package/dist/node/PluginDriver.d.ts +1 -1
  50. package/dist/node/PluginDriver.js +143 -0
  51. package/dist/node/auto-nav-sidebar/index.js +44 -0
  52. package/dist/node/auto-nav-sidebar/locales.js +26 -0
  53. package/dist/node/auto-nav-sidebar/normalize.js +228 -0
  54. package/dist/node/auto-nav-sidebar/utils.js +68 -0
  55. package/dist/node/auto-nav-sidebar/walk.js +67 -0
  56. package/dist/node/build.js +31 -0
  57. package/dist/node/constants.d.ts +1 -0
  58. package/dist/node/constants.js +33 -0
  59. package/dist/node/dev.js +32 -0
  60. package/dist/node/eject.js +111 -0
  61. package/dist/node/index.d.ts +5 -5
  62. package/dist/node/initRsbuild.d.ts +2 -2
  63. package/dist/node/initRsbuild.js +338 -0
  64. package/dist/node/last-updated/index.js +28 -0
  65. package/dist/node/logger/hint.d.ts +1 -1
  66. package/dist/node/logger/hint.js +85 -0
  67. package/dist/node/mdx/loader.d.ts +1 -1
  68. package/dist/node/mdx/loader.e1578c62.js +13 -0
  69. package/dist/{loader.js → node/mdx/loader.js} +2 -2
  70. package/dist/node/mdx/options.d.ts +2 -2
  71. package/dist/node/mdx/options.js +100 -0
  72. package/dist/node/mdx/processor.d.ts +2 -2
  73. package/dist/node/mdx/processor.js +71 -0
  74. package/dist/node/mdx/rehypePlugins/codeMeta.js +10 -0
  75. package/dist/node/mdx/rehypePlugins/headerAnchor.js +53 -0
  76. package/dist/node/mdx/rehypePlugins/shiki.js +34 -0
  77. package/dist/node/mdx/rehypePlugins/transformers/add-lang.js +15 -0
  78. package/dist/node/mdx/rehypePlugins/transformers/add-line-numbers.js +22 -0
  79. package/dist/node/mdx/rehypePlugins/transformers/add-title.js +24 -0
  80. package/dist/node/mdx/rehypePlugins/transformers/add-wrap-code.js +22 -0
  81. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +5 -5
  82. package/dist/node/mdx/rehypePlugins/transformers/index.js +5 -0
  83. package/dist/node/mdx/rehypePlugins/transformers/meta-highlight.js +41 -0
  84. package/dist/node/mdx/remarkPlugins/builtin.js +11 -0
  85. package/dist/node/mdx/remarkPlugins/containerSyntax.js +190 -0
  86. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +66 -0
  87. package/dist/node/mdx/remarkPlugins/image.js +67 -0
  88. package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
  89. package/dist/node/mdx/remarkPlugins/link.js +99 -0
  90. package/dist/node/mdx/remarkPlugins/toc.js +50 -0
  91. package/dist/node/mdx/types.d.ts +3 -3
  92. package/dist/node/medium-zoom/index.d.ts +1 -1
  93. package/dist/node/medium-zoom/index.js +14 -0
  94. package/dist/node/route/RoutePage.d.ts +1 -1
  95. package/dist/node/route/RoutePage.js +61 -0
  96. package/dist/node/route/RouteService.d.ts +1 -1
  97. package/dist/node/route/RouteService.js +177 -0
  98. package/dist/node/route/extractPageData.d.ts +1 -1
  99. package/dist/node/route/extractPageData.js +112 -0
  100. package/dist/node/route/normalizeRoutePath.js +54 -0
  101. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
  102. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +150 -0
  103. package/dist/node/runtimeModule/globalStyles.d.ts +1 -1
  104. package/dist/node/runtimeModule/globalStyles.js +12 -0
  105. package/dist/node/runtimeModule/globalUIComponents.d.ts +1 -1
  106. package/dist/node/runtimeModule/globalUIComponents.js +25 -0
  107. package/dist/node/runtimeModule/i18n.d.ts +2 -2
  108. package/dist/node/runtimeModule/i18n.js +83 -0
  109. package/dist/node/runtimeModule/pageData/createPageData.d.ts +1 -1
  110. package/dist/node/runtimeModule/pageData/createPageData.js +64 -0
  111. package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
  112. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +51 -0
  113. package/dist/node/runtimeModule/routeList.d.ts +1 -1
  114. package/dist/node/runtimeModule/routeList.js +7 -0
  115. package/dist/node/runtimeModule/searchHooks.d.ts +1 -1
  116. package/dist/node/runtimeModule/searchHooks.js +11 -0
  117. package/dist/node/runtimeModule/siteData/createSiteData.js +34 -0
  118. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +94 -0
  119. package/dist/node/runtimeModule/siteData/rsbuildPlugin.d.ts +1 -1
  120. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +24 -0
  121. package/dist/node/runtimeModule/socialLinks.d.ts +1 -1
  122. package/dist/node/runtimeModule/socialLinks.js +8 -0
  123. package/dist/node/runtimeModule/types.d.ts +2 -2
  124. package/dist/node/serve.js +23 -0
  125. package/dist/node/ssg/renderHtmlTemplate.js +33 -0
  126. package/dist/node/ssg/renderPage.js +34 -0
  127. package/dist/node/ssg/renderPageWorker.474f9f73.js +2 -0
  128. package/dist/node/ssg/renderPageWorker.js +15 -0
  129. package/dist/node/ssg/renderPages.d.ts +1 -1
  130. package/dist/node/ssg/renderPages.js +105 -0
  131. package/dist/node/ssg/renderPages.js.LICENSE.txt +4 -0
  132. package/dist/node/ssg/rsbuildPluginCSR.d.ts +1 -1
  133. package/dist/node/ssg/rsbuildPluginCSR.js +27 -0
  134. package/dist/node/ssg/rsbuildPluginSSG.d.ts +1 -1
  135. package/dist/node/ssg/rsbuildPluginSSG.js +72 -0
  136. package/dist/node/ssg/ssgEnv.js +33 -0
  137. package/dist/node/ssg/ssgEnv.js.LICENSE.txt +5 -0
  138. package/dist/node/ssg-md/llms/emitLlmsTxt.d.ts +1 -1
  139. package/dist/node/ssg-md/llms/emitLlmsTxt.js +80 -0
  140. package/dist/node/ssg-md/llms/llmsTxt.d.ts +1 -1
  141. package/dist/node/ssg-md/llms/llmsTxt.js +66 -0
  142. package/dist/node/ssg-md/react/index.d.ts +1 -1
  143. package/dist/node/ssg-md/remarkSplitMdx.js +202 -0
  144. package/dist/node/ssg-md/renderPage.js +31 -0
  145. package/dist/node/ssg-md/renderPages.d.ts +1 -1
  146. package/dist/node/ssg-md/renderPages.js +27 -0
  147. package/dist/node/ssg-md/rsbuildPluginSSGMD.d.ts +1 -1
  148. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +47 -0
  149. package/dist/node/utils/applyReplaceRules.js +6 -0
  150. package/dist/node/utils/checkLanguageParity.js +77 -0
  151. package/dist/node/utils/createHash.js +5 -0
  152. package/dist/node/utils/error.d.ts +9 -0
  153. package/dist/node/utils/error.js +9 -0
  154. package/dist/node/utils/escapeHeadingIds.js +5 -0
  155. package/dist/node/utils/flattenMdxContent.js +74 -0
  156. package/dist/node/utils/fs.js +14 -0
  157. package/dist/node/utils/getImportAstNode.js +63 -0
  158. package/dist/node/utils/getPageKey.js +6 -0
  159. package/dist/node/utils/getSocialIcons.js +32 -0
  160. package/dist/node/utils/index.d.ts +10 -9
  161. package/dist/node/utils/normalizePath.js +10 -0
  162. package/dist/node/utils/reactAlias.d.ts +2 -0
  163. package/dist/node/utils/reactAlias.js +83 -0
  164. package/dist/rslib-runtime.99091bf6.js +18 -0
  165. package/dist/runtime/App.js +2 -2
  166. package/dist/runtime/ClientApp.d.ts +1 -1
  167. package/dist/runtime/ClientApp.js +0 -4
  168. package/dist/runtime/ssrMdServerEntry.js +1 -1
  169. package/dist/runtime/ssrServerEntry.js +2 -1
  170. package/dist/runtime.72d450ac.js +1 -0
  171. package/dist/runtime.js +3 -2
  172. package/dist/shiki-transformers.d.ts +1 -1
  173. package/dist/shiki-transformers.js +6 -120
  174. package/dist/theme/components/Banner/index.d.ts +1 -1
  175. package/dist/theme/components/Banner/index.js +2 -3
  176. package/dist/theme/components/Callout/index.css +0 -2
  177. package/dist/theme/components/CodeBlock/index.css +4 -15
  178. package/dist/theme/components/CodeBlock/index.js +1 -0
  179. package/dist/theme/components/CodeButtonGroup/CopyCodeButton.js +3 -5
  180. package/dist/theme/components/CodeButtonGroup/index.css +5 -1
  181. package/dist/theme/components/CodeButtonGroup/index.js +3 -5
  182. package/dist/theme/components/DocContent/doc.css +28 -7
  183. package/dist/theme/components/DocContent/docComponents/index.d.ts +3 -3
  184. package/dist/theme/components/DocContent/docComponents/table.d.ts +2 -2
  185. package/dist/theme/components/DocContent/docComponents/table.js +8 -3
  186. package/dist/theme/components/DocContent/index.js +2 -3
  187. package/dist/theme/components/{DocContent/FallbackHeading.js → FallbackHeading/index.js} +19 -11
  188. package/dist/theme/components/HoverGroup/useHoverGroup.d.ts +1 -1
  189. package/dist/theme/components/Link/index.js +9 -5
  190. package/dist/theme/components/Nav/NavMenu.js +2 -3
  191. package/dist/theme/components/NavHamburger/index.js +3 -4
  192. package/dist/theme/components/NavScreen/NavScreenMenuItem.js +2 -3
  193. package/dist/theme/components/Overview/OverviewGroup.js +1 -2
  194. package/dist/theme/components/Overview/index.js +1 -2
  195. package/dist/theme/components/PackageManagerTabs/index.d.ts +1 -1
  196. package/dist/theme/components/PackageManagerTabs/index.js +4 -0
  197. package/dist/theme/components/PrevNextPage/index.js +3 -4
  198. package/dist/theme/components/Root/index.d.ts +54 -0
  199. package/dist/theme/components/Root/index.js +7 -0
  200. package/dist/theme/components/Search/NoSearchResult.js +2 -3
  201. package/dist/theme/components/Search/SearchButton.js +3 -4
  202. package/dist/theme/components/Search/SearchPanel.js +12 -15
  203. package/dist/theme/components/Search/SuggestItem.d.ts +1 -1
  204. package/dist/theme/components/Search/SuggestItem.js +7 -11
  205. package/dist/theme/components/Search/logic/Provider.d.ts +1 -1
  206. package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +2 -2
  207. package/dist/theme/components/Search/logic/search.d.ts +1 -1
  208. package/dist/theme/components/Sidebar/SidebarGroup.js +2 -3
  209. package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
  210. package/dist/theme/components/SidebarMenu/index.js +3 -5
  211. package/dist/theme/components/SocialLinks/index.js +2 -3
  212. package/dist/theme/components/SourceCode/index.js +2 -4
  213. package/dist/theme/components/SwitchAppearance/index.js +3 -5
  214. package/dist/theme/components/Tabs/index.css +13 -22
  215. package/dist/theme/components/Toc/TocItem.css +2 -3
  216. package/dist/theme/components/Toc/TocItem.js +1 -0
  217. package/dist/theme/icons.d.ts +25 -0
  218. package/dist/theme/icons.js +47 -0
  219. package/dist/theme/index.d.ts +62 -59
  220. package/dist/theme/index.js +4 -1
  221. package/dist/theme/layout/DocLayout/index.css +2 -2
  222. package/dist/theme/logic/useFullTextSearch.d.ts +1 -1
  223. package/dist/theme/styles/scrollbar.css +1 -0
  224. package/dist/theme/styles/vars/base-vars.css +5 -3
  225. package/dist/theme/styles/vars/home-vars.css +2 -1
  226. package/package.json +17 -18
  227. package/dist/3~128.js +0 -74
  228. package/dist/3~517.js +0 -1786
  229. package/dist/3~894.js +0 -26
  230. package/dist/cli.js +0 -259
  231. package/dist/index.js.LICENSE.txt +0 -10
  232. package/dist/node/auto-nav-sidebar/fixtures/docs/guide/c.d.ts +0 -2
  233. package/dist/node/auto-nav-sidebar/fixtures/docs-locales/en/guide/c.d.ts +0 -2
  234. package/dist/node/auto-nav-sidebar/fixtures/docs-locales/zh/guide/c.d.ts +0 -2
  235. package/dist/node/auto-nav-sidebar/locales.test.d.ts +0 -1
  236. package/dist/node/auto-nav-sidebar/walk.test.d.ts +0 -1
  237. package/dist/node/mdx/rehypePlugins/headerAnchor.test.d.ts +0 -1
  238. package/dist/node/mdx/remarkPlugins/containerSyntax.test.d.ts +0 -1
  239. package/dist/node/mdx/remarkPlugins/fileCodeBlock.test.d.ts +0 -1
  240. package/dist/node/mdx/remarkPlugins/image.test.d.ts +0 -1
  241. package/dist/node/mdx/remarkPlugins/link.test.d.ts +0 -1
  242. package/dist/node/route/RouteService.test.d.ts +0 -1
  243. package/dist/node/route/extractPageData.test.d.ts +0 -1
  244. package/dist/node/route/fixtures/basic/guide/c.d.ts +0 -2
  245. package/dist/node/route/normalizeRoutePath.test.d.ts +0 -1
  246. package/dist/node/runtimeModule/i18n.test.d.ts +0 -1
  247. package/dist/node/ssg-md/remarkSplitMdx.test.d.ts +0 -4
  248. package/dist/node/utils/checkLanguageParity.test.d.ts +0 -1
  249. package/dist/node/utils/detectCustomIcon.d.ts +0 -1
  250. package/dist/node/utils/detectReactVersion.d.ts +0 -3
  251. package/dist/processor.js +0 -4539
  252. package/dist/renderPageWorker.js +0 -196
  253. package/dist/theme/components/Search/logic/util.test.d.ts +0 -1
  254. /package/dist/cli/{config.d.ts → config/index.d.ts} +0 -0
  255. /package/dist/{shiki-transformers.js.LICENSE.txt → node/mdx/rehypePlugins/transformers/meta-highlight.js.LICENSE.txt} +0 -0
  256. /package/dist/theme/components/{DocContent/FallbackHeading.d.ts → FallbackHeading/index.d.ts} +0 -0
@@ -0,0 +1,100 @@
1
+ import { node_path } from "../../6289.c67fe0d5.js";
2
+ import { nodeTypes } from "../../7805.cadab34e.js";
3
+ import { rehype_external_links, rehype_raw, remark_gfm, rehype } from "./loader.e1578c62.js";
4
+ import { remarkToc } from "./remarkPlugins/toc.js";
5
+ import { remarkContainerSyntax } from "./remarkPlugins/containerSyntax.js";
6
+ import { remarkFileCodeBlock } from "./remarkPlugins/fileCodeBlock.js";
7
+ import { remarkLink } from "./remarkPlugins/link.js";
8
+ import { remarkImage } from "./remarkPlugins/image.js";
9
+ import { remarkSplitMdx } from "../ssg-md/remarkSplitMdx.js";
10
+ import { remarkBuiltin } from "./remarkPlugins/builtin.js";
11
+ import { rehypeHeaderAnchor } from "./rehypePlugins/headerAnchor.js";
12
+ import { rehypeCodeMeta } from "./rehypePlugins/codeMeta.js";
13
+ import { createRehypeShikiOptions } from "./rehypePlugins/shiki.js";
14
+ async function createMDXOptions(options) {
15
+ const { docDirectory, config, routeService, filepath, pluginDriver, addDependency, isSsgMd = false } = options;
16
+ const remarkLinkOptions = config?.markdown?.link;
17
+ const format = node_path.extname(filepath).slice(1);
18
+ const { remarkPlugins: remarkPluginsFromConfig = [], rehypePlugins: rehypePluginsFromConfig = [], globalComponents: globalComponentsFromConfig = [], showLineNumbers = false, defaultWrapCode = false, shiki } = config?.markdown || {};
19
+ const rspressPlugins = pluginDriver?.getPlugins() ?? [];
20
+ const remarkPluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.remarkPlugins || []);
21
+ const rehypePluginsFromPlugins = rspressPlugins.flatMap((plugin)=>plugin.markdown?.rehypePlugins || []);
22
+ const globalComponents = [
23
+ ...rspressPlugins.flatMap((plugin)=>plugin.markdown?.globalComponents || []),
24
+ ...globalComponentsFromConfig
25
+ ];
26
+ return {
27
+ providerImportSource: '@mdx-js/react',
28
+ format,
29
+ remarkPlugins: [
30
+ remark_gfm,
31
+ remarkToc,
32
+ !isSsgMd && remarkContainerSyntax,
33
+ [
34
+ remarkFileCodeBlock,
35
+ {
36
+ filepath,
37
+ addDependency
38
+ }
39
+ ],
40
+ [
41
+ remarkLink,
42
+ isSsgMd ? {
43
+ cleanUrls: '.md',
44
+ root: docDirectory,
45
+ routeService,
46
+ remarkLinkOptions: {
47
+ checkDeadLinks: false,
48
+ autoPrefix: true
49
+ }
50
+ } : {
51
+ cleanUrls: false,
52
+ root: docDirectory,
53
+ routeService,
54
+ remarkLinkOptions
55
+ }
56
+ ],
57
+ remarkImage,
58
+ isSsgMd && [
59
+ remarkSplitMdx,
60
+ 'object' == typeof config?.llms ? config.llms.remarkSplitMdxOptions : void 0
61
+ ],
62
+ globalComponents.length && [
63
+ remarkBuiltin,
64
+ {
65
+ globalComponents
66
+ }
67
+ ],
68
+ ...remarkPluginsFromConfig,
69
+ ...remarkPluginsFromPlugins
70
+ ].filter(Boolean),
71
+ ...isSsgMd ? {} : {
72
+ rehypePlugins: [
73
+ rehypeHeaderAnchor,
74
+ ...'md' === format ? [
75
+ rehypeCodeMeta,
76
+ [
77
+ rehype_raw,
78
+ {
79
+ passThrough: nodeTypes
80
+ }
81
+ ]
82
+ ] : [],
83
+ [
84
+ rehype,
85
+ createRehypeShikiOptions(showLineNumbers, defaultWrapCode, shiki)
86
+ ],
87
+ [
88
+ rehype_external_links,
89
+ {
90
+ target: '_blank',
91
+ rel: 'noopener noreferrer'
92
+ }
93
+ ],
94
+ ...rehypePluginsFromConfig,
95
+ ...rehypePluginsFromPlugins
96
+ ]
97
+ }
98
+ };
99
+ }
100
+ export { createMDXOptions };
@@ -1,7 +1,7 @@
1
1
  import type { Rspack } from '@rsbuild/core';
2
2
  import type { UserConfig } from '@rspress/shared';
3
- import type { PluginDriver } from '../PluginDriver';
4
- import type { RouteService } from '../route/RouteService';
3
+ import type { PluginDriver } from '../PluginDriver.js';
4
+ import type { RouteService } from '../route/RouteService.js';
5
5
  interface CompileOptions {
6
6
  source: string;
7
7
  filepath: string;
@@ -0,0 +1,71 @@
1
+ import { node_path } from "../../6289.c67fe0d5.js";
2
+ import { createProcessor, loadFrontMatter, extractTextAndId } from "../../7805.cadab34e.js";
3
+ import { createMDXOptions } from "./options.js";
4
+ import { applyReplaceRules } from "../utils/applyReplaceRules.js";
5
+ import { escapeMarkdownHeadingIds } from "../utils/escapeHeadingIds.js";
6
+ import { normalizePath } from "../utils/normalizePath.js";
7
+ import { createError } from "../utils/error.js";
8
+ async function compile(options) {
9
+ const { source, filepath, docDirectory, config, routeService, pluginDriver, addDependency, isSsgMd = false } = options;
10
+ const mdxOptions = await createMDXOptions({
11
+ config,
12
+ docDirectory,
13
+ filepath,
14
+ pluginDriver,
15
+ routeService,
16
+ addDependency,
17
+ isSsgMd
18
+ });
19
+ const { frontmatter, emptyLinesSource } = loadFrontMatter(source, filepath, docDirectory, true);
20
+ const { replaceRules } = config ?? {};
21
+ const replacedSource = applyReplaceRules(emptyLinesSource, replaceRules);
22
+ const preprocessedContent = escapeMarkdownHeadingIds(replacedSource);
23
+ try {
24
+ let pageMeta = {
25
+ title: '',
26
+ toc: [],
27
+ headingTitle: ''
28
+ };
29
+ const frontmatterTitle = extractTextAndId(frontmatter.title)[0];
30
+ const compiler = createProcessor(mdxOptions);
31
+ compiler.data('pageMeta', {
32
+ toc: [],
33
+ title: ''
34
+ });
35
+ const vFile = await compiler.process({
36
+ value: preprocessedContent,
37
+ path: filepath
38
+ });
39
+ const compileResult = String(vFile);
40
+ const compilationMeta = compiler.data('pageMeta');
41
+ const headingTitle = extractTextAndId(compilationMeta.title)[0];
42
+ pageMeta = {
43
+ ...compilationMeta,
44
+ title: frontmatterTitle || headingTitle,
45
+ headingTitle,
46
+ frontmatter
47
+ };
48
+ const result = `${compileResult}
49
+
50
+ MDXContent.__RSPRESS_PAGE_META = {};
51
+ MDXContent.__RSPRESS_PAGE_META["${encodeURIComponent(normalizePath(node_path.relative(docDirectory, filepath)))}"] = ${JSON.stringify(pageMeta)};
52
+ `;
53
+ return result;
54
+ } catch (e) {
55
+ if (e instanceof Error) throw e;
56
+ throw createError(`MDX compile error: ${e} in ${filepath}`);
57
+ }
58
+ }
59
+ const cache = new Map();
60
+ async function compileWithCrossCompilerCache(options) {
61
+ const filepath = options.filepath;
62
+ const task = cache.get(filepath);
63
+ if (task) {
64
+ cache.delete(filepath);
65
+ return task;
66
+ }
67
+ const promise = compile(options);
68
+ cache.set(filepath, promise);
69
+ return promise;
70
+ }
71
+ export { compile, compileWithCrossCompilerCache };
@@ -0,0 +1,10 @@
1
+ import { visit } from "../../../8813.9da1f210.js";
2
+ const rehypeCodeMeta = ()=>(tree)=>{
3
+ visit(tree, 'element', (node)=>{
4
+ if ('pre' === node.tagName && node.children[0]?.type === 'element' && 'code' === node.children[0].tagName) {
5
+ const codeNode = node.children[0];
6
+ codeNode.properties.metastring = codeNode.data?.meta;
7
+ }
8
+ });
9
+ };
10
+ export { rehypeCodeMeta };
@@ -0,0 +1,53 @@
1
+ import { extractTextAndId } from "../../../7805.cadab34e.js";
2
+ import { github_slugger, headingRank } from "../loader.e1578c62.js";
3
+ import { visit } from "../../../8813.9da1f210.js";
4
+ const rehypeHeaderAnchor = ()=>{
5
+ const slugger = new github_slugger();
6
+ return (tree)=>{
7
+ visit(tree, 'element', (node)=>{
8
+ if (!headingRank(node)) return;
9
+ if (!node.properties?.id) {
10
+ const [text, customId] = collectHeaderText(node);
11
+ node.properties ??= {};
12
+ node.properties.id = customId || slugger.slug(text.trim());
13
+ }
14
+ node.children.unshift(create(node));
15
+ });
16
+ };
17
+ };
18
+ const collectHeaderText = (node)=>{
19
+ let text = '';
20
+ let id = '';
21
+ node.children.forEach((child)=>{
22
+ if ('text' === child.type) {
23
+ const [textPart, idPart] = extractTextAndId(child.value);
24
+ child.value = textPart;
25
+ text += textPart;
26
+ id = idPart;
27
+ } else if ('element' === child.type) child.children.forEach((c)=>{
28
+ if ('text' === c.type) text += c.value;
29
+ });
30
+ });
31
+ return [
32
+ text,
33
+ id
34
+ ];
35
+ };
36
+ function create(node) {
37
+ return {
38
+ type: 'element',
39
+ tagName: 'a',
40
+ properties: {
41
+ class: 'rp-header-anchor',
42
+ ariaHidden: 'true',
43
+ href: `#${node.properties.id}`
44
+ },
45
+ children: [
46
+ {
47
+ type: 'text',
48
+ value: '#'
49
+ }
50
+ ]
51
+ };
52
+ }
53
+ export { collectHeaderText, rehypeHeaderAnchor };
@@ -0,0 +1,34 @@
1
+ import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, createCssVariablesTheme, transformerAddWrapCode } from "../loader.e1578c62.js";
2
+ const cssVariablesTheme = createCssVariablesTheme({
3
+ name: 'css-variables',
4
+ variablePrefix: '--shiki-',
5
+ variableDefaults: {},
6
+ fontStyle: true
7
+ });
8
+ function createRehypeShikiOptions(showLineNumbers, defaultWrapCode, options) {
9
+ const { transformers = [], ...restOptions } = options || {};
10
+ const newTransformers = [
11
+ transformerAddTitle(),
12
+ transformerAddLang(),
13
+ transformerAddLineNumbers({
14
+ defaultShowLineNumbers: showLineNumbers
15
+ }),
16
+ transformerAddWrapCode({
17
+ defaultWrapCode
18
+ }),
19
+ ...transformers
20
+ ];
21
+ return {
22
+ theme: cssVariablesTheme,
23
+ defaultLanguage: 'txt',
24
+ lazy: true,
25
+ langs: [
26
+ 'tsx',
27
+ 'ts',
28
+ 'js'
29
+ ],
30
+ ...restOptions,
31
+ transformers: newTransformers
32
+ };
33
+ }
34
+ export { createRehypeShikiOptions };
@@ -0,0 +1,15 @@
1
+ const SHIKI_TRANSFORMER_ADD_LANG = 'shiki-transformer:add-lang';
2
+ function transformerAddLang() {
3
+ return {
4
+ name: SHIKI_TRANSFORMER_ADD_LANG,
5
+ pre (pre) {
6
+ const lang = this.options.lang;
7
+ if (lang.length > 0) pre.properties = {
8
+ ...pre.properties,
9
+ lang
10
+ };
11
+ return pre;
12
+ }
13
+ };
14
+ }
15
+ export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang };
@@ -0,0 +1,22 @@
1
+ const SHIKI_TRANSFORMER_ADD_LINE_NUMBERS = 'shiki-transformer:add-line-numbers';
2
+ function hasLineNumbersInMeta(meta) {
3
+ if (!meta) return;
4
+ const kvList = meta.split(' ').filter(Boolean);
5
+ return kvList.includes('lineNumbers');
6
+ }
7
+ function transformerAddLineNumbers(options = {}) {
8
+ const { defaultShowLineNumbers = false } = options;
9
+ return {
10
+ name: SHIKI_TRANSFORMER_ADD_LINE_NUMBERS,
11
+ pre (pre) {
12
+ const metaHasLineNumbers = hasLineNumbersInMeta(this.options.meta?.__raw);
13
+ const shouldShowLineNumbers = metaHasLineNumbers ?? defaultShowLineNumbers;
14
+ if (shouldShowLineNumbers) pre.properties = {
15
+ ...pre.properties,
16
+ lineNumbers: shouldShowLineNumbers
17
+ };
18
+ return pre;
19
+ }
20
+ };
21
+ }
22
+ export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers };
@@ -0,0 +1,24 @@
1
+ const SHIKI_TRANSFORMER_ADD_TITLE = 'shiki-transformer:add-title';
2
+ function parseTitleFromMeta(meta) {
3
+ if (!meta) return '';
4
+ const kvList = meta.split(' ').filter(Boolean);
5
+ for (const item of kvList){
6
+ const [k, v = ''] = item.split('=').filter(Boolean);
7
+ if ('title' === k && v.length > 0) return v.replace(/["'`]/g, '');
8
+ }
9
+ return '';
10
+ }
11
+ function transformerAddTitle() {
12
+ return {
13
+ name: SHIKI_TRANSFORMER_ADD_TITLE,
14
+ pre (pre) {
15
+ const title = parseTitleFromMeta(this.options.meta?.__raw);
16
+ if (title.length > 0) pre.properties = {
17
+ ...pre.properties,
18
+ title
19
+ };
20
+ return pre;
21
+ }
22
+ };
23
+ }
24
+ export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle };
@@ -0,0 +1,22 @@
1
+ const SHIKI_TRANSFORMER_ADD_WRAP_CODE = 'shiki-transformer:wrap-code';
2
+ function hasWrapCodeInMeta(meta) {
3
+ if (!meta) return;
4
+ const kvList = meta.split(' ').filter(Boolean);
5
+ return kvList.includes('wrapCode');
6
+ }
7
+ function transformerAddWrapCode(options = {}) {
8
+ const { defaultWrapCode = false } = options;
9
+ return {
10
+ name: SHIKI_TRANSFORMER_ADD_WRAP_CODE,
11
+ pre (pre) {
12
+ const metaHasWrapCode = hasWrapCodeInMeta(this.options.meta?.__raw);
13
+ const shouldWrapCode = metaHasWrapCode ?? defaultWrapCode;
14
+ if (shouldWrapCode) pre.properties = {
15
+ ...pre.properties,
16
+ wrapCode: true
17
+ };
18
+ return pre;
19
+ }
20
+ };
21
+ }
22
+ export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode };
@@ -1,5 +1,5 @@
1
- export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from './add-lang';
2
- export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers, } from './add-line-numbers';
3
- export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from './add-title';
4
- export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode, } from './add-wrap-code';
5
- export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight, } from './meta-highlight';
1
+ export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from './add-lang.js';
2
+ export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers, } from './add-line-numbers.js';
3
+ export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from './add-title.js';
4
+ export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode, } from './add-wrap-code.js';
5
+ export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight, } from './meta-highlight.js';
@@ -0,0 +1,5 @@
1
+ export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from "./add-lang.js";
2
+ export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers } from "./add-line-numbers.js";
3
+ export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from "./add-title.js";
4
+ export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode } from "./add-wrap-code.js";
5
+ export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight } from "./meta-highlight.js";
@@ -0,0 +1,41 @@
1
+ /*! For license information please see meta-highlight.js.LICENSE.txt */
2
+ /**
3
+ * these codes are copied from @shiki/transformers, transformerMetaHighlight
4
+ * @source https://github.com/shikijs/shiki/blob/f5cf06f55a0b4643d7b02f15ee2c5033be6f1245/packages/transformers/src/transformers/meta-highlight.ts#L56
5
+ * @license MIT
6
+ */ function parseMetaHighlightString(meta) {
7
+ if (!meta) return null;
8
+ const match = meta.match(/\{([\d,-]+)\}/);
9
+ if (!match) return null;
10
+ const lines = match[1].split(',').flatMap((v)=>{
11
+ const num = v.split('-').map((v)=>Number.parseInt(v, 10));
12
+ if (1 === num.length) return [
13
+ num[0]
14
+ ];
15
+ return Array.from({
16
+ length: num[1] - num[0] + 1
17
+ }, (_, i)=>i + num[0]);
18
+ });
19
+ return lines;
20
+ }
21
+ const symbol = Symbol('highlighted-lines');
22
+ const SHIKI_TRANSFORMER_META_HIGHLIGHT = 'shiki-transformer:compatible-meta-highlight';
23
+ function transformerCompatibleMetaHighlight(options = {}) {
24
+ const { classActiveLine = 'highlighted', classActivePre = 'has-highlighted' } = options;
25
+ return {
26
+ name: '@shikijs/transformers:meta-highlight',
27
+ line (node, line) {
28
+ if (!this.options.meta?.__raw) return;
29
+ const meta = this.meta;
30
+ meta[symbol] ??= parseMetaHighlightString(this.options.meta.__raw);
31
+ const lines = meta[symbol] ?? [];
32
+ if (lines.includes(line)) this.addClassToHast(node, classActiveLine);
33
+ return node;
34
+ },
35
+ pre (hast) {
36
+ this.addClassToHast(hast, classActivePre);
37
+ return hast;
38
+ }
39
+ };
40
+ }
41
+ export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight };
@@ -0,0 +1,11 @@
1
+ import { node_path } from "../../../6289.c67fe0d5.js";
2
+ import { getDefaultImportAstNode } from "../../utils/getImportAstNode.js";
3
+ const remarkBuiltin = ({ globalComponents })=>(tree)=>{
4
+ const demos = globalComponents.map((componentPath)=>{
5
+ const filename = node_path.parse(componentPath).name;
6
+ const componentName = filename[0].toUpperCase() + filename.slice(1);
7
+ return getDefaultImportAstNode(componentName, componentPath);
8
+ });
9
+ tree.children.unshift(...demos);
10
+ };
11
+ export { remarkBuiltin };
@@ -0,0 +1,190 @@
1
+ import { getNamedImportAstNode } from "../../utils/getImportAstNode.js";
2
+ const DIRECTIVE_TYPES = [
3
+ 'tip',
4
+ 'note',
5
+ 'warning',
6
+ 'caution',
7
+ 'danger',
8
+ 'info',
9
+ 'details'
10
+ ];
11
+ const REGEX_BEGIN = /^\s*:::\s*(\w+)\s*(.*)?/;
12
+ const REGEX_END = /\s*:::$/;
13
+ const REGEX_GH_BEGIN = /^\s*\s*\[!(\w+)\]\s*(.*)?/;
14
+ const TITLE_REGEX_IN_MD = /{\s*title=["']?(.+)}\s*/;
15
+ const TITLE_REGEX_IN_MDX = /\s*title=["']?(.+)\s*/;
16
+ const CALLOUT_COMPONENT = '$$$callout$$$';
17
+ const trimTailingQuote = (str)=>str.replace(/['"]$/g, '');
18
+ const parseTitle = (rawTitle = '', isMDX = false)=>{
19
+ const matched = rawTitle?.match(isMDX ? TITLE_REGEX_IN_MDX : TITLE_REGEX_IN_MD);
20
+ return trimTailingQuote(matched?.[1] || rawTitle);
21
+ };
22
+ const getTypeName = (type)=>type[0].toUpperCase() + type.slice(1).toLowerCase();
23
+ const createContainer = (type, title, children)=>({
24
+ type: 'containerDirective',
25
+ name: CALLOUT_COMPONENT,
26
+ attributes: {
27
+ type: type,
28
+ title: title || getTypeName(type)
29
+ },
30
+ data: {
31
+ hName: CALLOUT_COMPONENT,
32
+ hProperties: {
33
+ type: type,
34
+ title: title || getTypeName(type)
35
+ }
36
+ },
37
+ children: children
38
+ });
39
+ function transformer(tree, warnUnknownType) {
40
+ let i = 0;
41
+ while(i < tree.children.length){
42
+ const node = tree.children[i];
43
+ if ('children' in node) transformer(node, warnUnknownType);
44
+ if ('containerDirective' === node.type) {
45
+ const type = node.name;
46
+ if (type === CALLOUT_COMPONENT) {
47
+ i++;
48
+ continue;
49
+ }
50
+ if (DIRECTIVE_TYPES.includes(type)) tree.children.splice(i, 1, createContainer(type, node.attributes?.title ?? type.toUpperCase(), node.children));
51
+ else warnUnknownType(type);
52
+ } else if ('blockquote' === node.type && node.children[0]?.type === 'paragraph' && node.children[0].children?.[0] && 'value' in node.children[0].children[0]) {
53
+ const initiatorTag = node.children[0].children[0].value;
54
+ const match = initiatorTag.match(REGEX_GH_BEGIN);
55
+ if (match) {
56
+ const [, type] = match;
57
+ if (!DIRECTIVE_TYPES.includes(type.toLowerCase())) {
58
+ warnUnknownType(type);
59
+ i++;
60
+ continue;
61
+ }
62
+ if (1 === node.children.length && 'paragraph' === node.children[0].type) node.children[0].children[0].value = match[2] ?? '';
63
+ const newChild = createContainer(type.toLowerCase(), type.toUpperCase(), 0 === node.children.slice(1).length ? node.children.slice(0) : node.children.slice(1));
64
+ tree.children.splice(i, 1, newChild);
65
+ }
66
+ }
67
+ if ('paragraph' !== node.type || 'text' !== node.children[0].type) {
68
+ i++;
69
+ continue;
70
+ }
71
+ const firstTextNode = node.children[0];
72
+ const text = firstTextNode.value;
73
+ const metaText = text.split('\n')[0];
74
+ const content = text.slice(metaText.length);
75
+ const match = metaText.match(REGEX_BEGIN);
76
+ if (!match) {
77
+ i++;
78
+ continue;
79
+ }
80
+ const [, type, rawTitle] = match;
81
+ let title = parseTitle(rawTitle);
82
+ const titleExpressionNode = node.children[1] && 'mdxTextExpression' === node.children[1].type ? node.children[1] : null;
83
+ if (titleExpressionNode) {
84
+ title = parseTitle(titleExpressionNode.value, true);
85
+ node.children.splice(1, 1);
86
+ }
87
+ if (!DIRECTIVE_TYPES.includes(type)) {
88
+ warnUnknownType(type);
89
+ i++;
90
+ continue;
91
+ }
92
+ const wrappedChildren = [];
93
+ if (content?.endsWith(':::')) {
94
+ wrappedChildren.push({
95
+ type: 'paragraph',
96
+ children: [
97
+ {
98
+ type: 'text',
99
+ value: content.replace(REGEX_END, '')
100
+ }
101
+ ]
102
+ });
103
+ const newChild = createContainer(type, title, wrappedChildren);
104
+ tree.children.splice(i, 1, newChild);
105
+ } else {
106
+ const paragraphChild = {
107
+ type: 'paragraph',
108
+ children: []
109
+ };
110
+ wrappedChildren.push(paragraphChild);
111
+ if (content.length) paragraphChild.children.push({
112
+ type: 'text',
113
+ value: content
114
+ });
115
+ paragraphChild.children.push(...node.children.slice(1, -1));
116
+ if (0 === paragraphChild.children.length) wrappedChildren.pop();
117
+ const lastChildInNode = node.children[node.children.length - 1];
118
+ if ('text' === lastChildInNode.type && REGEX_END.test(lastChildInNode.value)) {
119
+ const lastChildInNodeText = lastChildInNode.value;
120
+ const matchedEndContent = lastChildInNodeText.slice(0, -3).trimEnd();
121
+ if (wrappedChildren.length) wrappedChildren[0].children.push({
122
+ type: 'text',
123
+ value: matchedEndContent
124
+ });
125
+ else if (matchedEndContent) wrappedChildren.push({
126
+ type: 'paragraph',
127
+ children: [
128
+ {
129
+ type: 'text',
130
+ value: matchedEndContent
131
+ }
132
+ ]
133
+ });
134
+ const newChild = createContainer(type, title, wrappedChildren);
135
+ tree.children.splice(i, 1, newChild);
136
+ i++;
137
+ continue;
138
+ }
139
+ if (lastChildInNode !== firstTextNode && wrappedChildren.length) wrappedChildren[0].children.push(lastChildInNode);
140
+ let j = i + 1;
141
+ while(j < tree.children.length){
142
+ const currentParagraph = tree.children[j];
143
+ if ('paragraph' !== currentParagraph.type) {
144
+ wrappedChildren.push(currentParagraph);
145
+ j++;
146
+ continue;
147
+ }
148
+ const lastChild = currentParagraph.children[currentParagraph.children.length - 1];
149
+ if (lastChild === firstTextNode || 'text' === lastChild.type && REGEX_END.test(lastChild.value)) {
150
+ const lastChildText = lastChild.value;
151
+ const matchedEndContent = lastChildText.slice(0, -3).trimEnd();
152
+ const filteredChildren = currentParagraph.children.filter((child)=>child !== firstTextNode && child !== lastChild);
153
+ if (matchedEndContent) wrappedChildren.push({
154
+ type: 'paragraph',
155
+ children: [
156
+ ...filteredChildren,
157
+ {
158
+ type: 'text',
159
+ value: matchedEndContent
160
+ }
161
+ ]
162
+ });
163
+ else wrappedChildren.push(...filteredChildren);
164
+ const newChild = createContainer(type, title, wrappedChildren);
165
+ tree.children.splice(i, j - i + 1, newChild);
166
+ break;
167
+ }
168
+ wrappedChildren.push({
169
+ ...currentParagraph,
170
+ children: currentParagraph.children.filter((child)=>child !== firstTextNode)
171
+ });
172
+ j++;
173
+ }
174
+ }
175
+ i++;
176
+ }
177
+ }
178
+ const remarkContainerSyntax = ()=>{
179
+ const unknownTypes = new Set();
180
+ const warnUnknownType = (type)=>{
181
+ if (!type || type === CALLOUT_COMPONENT) return;
182
+ if (unknownTypes.has(type)) return;
183
+ unknownTypes.add(type);
184
+ };
185
+ return (tree)=>{
186
+ transformer(tree, warnUnknownType);
187
+ tree.children.unshift(getNamedImportAstNode('Callout', CALLOUT_COMPONENT, '@theme'));
188
+ };
189
+ };
190
+ export { DIRECTIVE_TYPES, REGEX_BEGIN, REGEX_END, REGEX_GH_BEGIN, TITLE_REGEX_IN_MD, TITLE_REGEX_IN_MDX, remarkContainerSyntax };