@devries-cameron20 / t3code Mirror · read-only / commits / 666631e94e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 14:45 UTC

fix(web): copied inline code keeps meaningful edge spaces (#36712)

Co-authored-by: Grok 4.7 <noreply@x.ai> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 13:38 UTC 666631e94eb183b09183fa9f05dd3d87da3cbc34
2 files changed +21 -1
apps/web/src/markdown-clipboard.test.ts
+18
@@ -198,6 +198,24 @@ describe("serializeRenderedMarkdownFragment", () => {
198 expect(serializeRenderedMarkdownFragment(asNode(container))).toBe("first line\nsecond line");
199 });
200
201 + it.each([
202 + ["backtick edges", "`value`"],
203 + ["space edges", " value "],
204 + ["only spaces", " "],
205 + ])("copies inline code that parses back unchanged: %s", (_, value) => {
206 + const container = new FakeElement("DIV").append(
207 + new FakeElement("P").append(
208 + new FakeText("Use "),
209 + new FakeElement("CODE").append(new FakeText(value)),
210 + new FakeText(" here."),
211 + ),
212 + );
213 + const paragraph = parseMarkdownWithMath(serializeRenderedMarkdownFragment(asNode(container)))
214 + .children[0];
215 + if (paragraph?.type !== "paragraph") throw new Error("Expected a paragraph");
216 + expect(paragraph.children.find((child) => child.type === "inlineCode")?.value).toBe(value);
217 + });
218 +
219 it("copies alert and insight callouts as their Markdown instead of the rendered label", () => {
220 // The shape ChatMarkdown renders for `> [!WARNING]\n> Back up first.`.
221 const callout = new FakeElement("DIV", [], {
apps/web/src/markdown-clipboard.ts
+3 -1
@@ -48,7 +48,9 @@ function wrapInlineCode(code: string): string {
48 0,
49 );
50 const fence = "`".repeat(Math.max(1, longestRun + (longestRun > 0 ? 1 : 0)));
51 - const pad = code.startsWith("`") || code.endsWith("`") ? " " : "";
51 + // CommonMark strips one edge space from content that has both and isn't all spaces.
52 + const spaceEdges = code.startsWith(" ") && code.endsWith(" ") && /[^ ]/.test(code);
53 + const pad = spaceEdges || code.startsWith("`") || code.endsWith("`") ? " " : "";
54 return `${fence}${pad}${code}${pad}${fence}`;
55 }
56