Skip to content

Commit 2efb817

Browse files
authored
fix(clients): keep backslashes in copied Codex citations (pingdotgg#12243)
Co-authored-by: Simone <[email protected]>
1 parent 411da2a commit 2efb817

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/client-runtime/src/codexFileCitations.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function markdownLabel(value: string): string {
4444

4545
function markdownDestination(value: string): string {
4646
return value
47+
.replaceAll("\\", "%5C")
4748
.replaceAll("<", "%3C")
4849
.replaceAll(">", "%3E")
4950
.replaceAll("\r", "%0D")

‎packages/client-runtime/src/codexMarkdownDirectives.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
renderCodexFileCitationsAsMarkdown,
99
splitCodexArtifactTemplateMarkdown,
1010
} from "./codexMarkdownDirectives.js";
11+
import { parseMarkdownFileLink } from "./markdownLinks.js";
1112

1213
interface TestNode {
1314
readonly type: string;
@@ -89,6 +90,24 @@ describe("remarkCodexDirectives", () => {
8990
});
9091
});
9192

93+
describe.each([
94+
{ name: "renderCodexDirectivesForCopy", render: renderCodexDirectivesForCopy },
95+
{ name: "renderCodexFileCitationsAsMarkdown", render: renderCodexFileCitationsAsMarkdown },
96+
])("$name file citation round trips", ({ render }) => {
97+
it.each([
98+
"C:\\Users\\test\\[draft]\\report.md",
99+
"\\\\server\\share\\report.md",
100+
"outputs/report.md",
101+
"/tmp/report%5C.md",
102+
])("preserves the literal path and line: %s", (path) => {
103+
const markdown = render(`:codex-file-citation{path="${path}" line_range_start="7"}`);
104+
const link = parseOrdinaryMarkdown(markdown).children?.[0]?.children?.[0];
105+
106+
expect(link?.type).toBe("link");
107+
expect(parseMarkdownFileLink(link?.url ?? "")).toEqual({ path, line: 7 });
108+
});
109+
});
110+
92111
describe("native Markdown adapters", () => {
93112
it("uses the same parser to render file citations as portable links", () => {
94113
expect(renderCodexFileCitationsAsMarkdown(`Created ${FILE_CITATION}.`)).toBe(

0 commit comments

Comments
 (0)