@alauda/doom 2.7.0 → 2.8.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/translate-call.d.ts +3 -2
- package/lib/cli/translate-call.js +16 -2
- package/lib/cli/translate-judge.d.ts +10 -2
- package/lib/cli/translate-judge.js +28 -4
- package/lib/cli/translate-pipeline.d.ts +27 -2
- package/lib/cli/translate-pipeline.js +57 -5
- package/lib/cli/translate-segment-check.js +41 -0
- package/lib/cli/translate.js +29 -1
- package/lib/remark-lint/no-unparsed-emphasis.d.ts +13 -0
- package/lib/remark-lint/no-unparsed-emphasis.js +30 -5
- package/package.json +1 -1
|
@@ -19,8 +19,9 @@ import type { Segment } from './translate-segment.ts';
|
|
|
19
19
|
* context it has filled and had released is a model that reaches for a rewrite.
|
|
20
20
|
*/
|
|
21
21
|
/** Retries for a refused request. Transient limits are normal at corpus scale. */
|
|
22
|
-
export declare const DEFAULT_CALL_MAX_RETRIES =
|
|
23
|
-
|
|
22
|
+
export declare const DEFAULT_CALL_MAX_RETRIES = 6;
|
|
23
|
+
/** 5 s, doubled per attempt: about five minutes, the same budget as the judge. See there for the measurement. */
|
|
24
|
+
export declare const DEFAULT_CALL_RETRY_DELAY_MS = 5000;
|
|
24
25
|
/** How many lines of the previous segment's translation carry the voice forward. */
|
|
25
26
|
export declare const DEFAULT_CONTEXT_TAIL = 20;
|
|
26
27
|
export interface SegmentTranslationRequest {
|
|
@@ -15,13 +15,25 @@
|
|
|
15
15
|
* context it has filled and had released is a model that reaches for a rewrite.
|
|
16
16
|
*/
|
|
17
17
|
/** Retries for a refused request. Transient limits are normal at corpus scale. */
|
|
18
|
-
export const DEFAULT_CALL_MAX_RETRIES =
|
|
19
|
-
|
|
18
|
+
export const DEFAULT_CALL_MAX_RETRIES = 6;
|
|
19
|
+
/** 5 s, doubled per attempt: about five minutes, the same budget as the judge. See there for the measurement. */
|
|
20
|
+
export const DEFAULT_CALL_RETRY_DELAY_MS = 5_000;
|
|
20
21
|
/** How many lines of the previous segment's translation carry the voice forward. */
|
|
21
22
|
export const DEFAULT_CONTEXT_TAIL = 20;
|
|
22
23
|
const PLACEHOLDER_DISCIPLINE = `## Placeholders
|
|
23
24
|
|
|
24
25
|
Tokens shaped like \`__DOOM_TR_LINK_3__\` stand for content you must not author — link targets, code, identifiers, component attribute values. Reproduce each one verbatim and exactly once, in the position it appears. Never translate, reformat, split, renumber, remove, duplicate or invent one. The text around a placeholder is translated as usual.`;
|
|
26
|
+
/**
|
|
27
|
+
* Kept out of `DEFAULT_SYSTEM_PROMPT` for the same reason the placeholder
|
|
28
|
+
* discipline is: a repository can replace that prompt wholesale through
|
|
29
|
+
* `translate.systemPrompt`, and this constraint is enforced by a blocking
|
|
30
|
+
* check, so it has to live where a repository cannot drop it.
|
|
31
|
+
*/
|
|
32
|
+
const EMPHASIS_DISCIPLINE = `## Emphasis
|
|
33
|
+
|
|
34
|
+
\`**bold**\` only works when the delimiters sit directly against the text, and CommonMark will not close a run that is preceded by punctuation and followed by a letter. \`**Note:** text\` is bold; \`**注意:**文本\` is not — it prints the asterisks to the page.
|
|
35
|
+
|
|
36
|
+
When a bold label ends in a colon or other punctuation and the next thing is a word, put the punctuation outside the emphasis (\`**注意**:文本\`) or leave a space after the closing \`**\`. Never write \`** text **\`.`;
|
|
25
37
|
const SEGMENT_TASK = `Answer with the translated segment and nothing else: no explanation, no preamble, no summary, and no code fence wrapped around your whole answer.
|
|
26
38
|
|
|
27
39
|
The segment is one piece of a longer page. It begins and ends mid-document, and that is correct — do not add a title, an introduction or a conclusion, and do not finish a section that carries on past the end of what you were given.
|
|
@@ -39,6 +51,8 @@ export const createSegmentTranslator = ({ models, model, reasoningEffort, transl
|
|
|
39
51
|
'',
|
|
40
52
|
PLACEHOLDER_DISCIPLINE,
|
|
41
53
|
'',
|
|
54
|
+
EMPHASIS_DISCIPLINE,
|
|
55
|
+
'',
|
|
42
56
|
'## Translation rules',
|
|
43
57
|
'',
|
|
44
58
|
translationRules,
|
|
@@ -129,8 +129,16 @@ export declare const DEFAULT_JUDGE_DRAWS = 2;
|
|
|
129
129
|
* readings will meet it. Retrying is not softening the check — a reading that
|
|
130
130
|
* never succeeds still fails the document.
|
|
131
131
|
*/
|
|
132
|
-
export declare const DEFAULT_JUDGE_MAX_RETRIES =
|
|
133
|
-
|
|
132
|
+
export declare const DEFAULT_JUDGE_MAX_RETRIES = 6;
|
|
133
|
+
/**
|
|
134
|
+
* 5 s, doubled per attempt: about five minutes in all.
|
|
135
|
+
*
|
|
136
|
+
* Measured on 2026-09-04 with four translation runs sharing one gateway
|
|
137
|
+
* account: the refusals lasted minutes, not seconds, and the previous budget
|
|
138
|
+
* of about thirty seconds turned a busy gateway into a failed document — and,
|
|
139
|
+
* before `translate.ts` learned to contain it, into a failed run.
|
|
140
|
+
*/
|
|
141
|
+
export declare const DEFAULT_JUDGE_RETRY_DELAY_MS = 5000;
|
|
134
142
|
/**
|
|
135
143
|
* The findings enough readings agreed on.
|
|
136
144
|
*
|
|
@@ -17,8 +17,16 @@ export const DEFAULT_JUDGE_DRAWS = 2;
|
|
|
17
17
|
* readings will meet it. Retrying is not softening the check — a reading that
|
|
18
18
|
* never succeeds still fails the document.
|
|
19
19
|
*/
|
|
20
|
-
export const DEFAULT_JUDGE_MAX_RETRIES =
|
|
21
|
-
|
|
20
|
+
export const DEFAULT_JUDGE_MAX_RETRIES = 6;
|
|
21
|
+
/**
|
|
22
|
+
* 5 s, doubled per attempt: about five minutes in all.
|
|
23
|
+
*
|
|
24
|
+
* Measured on 2026-09-04 with four translation runs sharing one gateway
|
|
25
|
+
* account: the refusals lasted minutes, not seconds, and the previous budget
|
|
26
|
+
* of about thirty seconds turned a busy gateway into a failed document — and,
|
|
27
|
+
* before `translate.ts` learned to contain it, into a failed run.
|
|
28
|
+
*/
|
|
29
|
+
export const DEFAULT_JUDGE_RETRY_DELAY_MS = 5_000;
|
|
22
30
|
const SYSTEM_PROMPT = `You are reviewing a translation of technical documentation. You are not improving it and not rewriting it: you are saying what is wrong with it, if anything.
|
|
23
31
|
|
|
24
32
|
Work in two passes, in this order.
|
|
@@ -246,8 +254,24 @@ export const createJudge = ({ models, model, reasoningEffort, draws = DEFAULT_JU
|
|
|
246
254
|
return {
|
|
247
255
|
readings: () => readings,
|
|
248
256
|
async review(request) {
|
|
249
|
-
|
|
250
|
-
|
|
257
|
+
// One reading first, and a clean reading is final.
|
|
258
|
+
//
|
|
259
|
+
// Measured on 2026-09-04 over 80 readings of translations the pipeline
|
|
260
|
+
// had already accepted: 97% found nothing, and the two that found
|
|
261
|
+
// something were right. The extra readings exist to confirm a finding,
|
|
262
|
+
// not to look for one the first reading missed — so they are taken only
|
|
263
|
+
// when there is something blocking to confirm, and the same vote then
|
|
264
|
+
// applies to all of them. What gets sent back does not change; what a
|
|
265
|
+
// segment that passes costs does: one reading instead of `draws`.
|
|
266
|
+
const first = await readOnce(request);
|
|
267
|
+
const confirm = first.some((finding) => BLOCKING_JUDGE_KINDS.includes(finding.kind));
|
|
268
|
+
const results = confirm
|
|
269
|
+
? [
|
|
270
|
+
first,
|
|
271
|
+
...(await Promise.all(Array.from({ length: Math.max(0, draws - 1) }, () => readOnce(request)))),
|
|
272
|
+
]
|
|
273
|
+
: [first];
|
|
274
|
+
return agreedFindings(results, confirm ? votes : 1).map((finding) => ({
|
|
251
275
|
rule: `doom-judge:${finding.kind}`,
|
|
252
276
|
reason: `${finding.detail} — the source says: “${finding.source}”`,
|
|
253
277
|
blocking: BLOCKING_JUDGE_KINDS.includes(finding.kind),
|
|
@@ -23,8 +23,20 @@ import type { TermPair } from './translate-terms.ts';
|
|
|
23
23
|
*/
|
|
24
24
|
/** How many times a segment is asked for before it is escalated. */
|
|
25
25
|
export declare const DEFAULT_MAX_SEGMENT_ATTEMPTS = 3;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* How many times the assembled document may send segments back.
|
|
28
|
+
*
|
|
29
|
+
* Raised from 2 on 2026-09-03. At 2, the only rule that ever fired here in
|
|
30
|
+
* production — `no-unparsed-emphasis`, 22 send-backs out of 22 across four
|
|
31
|
+
* builds of `immutable-infra-docs` — failed three of six documents by running
|
|
32
|
+
* out of rounds, and a document that fails discards every other document's
|
|
33
|
+
* accepted work in the same run. The model does fix it; it does not always fix
|
|
34
|
+
* it twice in a row.
|
|
35
|
+
*
|
|
36
|
+
* This is the backstop, not the fix: that rule is now also checked per segment,
|
|
37
|
+
* where it gets three attempts and a repair agent before it ever reaches here.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DEFAULT_MAX_ASSEMBLY_ROUNDS = 4;
|
|
28
40
|
export type SegmentStatus = 'translated' | 'cached' | 'repaired' | 'failed';
|
|
29
41
|
export interface SegmentOutcome {
|
|
30
42
|
index: number;
|
|
@@ -55,6 +67,11 @@ export type DocumentFailure =
|
|
|
55
67
|
/** The assembled document failed a rule nothing could attribute to a segment. */
|
|
56
68
|
| {
|
|
57
69
|
kind: 'unlocatable';
|
|
70
|
+
}
|
|
71
|
+
/** The translation stopped on an error — a gateway that never answered, or a bug. Nothing was written. */
|
|
72
|
+
| {
|
|
73
|
+
kind: 'error';
|
|
74
|
+
detail: string;
|
|
58
75
|
};
|
|
59
76
|
export interface TranslateDocumentResult {
|
|
60
77
|
/** The finished document, when it passed. */
|
|
@@ -142,3 +159,11 @@ export interface TranslateDocumentOptions {
|
|
|
142
159
|
*/
|
|
143
160
|
export declare const maskFindingToTranslationFinding: (finding: MaskIntegrityError["findings"][number]) => TranslationFinding;
|
|
144
161
|
export declare const translateDocument: (options: TranslateDocumentOptions) => Promise<TranslateDocumentResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Whether a segment has any text a reviewer could judge.
|
|
164
|
+
*
|
|
165
|
+
* Frontmatter, headings, blank lines, lines that are only a component tag or
|
|
166
|
+
* a placeholder do not count: a heading is held to the source by the structure
|
|
167
|
+
* check, a tag by the component multiset, a placeholder by the count.
|
|
168
|
+
*/
|
|
169
|
+
export declare const hasProse: (segment: Pick<Segment, "text">) => boolean;
|
|
@@ -21,8 +21,20 @@ import { UnsplittableBlockError, assemble, documentOutline, planSegments, resolv
|
|
|
21
21
|
*/
|
|
22
22
|
/** How many times a segment is asked for before it is escalated. */
|
|
23
23
|
export const DEFAULT_MAX_SEGMENT_ATTEMPTS = 3;
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* How many times the assembled document may send segments back.
|
|
26
|
+
*
|
|
27
|
+
* Raised from 2 on 2026-09-03. At 2, the only rule that ever fired here in
|
|
28
|
+
* production — `no-unparsed-emphasis`, 22 send-backs out of 22 across four
|
|
29
|
+
* builds of `immutable-infra-docs` — failed three of six documents by running
|
|
30
|
+
* out of rounds, and a document that fails discards every other document's
|
|
31
|
+
* accepted work in the same run. The model does fix it; it does not always fix
|
|
32
|
+
* it twice in a row.
|
|
33
|
+
*
|
|
34
|
+
* This is the backstop, not the fix: that rule is now also checked per segment,
|
|
35
|
+
* where it gets three attempts and a repair agent before it ever reaches here.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_MAX_ASSEMBLY_ROUNDS = 4;
|
|
26
38
|
/**
|
|
27
39
|
* A mask finding, said in the vocabulary the rest of the pipeline speaks.
|
|
28
40
|
*
|
|
@@ -155,6 +167,13 @@ export const translateDocument = async (options) => {
|
|
|
155
167
|
let retry = sentBack?.length
|
|
156
168
|
? { previous: frozen[segment.index] ?? '', findings: sentBack }
|
|
157
169
|
: undefined;
|
|
170
|
+
// A page that is a heading and an `<Overview />` has nothing for a
|
|
171
|
+
// reviewer to read, and the deterministic layers already hold the heading
|
|
172
|
+
// to the source. Half the index pages of a site are exactly that.
|
|
173
|
+
const judge = hasProse(segment) ? segmentJudge : undefined;
|
|
174
|
+
if (segmentJudge && !judge && !sentBack) {
|
|
175
|
+
onProgress?.(`${sourceLabel} [segment ${segment.index + 1}/${plan.segments.length}${describe(segment)}] not reviewed: nothing but headings and components`);
|
|
176
|
+
}
|
|
158
177
|
for (let attempt = 1; attempt <= maxSegmentAttempts; attempt++) {
|
|
159
178
|
outcome.attempts++;
|
|
160
179
|
const translation = await translator.translate({
|
|
@@ -169,7 +188,7 @@ export const translateDocument = async (options) => {
|
|
|
169
188
|
translation,
|
|
170
189
|
processor,
|
|
171
190
|
documentTokens,
|
|
172
|
-
judge
|
|
191
|
+
judge,
|
|
173
192
|
fragment,
|
|
174
193
|
sourceLanguage,
|
|
175
194
|
targetLanguage,
|
|
@@ -189,7 +208,7 @@ export const translateDocument = async (options) => {
|
|
|
189
208
|
best[segment.index] = { text: translation, blocking: blocking.length };
|
|
190
209
|
}
|
|
191
210
|
retry = { previous: translation, findings };
|
|
192
|
-
onProgress?.(`${sourceLabel} [segment ${segment.index + 1}/${plan.segments.length}${describe(segment)}] attempt ${attempt} rejected: ${summarise(blocking)}`);
|
|
211
|
+
onProgress?.(`${sourceLabel} [segment ${segment.index + 1}/${plan.segments.length}${describe(segment)}] attempt ${attempt} rejected: ${summarise(blocking)}${reasons(blocking)}`);
|
|
193
212
|
}
|
|
194
213
|
if (repairer) {
|
|
195
214
|
const draft = best[segment.index]?.text ?? '';
|
|
@@ -352,7 +371,7 @@ export const translateDocument = async (options) => {
|
|
|
352
371
|
assemblyRounds++;
|
|
353
372
|
for (const [index, sentBack] of routed) {
|
|
354
373
|
const segment = plan.segments[index];
|
|
355
|
-
onProgress?.(`${sourceLabel} [segment ${index + 1}/${plan.segments.length}${describe(segment)}] sent back by the assembled document: ${summarise(sentBack)}`);
|
|
374
|
+
onProgress?.(`${sourceLabel} [segment ${index + 1}/${plan.segments.length}${describe(segment)}] sent back by the assembled document: ${summarise(sentBack)}${reasons(sentBack)}`);
|
|
356
375
|
await workOn(segment, sentBack);
|
|
357
376
|
}
|
|
358
377
|
}
|
|
@@ -362,6 +381,39 @@ const summarise = (findings) => findings
|
|
|
362
381
|
.slice(0, 3)
|
|
363
382
|
.map((finding) => finding.rule)
|
|
364
383
|
.join(', ') + (findings.length > 3 ? `, +${findings.length - 3} more` : '');
|
|
384
|
+
/**
|
|
385
|
+
* What the findings said, one per line under the summary.
|
|
386
|
+
*
|
|
387
|
+
* The rule names alone were what the build log used to carry, and they are
|
|
388
|
+
* not enough to tell a reviewer that is right from one that is not: on
|
|
389
|
+
* 2026-09-04 that question needed a day of probing to answer, because the
|
|
390
|
+
* reviewer's reasons for 29 rejections had been printed nowhere. Now they
|
|
391
|
+
* are in the log, where a person can read them.
|
|
392
|
+
*/
|
|
393
|
+
const reasons = (findings) => findings
|
|
394
|
+
.slice(0, 3)
|
|
395
|
+
.map((finding) => `\n ${finding.rule}: ${finding.reason.length > 240 ? `${finding.reason.slice(0, 240)}…` : finding.reason}`)
|
|
396
|
+
.join('');
|
|
397
|
+
/**
|
|
398
|
+
* Whether a segment has any text a reviewer could judge.
|
|
399
|
+
*
|
|
400
|
+
* Frontmatter, headings, blank lines, lines that are only a component tag or
|
|
401
|
+
* a placeholder do not count: a heading is held to the source by the structure
|
|
402
|
+
* check, a tag by the component multiset, a placeholder by the count.
|
|
403
|
+
*/
|
|
404
|
+
export const hasProse = (segment) => {
|
|
405
|
+
const body = segment.text.replace(/^---\n[\s\S]*?\n---\n?/u, '');
|
|
406
|
+
return body.split('\n').some((line) => {
|
|
407
|
+
const text = line.trim();
|
|
408
|
+
if (text === '' || text.startsWith('#')) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
if (/^<\/?[A-Za-z][^>]*>$/u.test(text) || /^\{.*\}$/u.test(text)) {
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
return /[\p{L}\p{N}]/u.test(text.replace(/__DOOM_TR_[A-Z]+_\d+__/gu, ''));
|
|
415
|
+
});
|
|
416
|
+
};
|
|
365
417
|
/**
|
|
366
418
|
* Rules that compare the translation with its source across the whole tree.
|
|
367
419
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { explainUnparsedEmphasis, findUnparsedEmphasis, } from "../remark-lint/no-unparsed-emphasis.js";
|
|
2
3
|
import { collectComponents, collectHeadingDepths, } from "../remark-lint/translation-parity/shared.js";
|
|
3
4
|
import { countPlaceholders } from "./translate-mask.js";
|
|
4
5
|
import { parseAttributeElement } from "./translate-segment.js";
|
|
@@ -208,8 +209,48 @@ const structureFindings = (segment, tree, processor) => {
|
|
|
208
209
|
});
|
|
209
210
|
});
|
|
210
211
|
}
|
|
212
|
+
// Emphasis the translation broke.
|
|
213
|
+
//
|
|
214
|
+
// `**` reaching a text node means the delimiters were printed instead of
|
|
215
|
+
// read, and the usual cause is a target language that does not space the way
|
|
216
|
+
// the source did: `**Note:** text` is bold, and the Chinese it becomes,
|
|
217
|
+
// `**注意:**文本`, is not — the closing run is preceded by punctuation and
|
|
218
|
+
// followed by a letter, which CommonMark refuses to close on. The page then
|
|
219
|
+
// shows the asterisks, and nothing else notices: it parses, every link
|
|
220
|
+
// resolves, every component is present.
|
|
221
|
+
//
|
|
222
|
+
// `no-unparsed-emphasis` already catches this over the whole document. It is
|
|
223
|
+
// here for the same reason the heading and component collectors are (see this
|
|
224
|
+
// function's own note): checked per segment it arrives with the segment
|
|
225
|
+
// attached and can simply be retranslated, with three attempts and a repair
|
|
226
|
+
// agent behind it, instead of sharing the two rounds the assembled page gets.
|
|
227
|
+
//
|
|
228
|
+
// Only what the translation introduced. A source that shows literal asterisks
|
|
229
|
+
// on purpose is the author's business, and its translation should keep them.
|
|
230
|
+
if (!firstUnparsedEmphasis(source)) {
|
|
231
|
+
const broken = firstUnparsedEmphasis(tree);
|
|
232
|
+
if (broken) {
|
|
233
|
+
findings.push({
|
|
234
|
+
rule: 'doom-translate:segment-unparsed-emphasis',
|
|
235
|
+
reason: `${explainUnparsedEmphasis(broken.delimiter, broken.window)} The source segment has none, so this one came from the translation. Put the punctuation outside the emphasis — \`**注意**:文本\` — or leave a space after the closing \`**\`.`,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
211
239
|
return findings;
|
|
212
240
|
};
|
|
241
|
+
/**
|
|
242
|
+
* The first `**` a segment prints instead of reading, if there is one.
|
|
243
|
+
*
|
|
244
|
+
* Masked text, so the `__` half of the rule is off: a masked segment is full of
|
|
245
|
+
* `__DOOM_TR_ICODE_0__`, and `**` never appears inside a placeholder.
|
|
246
|
+
*/
|
|
247
|
+
const firstUnparsedEmphasis = (tree) => {
|
|
248
|
+
let found;
|
|
249
|
+
visit(tree, 'text', (node) => {
|
|
250
|
+
found ??= findUnparsedEmphasis(node.value, { maskedText: true });
|
|
251
|
+
});
|
|
252
|
+
return found;
|
|
253
|
+
};
|
|
213
254
|
/**
|
|
214
255
|
* A tag's prose, checked as the tag it has to become.
|
|
215
256
|
*
|
package/lib/cli/translate.js
CHANGED
|
@@ -165,6 +165,9 @@ const describeFailure = (result) => {
|
|
|
165
165
|
case 'unlocatable': {
|
|
166
166
|
return 'The assembled document failed a check of the whole page that could not be attributed to any one segment.';
|
|
167
167
|
}
|
|
168
|
+
case 'error': {
|
|
169
|
+
return `The translation stopped on an error and nothing was written: ${failure.detail}`;
|
|
170
|
+
}
|
|
168
171
|
default: {
|
|
169
172
|
return 'The document did not pass its checks.';
|
|
170
173
|
}
|
|
@@ -445,7 +448,32 @@ export const translateCommand = new Command('translate')
|
|
|
445
448
|
}
|
|
446
449
|
return stringifyMatter(newFrontmatter, content);
|
|
447
450
|
};
|
|
451
|
+
// One document's error is that document's failure, not the run's.
|
|
452
|
+
//
|
|
453
|
+
// Measured on 2026-09-04: a judge reading refused by the gateway for
|
|
454
|
+
// longer than its retries threw out of here, and the whole process
|
|
455
|
+
// exited — forty minutes of accepted translations of other documents
|
|
456
|
+
// still in flight went with it. The documents already written stay
|
|
457
|
+
// written; this one is reported with the rest at the end.
|
|
448
458
|
await documentLimit(async () => {
|
|
459
|
+
try {
|
|
460
|
+
await translateOne();
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
464
|
+
failures.push({
|
|
465
|
+
file: targetRelativePath,
|
|
466
|
+
result: {
|
|
467
|
+
findings: [{ rule: 'doom-translate:error', reason: detail }],
|
|
468
|
+
failure: { kind: 'error', detail },
|
|
469
|
+
outcomes: [],
|
|
470
|
+
assemblyRounds: 0,
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
logger.error(`${cyan(sourceRelativePath)}: translation stopped on an error and nothing was written: ${detail}`);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
async function translateOne() {
|
|
449
477
|
if (shouldCopyOnly) {
|
|
450
478
|
logger.info(`Copying ${cyan(sourceRelativePath)} to ${cyan(targetRelativePath)}`);
|
|
451
479
|
const { content } = matter(sourceContent);
|
|
@@ -570,7 +598,7 @@ export const translateCommand = new Command('translate')
|
|
|
570
598
|
? `, ${result.assemblyRounds} assembly round(s)`
|
|
571
599
|
: '') +
|
|
572
600
|
')');
|
|
573
|
-
}
|
|
601
|
+
}
|
|
574
602
|
}));
|
|
575
603
|
await fs.rm(scratchDir, { recursive: true, force: true });
|
|
576
604
|
// Fail at the end, with the whole list.
|
|
@@ -1,2 +1,15 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
|
+
/** What one of these looks like to a person, wherever it is reported. */
|
|
3
|
+
export declare const explainUnparsedEmphasis: (delimiter: string, window: string) => string;
|
|
4
|
+
/**
|
|
5
|
+
* The first unparsed delimiter in a string, if there is one.
|
|
6
|
+
*
|
|
7
|
+
* `maskedText` narrows the test to `**`; see `UNPARSED_STRONG`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const findUnparsedEmphasis: (value: string, { maskedText }?: {
|
|
10
|
+
maskedText?: boolean;
|
|
11
|
+
}) => {
|
|
12
|
+
delimiter: string;
|
|
13
|
+
window: string;
|
|
14
|
+
} | undefined;
|
|
2
15
|
export declare const noUnparsedEmphasis: import("unified-lint-rule").Plugin<Root, unknown>;
|
|
@@ -34,15 +34,40 @@ import { visitParents } from 'unist-util-visit-parents';
|
|
|
34
34
|
* accident.
|
|
35
35
|
*/
|
|
36
36
|
const UNPARSED_EMPHASIS = /\*\*|(?<![\p{L}\p{N}])__|__(?![\p{L}\p{N}])/u;
|
|
37
|
+
/**
|
|
38
|
+
* The `**` half of the test on its own.
|
|
39
|
+
*
|
|
40
|
+
* `doom translate` runs this check a segment at a time, before the placeholders
|
|
41
|
+
* are put back, and a masked segment is full of `__DOOM_TR_ICODE_0__`. The `__`
|
|
42
|
+
* half would report every one of them. `**` never appears in a placeholder, so
|
|
43
|
+
* the half that matters for the defect this rule was written for is also the
|
|
44
|
+
* half that is safe to run on masked text.
|
|
45
|
+
*/
|
|
46
|
+
const UNPARSED_STRONG = /\*\*/u;
|
|
47
|
+
/** What one of these looks like to a person, wherever it is reported. */
|
|
48
|
+
export const explainUnparsedEmphasis = (delimiter, window) => `\`${delimiter}\` is printed to the page here, not read as emphasis: \`${window}\`. ` +
|
|
49
|
+
`Emphasis delimiters must sit directly against the text they emphasise — \`**text**\`, not \`** text **\` and not \`**text:**more\`.`;
|
|
50
|
+
/**
|
|
51
|
+
* The first unparsed delimiter in a string, if there is one.
|
|
52
|
+
*
|
|
53
|
+
* `maskedText` narrows the test to `**`; see `UNPARSED_STRONG`.
|
|
54
|
+
*/
|
|
55
|
+
export const findUnparsedEmphasis = (value, { maskedText = false } = {}) => {
|
|
56
|
+
const match = (maskedText ? UNPARSED_STRONG : UNPARSED_EMPHASIS).exec(value);
|
|
57
|
+
return match
|
|
58
|
+
? { delimiter: match[0], window: preview(value, match.index) }
|
|
59
|
+
: undefined;
|
|
60
|
+
};
|
|
37
61
|
export const noUnparsedEmphasis = lintRule('doom-lint:no-unparsed-emphasis', (root, vfile) => {
|
|
38
62
|
visitParents(root, 'text', (node, parents) => {
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
63
|
+
const found = findUnparsedEmphasis(node.value);
|
|
64
|
+
if (!found) {
|
|
41
65
|
return;
|
|
42
66
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
vfile.message(explainUnparsedEmphasis(found.delimiter, found.window), {
|
|
68
|
+
ancestors: [...parents, node],
|
|
69
|
+
place: pointStart(node),
|
|
70
|
+
});
|
|
46
71
|
});
|
|
47
72
|
});
|
|
48
73
|
/** A short window around the offending delimiter, for a person reading the log. */
|