From e4f74fc962e82f119e1a1c421169587af58d017f Mon Sep 17 00:00:00 2001 From: Corwin Marsh Date: Mon, 11 May 2026 12:22:49 -0700 Subject: [PATCH 1/2] Fix copied code block trailing newline --- extensions/pi-copy-code-block/src/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/pi-copy-code-block/src/index.ts b/extensions/pi-copy-code-block/src/index.ts index 71eedda..8e4d070 100644 --- a/extensions/pi-copy-code-block/src/index.ts +++ b/extensions/pi-copy-code-block/src/index.ts @@ -90,6 +90,12 @@ function getPreview(code: string): string { return lines.length > 1 ? `${linePreview} ⏎ …` : linePreview; } +function normalizeExtractedCode(code: string): string { + // The newline immediately before the closing fence is Markdown structure, not + // usually part of the code users expect to paste/run. + return code.replace(/\n$/, ""); +} + function extractCodeBlocks(text: string): CodeBlock[] { const extracted: Array> = []; const fencePattern = /^```([^\n`]*)\r?\n([\s\S]*?)^```[ \t]*$/gm; @@ -98,7 +104,7 @@ function extractCodeBlocks(text: string): CodeBlock[] { while (match) { const infoString = match[1]?.trim() ?? ""; const language = infoString.split(/\s+/)[0] || "text"; - const code = match[2]?.replace(/\r\n/g, "\n") ?? ""; + const code = normalizeExtractedCode(match[2]?.replace(/\r\n/g, "\n") ?? ""); extracted.push({ language, code }); match = fencePattern.exec(text); From 22c4cea5590ac3560c6465d794a6a6892fa2a1bf Mon Sep 17 00:00:00 2001 From: Corwin Marsh Date: Mon, 11 May 2026 12:25:43 -0700 Subject: [PATCH 2/2] Add changeset for copy code newline fix --- .changeset/fix-copy-code-block-trailing-newline.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-copy-code-block-trailing-newline.md diff --git a/.changeset/fix-copy-code-block-trailing-newline.md b/.changeset/fix-copy-code-block-trailing-newline.md new file mode 100644 index 0000000..ed195b2 --- /dev/null +++ b/.changeset/fix-copy-code-block-trailing-newline.md @@ -0,0 +1,5 @@ +--- +"@haphazarddev/pi-copy-code-block": patch +--- + +Remove the extra trailing newline when copying code blocks so single-line commands paste cleanly.