@alauda/doom 0.17.4 → 0.17.6
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/helpers.d.ts +6 -0
- package/lib/cli/helpers.js +12 -0
- package/lib/cli/html-export-pdf/core/outline.js +3 -2
- package/lib/cli/html-export-pdf/core/postprocesser.js +1 -3
- package/lib/cli/html-export-pdf/core/printer.js +1 -1
- package/lib/cli/translate.d.ts +1 -1
- package/lib/cli/translate.js +7 -5
- package/lib/types.d.ts +1 -0
- package/package.json +11 -11
package/lib/cli/helpers.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export declare const parseBoolean: (value: string) => boolean;
|
|
2
2
|
export declare const getMatchedDocFilePaths: (matched: string[]) => Promise<(string | string[])[]>;
|
|
3
|
+
/**
|
|
4
|
+
* Support custom id like `#hello world {#custom-id}`
|
|
5
|
+
* Avoid https://mdxjs.com/docs/troubleshooting-mdx/#could-not-parse-expression-with-acorn-error
|
|
6
|
+
* {@link https://github.com/web-infra-dev/rspress/blob/f3e6544780a371d7c629d8784f31dbcf28fb2b07/packages/core/src/node/utils/escapeHeadingIds.ts}
|
|
7
|
+
*/
|
|
8
|
+
export declare function escapeMarkdownHeadingIds(content: string): string;
|
package/lib/cli/helpers.js
CHANGED
|
@@ -15,3 +15,15 @@ export const getMatchedDocFilePaths = (matched) => Promise.all(matched.map(async
|
|
|
15
15
|
}
|
|
16
16
|
return [];
|
|
17
17
|
}));
|
|
18
|
+
/**
|
|
19
|
+
* Support custom id like `#hello world {#custom-id}`
|
|
20
|
+
* Avoid https://mdxjs.com/docs/troubleshooting-mdx/#could-not-parse-expression-with-acorn-error
|
|
21
|
+
* {@link https://github.com/web-infra-dev/rspress/blob/f3e6544780a371d7c629d8784f31dbcf28fb2b07/packages/core/src/node/utils/escapeHeadingIds.ts}
|
|
22
|
+
*/
|
|
23
|
+
export function escapeMarkdownHeadingIds(content) {
|
|
24
|
+
const markdownHeadingRegexp = /(?:^|\n)#{1,6}(?!#).*/g;
|
|
25
|
+
return content.replace(markdownHeadingRegexp, (substring) => substring
|
|
26
|
+
.replace('{#', '\\{#')
|
|
27
|
+
// prevent duplicate escaping
|
|
28
|
+
.replace('\\\\{#', '\\{#'));
|
|
29
|
+
}
|
|
@@ -137,8 +137,8 @@ function countChildrenOfOutline(outlines) {
|
|
|
137
137
|
*/
|
|
138
138
|
function buildPdfObjectsForOutline(outlinesWithRef, context) {
|
|
139
139
|
for (const [i, item] of outlinesWithRef.entries()) {
|
|
140
|
-
const prev = outlinesWithRef
|
|
141
|
-
const next = outlinesWithRef
|
|
140
|
+
const prev = outlinesWithRef.at(i - 1);
|
|
141
|
+
const next = outlinesWithRef.at(i + 1);
|
|
142
142
|
const pdfObject = new Map();
|
|
143
143
|
pdfObject.set(PDFName.of('Title'), PDFHexString.fromText(decode(item.title)));
|
|
144
144
|
pdfObject.set(PDFName.of('Dest'), PDFName.of(item.destination));
|
|
@@ -175,6 +175,7 @@ function buildPdfObjectsForOutline(outlinesWithRef, context) {
|
|
|
175
175
|
function generateWarningsAboutMissingDestinations(layer, pdfDoc) {
|
|
176
176
|
const dests = pdfDoc.context.lookup(pdfDoc.catalog.get(PDFName.of('Dests')), PDFDict);
|
|
177
177
|
// Dests can be undefined if the PDF wasn't successfully generated (for instance if Paged.js threw an exception)
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
178
179
|
if (!dests) {
|
|
179
180
|
return;
|
|
180
181
|
}
|
|
@@ -71,7 +71,7 @@ export class Printer extends EventEmitter {
|
|
|
71
71
|
if (this.allowLocal) {
|
|
72
72
|
browserOptions.args.push('--allow-file-access-from-files');
|
|
73
73
|
}
|
|
74
|
-
if (this.browserArgs) {
|
|
74
|
+
if (this.browserArgs.length) {
|
|
75
75
|
browserOptions.args.push(...this.browserArgs);
|
|
76
76
|
}
|
|
77
77
|
if (this.browserWSEndpoint) {
|
package/lib/cli/translate.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface InternalTranslateOptions extends TranslateOptions {
|
|
|
16
16
|
targetContent?: string;
|
|
17
17
|
additionalPrompts?: string;
|
|
18
18
|
}
|
|
19
|
-
export declare const translate: ({ source, sourceContent, target, targetContent, systemPrompt, additionalPrompts, }: InternalTranslateOptions) => Promise<string>;
|
|
19
|
+
export declare const translate: ({ source, sourceContent, target, targetContent, systemPrompt, userPrompt, additionalPrompts, }: InternalTranslateOptions) => Promise<string>;
|
|
20
20
|
export interface TranslateCommandOptions {
|
|
21
21
|
source: string;
|
|
22
22
|
target: string;
|
package/lib/cli/translate.js
CHANGED
|
@@ -15,7 +15,7 @@ import { glob } from 'tinyglobby';
|
|
|
15
15
|
import { cyan, red } from 'yoctocolors';
|
|
16
16
|
import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
|
|
17
17
|
import { pathExists } from '../utils/index.js';
|
|
18
|
-
import { getMatchedDocFilePaths, parseBoolean } from './helpers.js';
|
|
18
|
+
import { escapeMarkdownHeadingIds, getMatchedDocFilePaths, parseBoolean, } from './helpers.js';
|
|
19
19
|
import { loadConfig } from './load-config.js';
|
|
20
20
|
const LANGUAGE_CODES = {
|
|
21
21
|
zh: '中文',
|
|
@@ -45,7 +45,7 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
45
45
|
- <!-- reference-start -->
|
|
46
46
|
- <!-- reference-end -->
|
|
47
47
|
- 翻译过程中务必保留原文中的 \\< 和 \\{ 转义字符不要做任何转义变更
|
|
48
|
-
- 翻译过程中不要破坏原有的 Markdown 格式,如 frontmatter, 代码块、列表、表格等,其中 frontmatter 的内容不用做任何翻译,只需要原样返回即可
|
|
48
|
+
- 翻译过程中不要破坏原有的 Markdown 格式,如 frontmatter, 代码块、列表、表格等,其中 frontmatter.ii8n 的内容不用做任何翻译,只需要原样返回即可
|
|
49
49
|
|
|
50
50
|
## 策略
|
|
51
51
|
分四步进行翻译工作:
|
|
@@ -59,10 +59,12 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
59
59
|
|
|
60
60
|
最终只需要输出最后一步的结果,不需要输出之前步骤的结果。
|
|
61
61
|
|
|
62
|
+
<%= userPrompt %>
|
|
63
|
+
|
|
62
64
|
<%= additionalPrompts %>
|
|
63
65
|
`.trim();
|
|
64
66
|
let openai;
|
|
65
|
-
export const translate = async ({ source, sourceContent, target, targetContent = '', systemPrompt, additionalPrompts = '', }) => {
|
|
67
|
+
export const translate = async ({ source, sourceContent, target, targetContent = '', systemPrompt, userPrompt = '', additionalPrompts = '', }) => {
|
|
66
68
|
if (!openai) {
|
|
67
69
|
openai = new AzureOpenAI({
|
|
68
70
|
endpoint: process.env.AZURE_OPENAI_ENDPOINT ||
|
|
@@ -77,7 +79,7 @@ export const translate = async ({ source, sourceContent, target, targetContent =
|
|
|
77
79
|
messages: [
|
|
78
80
|
{
|
|
79
81
|
role: 'system',
|
|
80
|
-
content: await render(systemPrompt?.trim() || DEFAULT_SYSTEM_PROMPT, { sourceLang, targetLang, additionalPrompts }, { async: true }),
|
|
82
|
+
content: await render(systemPrompt?.trim() || DEFAULT_SYSTEM_PROMPT, { sourceLang, targetLang, userPrompt, additionalPrompts }, { async: true }),
|
|
81
83
|
},
|
|
82
84
|
{
|
|
83
85
|
role: 'user',
|
|
@@ -199,7 +201,7 @@ export const translateCommand = new Command('translate')
|
|
|
199
201
|
logger.info(`Translating ${cyan(relativePath)}`);
|
|
200
202
|
const isMdx = sourceFilePath.endsWith('.mdx');
|
|
201
203
|
const processor = isMdx ? mdxProcessor : mdProcessor;
|
|
202
|
-
const ast = processor.parse(sourceContent);
|
|
204
|
+
const ast = processor.parse(escapeMarkdownHeadingIds(sourceContent));
|
|
203
205
|
const normalizeImgSrcOptions = {
|
|
204
206
|
localPublicBase: path.resolve(docsDir, 'public'),
|
|
205
207
|
sourceBase: path.dirname(sourceFilePath),
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": "https://gitlab-ce.alauda.cn/idp/Doom.git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
45
45
|
"@playwright/browser-chromium": "^1.51.1",
|
|
46
46
|
"@rsbuild/plugin-yaml": "^1.0.2",
|
|
47
|
-
"@rspress/core": "1.43.
|
|
47
|
+
"@rspress/core": "1.43.10",
|
|
48
48
|
"@shikijs/transformers": "^3.2.1",
|
|
49
49
|
"chokidar": "^4.0.3",
|
|
50
50
|
"cli-progress": "^3.12.0",
|
|
@@ -70,32 +70,32 @@
|
|
|
70
70
|
"simple-git": "^3.27.0",
|
|
71
71
|
"swagger2openapi": "^7.0.8",
|
|
72
72
|
"tinyglobby": "^0.2.12",
|
|
73
|
-
"type-fest": "^4.
|
|
74
|
-
"yaml": "^2.7.
|
|
73
|
+
"type-fest": "^4.39.0",
|
|
74
|
+
"yaml": "^2.7.1",
|
|
75
75
|
"yoctocolors": "^2.1.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@eslint/js": "^9.23.0",
|
|
79
79
|
"@swc-node/register": "^1.10.10",
|
|
80
|
-
"@swc/core": "1.11.
|
|
80
|
+
"@swc/core": "1.11.16",
|
|
81
81
|
"@types/cli-progress": "^3.11.6",
|
|
82
82
|
"@types/ejs": "^3.1.5",
|
|
83
|
-
"@types/node": "^18.19.
|
|
84
|
-
"@types/picomatch": "^
|
|
83
|
+
"@types/node": "^18.19.86",
|
|
84
|
+
"@types/picomatch": "^4.0.0",
|
|
85
85
|
"@types/react": "^18.3.20",
|
|
86
|
-
"@types/react-dom": "^18.3.
|
|
86
|
+
"@types/react-dom": "^18.3.6",
|
|
87
87
|
"@types/swagger2openapi": "^7.0.4",
|
|
88
88
|
"@unts/patch-package": "^8.1.1",
|
|
89
89
|
"eslint": "^9.23.0",
|
|
90
|
-
"eslint-import-resolver-typescript": "^4.
|
|
91
|
-
"eslint-plugin-import-x": "^4.
|
|
90
|
+
"eslint-import-resolver-typescript": "^4.3.1",
|
|
91
|
+
"eslint-plugin-import-x": "^4.10.0",
|
|
92
92
|
"lint-staged": "^15.5.0",
|
|
93
93
|
"npm-run-all2": "^7.0.2",
|
|
94
94
|
"prettier": "^3.5.3",
|
|
95
95
|
"prettier-plugin-pkg": "^0.18.1",
|
|
96
96
|
"simple-git-hooks": "^2.12.1",
|
|
97
97
|
"typescript": "^5.8.2",
|
|
98
|
-
"typescript-eslint": "^8.
|
|
98
|
+
"typescript-eslint": "^8.29.0",
|
|
99
99
|
"yarn-berry-deduplicate": "^6.1.1"
|
|
100
100
|
},
|
|
101
101
|
"publishConfig": {
|