Skip to content

Commit 8361489

Browse files
committed
fix(scriptlet): maintain code whitespace
1 parent 2e4a180 commit 8361489

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/core/scriptlets.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1700,3 +1700,20 @@ echo "dummy"
17001700
const scriptlets = await parseMarkdownAsScriptlets(markdown, dummyFilePath)
17011701
t.is(scriptlets[0].kenv, 'test')
17021702
})
1703+
1704+
ava("parseMarkdownAsScriptlets preserves whitespace in Python scripts", async (t) => {
1705+
const markdown = `
1706+
## Python Test
1707+
\`\`\`python
1708+
with open('~/hello-python.txt', 'w') as f:
1709+
f.write('Hello from Python!')
1710+
\`\`\`
1711+
`.trim()
1712+
1713+
const scripts = await parseMarkdownAsScriptlets(markdown)
1714+
t.is(scripts.length, 1)
1715+
t.is(scripts[0].name, "Python Test")
1716+
t.is(scripts[0].tool, "python")
1717+
t.is(scripts[0].scriptlet, `with open('~/hello-python.txt', 'w') as f:
1718+
f.write('Hello from Python!')`)
1719+
})

src/core/scriptlets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export let parseMarkdownAsScriptlets = async (markdown: string, filePath?: strin
186186
}
187187

188188
if (parsingValue && currentScriptlet) {
189-
currentScriptlet.scriptlet = currentScriptlet.scriptlet ? `${currentScriptlet.scriptlet}\n${line}` : line
189+
currentScriptlet.scriptlet = currentScriptlet.scriptlet ? `${currentScriptlet.scriptlet}\n${untrimmedLine}` : untrimmedLine
190190
}
191191

192192
if (parsingMetadata) {

0 commit comments

Comments
 (0)