Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/web/src/api/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,17 @@ const isSkippableBlock = (block: string): boolean => {
) {
return true;
}
// Tables: a pipe row plus a |---| separator row. Cell-safe translation is
// out of scope, so the whole block is passed through.
return (
lines.some((line) => line.includes("|")) &&
lines.some(
(line) => line.includes("|") && line.includes("-") && TABLE_SEPARATOR_LINE.test(line)
)
// Tables: a |---| separator row directly below a pipe row (the GFM shape).
// Cell-safe translation is out of scope, so the whole block is passed
// through; requiring adjacency keeps prose that merely contains pipe
// characters translatable.
return lines.some(
(line, i) =>
i > 0 &&
line.includes("|") &&
line.includes("-") &&
TABLE_SEPARATOR_LINE.test(line) &&
lines[i - 1].includes("|")
);
Comment on lines +270 to 277

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Standalone Separator Blocks Translate

When a separator row is split into its own block, such as a table-like block with blank lines around |---|, the new i > 0 check can no longer preserve that marker. That block now goes through translation and may come back with the pipe/dash structure changed, while the previous predicate skipped the separator-only block.

Suggested change
return lines.some(
(line, i) =>
i > 0 &&
line.includes("|") &&
line.includes("-") &&
TABLE_SEPARATOR_LINE.test(line) &&
lines[i - 1].includes("|")
);
return lines.some(
(line, i) =>
line.includes("|") &&
line.includes("-") &&
TABLE_SEPARATOR_LINE.test(line) &&
(lines.length === 1 || (i > 0 && lines[i - 1].includes("|")))
);

Fix in Claude Code

};

Expand Down
14 changes: 14 additions & 0 deletions apps/web/src/specs/api/translate-markdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,18 @@ it("preserves leading indentation on marker-less continuation lines", async () =
).rejects.toThrow("translate-cancelled");
expect(calls).toBe(1);
});
it("still skips a real GFM table (separator directly under the header row)", async () => {
const table = "| a | b |\n|---|---|\n| 1 | 2 |";
const result = await translateMarkdown(`Intro.\n\n${table}`, "es", "en");

expect(result).toBe(`\u00abIntro.\u00bb\n\n${table}`);
});

it("translates prose containing pipes and a stray separator-like line", async () => {
const block = "El valor |x| es absoluto\nnota al margen\n|---|";
const result = await translateMarkdown(block, "es", "en");

expect(result).toContain("\u00ab");
expect(post).toHaveBeenCalled();
});
});
Loading