@alauda/doom 0.14.21 → 0.15.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/lib/cli/index.js CHANGED
@@ -35,6 +35,7 @@ program
35
35
  2. translate ignore hash equality check and original text`, (value) => !!value && value !== 'false', false)
36
36
  .option('-i, --ignore [boolean]', 'Ignore internal routes', (value) => !!value && value !== 'false', false)
37
37
  .option('-d, --download [boolean]', 'Display download pdf link on nav bar', (value) => !!value && value !== 'false', false)
38
+ .option('--no-open [boolean]', 'Do not open the browser after starting the server')
38
39
  .command('dev', { isDefault: true })
39
40
  .description('Start the development server')
40
41
  .argument('[root]', 'Root directory of the documentation')
@@ -1,6 +1,6 @@
1
1
  import { type UserConfig } from '@rspress/core';
2
2
  import type { GlobalCliOptions } from '../types.js';
3
- export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, ignore, force, }?: GlobalCliOptions): Promise<{
3
+ export declare function loadConfig(root?: string, { config: configFile, base, prefix, v: version, download, ignore, force, open, }?: GlobalCliOptions): Promise<{
4
4
  config: UserConfig;
5
5
  filepath?: string;
6
6
  }>;
@@ -19,7 +19,7 @@ const zhLocaleConfig = {
19
19
  prevPageText: '上一页',
20
20
  nextPageText: '下一页',
21
21
  };
22
- const getCommonConfig = ({ config, root, configFilePath, base, version, download, ignore, force, }) => {
22
+ const getCommonConfig = ({ config, root, configFilePath, base, version, download, ignore, force, open, }) => {
23
23
  const fallbackToZh = 'lang' in config && !config.lang;
24
24
  root = resolveDocRoot(CWD, root, config.root);
25
25
  const localBasePath = configFilePath ? path.dirname(configFilePath) : root;
@@ -84,7 +84,18 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
84
84
  force,
85
85
  }),
86
86
  shikiPlugin({
87
- langs: ['dockerfile', 'dotenv', 'html', 'go', 'jsonc', 'mermaid'],
87
+ theme: config.shiki?.theme,
88
+ langs: [
89
+ 'dockerfile',
90
+ 'dotenv',
91
+ 'html',
92
+ 'go',
93
+ 'jsonc',
94
+ 'mermaid',
95
+ 'java',
96
+ 'python',
97
+ ...(config.shiki?.langs ?? []),
98
+ ],
88
99
  transformers: [
89
100
  // builtin transformers
90
101
  transformerMetaHighlight(),
@@ -97,13 +108,14 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
97
108
  transformerRemoveNotationEscape(),
98
109
  // custom transformers
99
110
  createTransformerCallouts(),
111
+ ...(config.shiki?.transformers ?? []),
100
112
  ],
101
113
  }),
102
114
  ],
103
115
  builderConfig: {
104
116
  plugins: [pluginYaml()],
105
117
  server: {
106
- open: true,
118
+ open,
107
119
  },
108
120
  tools: {
109
121
  rspack: {
@@ -120,7 +132,7 @@ const getCommonConfig = ({ config, root, configFilePath, base, version, download
120
132
  const findConfig = (basePath) => {
121
133
  return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
122
134
  };
123
- export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, ignore, force, } = {}) {
135
+ export async function loadConfig(root, { config: configFile, base, prefix, v: version, download, ignore, force, open, } = {}) {
124
136
  let configFilePath;
125
137
  if (configFile) {
126
138
  configFilePath = path.resolve(configFile);
@@ -179,6 +191,7 @@ export async function loadConfig(root, { config: configFile, base, prefix, v: ve
179
191
  download,
180
192
  ignore,
181
193
  force,
194
+ open,
182
195
  });
183
196
  base = commonConfig.base;
184
197
  const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
@@ -1,5 +1,6 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
  import { fromHtml } from 'hast-util-from-html';
3
+ import { logger } from '@rspress/shared/logger';
3
4
  // TODO: migrate to official @shikijs/rehype plugin after upgrading unified/remark/rehype packages
4
5
  export const rehypePluginShiki = ({ highlighter, theme }) => (tree) => {
5
6
  visit(tree, 'element', (node, index, parent) => {
@@ -16,13 +17,27 @@ export const rehypePluginShiki = ({ highlighter, theme }) => (tree) => {
16
17
  if (!lang) {
17
18
  return;
18
19
  }
19
- const highlightedCode = highlighter.codeToHtml(codeContent, {
20
- lang,
21
- theme,
22
- meta: {
23
- __raw: codeMeta,
24
- },
25
- });
20
+ let highlightedCode;
21
+ try {
22
+ highlightedCode = highlighter.codeToHtml(codeContent, {
23
+ lang,
24
+ theme,
25
+ meta: {
26
+ __raw: codeMeta,
27
+ },
28
+ });
29
+ }
30
+ catch (err) {
31
+ logger.error(`render with \`${lang}\` results error`, err);
32
+ logger.warn('fallback to `plaintext`');
33
+ highlightedCode = highlighter.codeToHtml(codeContent, {
34
+ lang: 'plaintext',
35
+ theme,
36
+ meta: {
37
+ __raw: codeMeta,
38
+ },
39
+ });
40
+ }
26
41
  const fragmentAst = fromHtml(highlightedCode, { fragment: true });
27
42
  const preElement = fragmentAst.children[0];
28
43
  const codeElement = preElement.children[0];
package/lib/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { serve } from '@rspress/core';
2
- import type { ApiPluginOptions, AutoSidebarPluginOptions, PermissionPluginOptions, ReferenceItem, ReleaseNotesOptions } from './plugins/index.js';
2
+ import type { ApiPluginOptions, AutoSidebarPluginOptions, PermissionPluginOptions, PluginShikiOptions, ReferenceItem, ReleaseNotesOptions } from './plugins/index.js';
3
3
  import type { DoomSite } from './shared/index.js';
4
4
  export type BaseServeOptions = Parameters<typeof serve>[0];
5
5
  export type ServeOptions = Omit<BaseServeOptions, 'config'>;
@@ -11,6 +11,7 @@ export interface GlobalCliOptions {
11
11
  download?: boolean;
12
12
  ignore?: boolean;
13
13
  force?: boolean;
14
+ open?: boolean;
14
15
  }
15
16
  export interface TranslateOptions {
16
17
  systemPrompt?: string;
@@ -27,6 +28,7 @@ declare module '@rspress/shared' {
27
28
  releaseNotes?: ReleaseNotesOptions;
28
29
  internalRoutes?: string[];
29
30
  translate?: TranslateOptions;
31
+ shiki?: PluginShikiOptions;
30
32
  }
31
33
  }
32
34
  export type ContentProcessor = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.14.21",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {