Skip to content

Commit 2c0c9f0

Browse files
author
Peter Steinberger
committed
fix(line): preserve semantic indentation in fenced code
1 parent aeaaaad commit 2c0c9f0

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎extensions/line/src/markdown-to-line.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,32 @@ That's it.`;
224224
expect(result.text).not.toContain("```");
225225
});
226226

227+
it.each([
228+
{
229+
name: "space-indented code",
230+
source: " first()\n second()",
231+
expected: " first()\n second()",
232+
},
233+
{
234+
name: "tab-indented Unicode code",
235+
source: "\t😀 first()\n\t界 second()",
236+
expected: "\t😀 first()\n\t界 second()",
237+
},
238+
{
239+
name: "existing terminal-newline behavior",
240+
source: " first()\n\n",
241+
expected: " first()",
242+
},
243+
])("preserves $name in code cards", ({ source, expected }) => {
244+
const result = processLineMessage(`\`\`\`python\n${source}\n\`\`\``);
245+
const bubble = requireEntry(result.flexMessages, 0, "code flex message").contents as {
246+
body: { contents: Array<{ contents?: Array<{ text: string }> }> };
247+
};
248+
const codeContent = requireEntry(bubble.body.contents, 1, "code flex body content");
249+
250+
expect(requireEntry(codeContent.contents ?? [], 0, "code flex text").text).toBe(expected);
251+
});
252+
227253
it("handles mixed content", () => {
228254
const text = `# Summary
229255

‎extensions/line/src/markdown-to-line.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function codeBlockSpans(ir: MarkdownIR): MarkdownStyleSpan[] {
7474
function toCodeBlock(ir: MarkdownIR, span: MarkdownStyleSpan): CodeBlock {
7575
return {
7676
...(span.language ? { language: span.language } : {}),
77-
code: ir.text.slice(span.start, span.end).trim(),
77+
code: ir.text.slice(span.start, span.end).trimEnd(),
7878
};
7979
}
8080

0 commit comments

Comments
 (0)