Skip to content

Commit

Permalink
#787 support CRLF for markdown script (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrenceching authored Apr 25, 2024
1 parent 5fd3d8a commit eda722c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/fixtures/markdown-crlf.md eol=crlf
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function transformMarkdown(buf: Buffer) {
const jsCodeBlock = /^(```+|~~~+)(js|javascript)$/
const shCodeBlock = /^(```+|~~~+)(sh|bash)$/
const otherCodeBlock = /^(```+|~~~+)(.*)$/
for (let line of source.split('\n')) {
for (let line of source.split(/\r?\n/)) {
switch (state) {
case 'root':
if (/^( {4}|\t)/.test(line) && prevLineIsEmpty) {
Expand Down
5 changes: 5 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ describe('cli', () => {
await $`node build/cli.js test/fixtures/markdown.md`
})

test('markdown scripts are working for CRLF', async () => {
let p = await $`node build/cli.js test/fixtures/markdown-crlf.md`
assert.ok(p.stdout.includes('Hello, world!'))
})

test('exceptions are caught', async () => {
let out1 = await $`node build/cli.js <<<${'await $`wtf`'}`.nothrow()
assert.match(out1.stderr, /Error:/)
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/markdown-crlf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```js
echo`Hello, world!`
```

0 comments on commit eda722c

Please sign in to comment.