Skip to content

Commit eda722c

Browse files
google#787 support CRLF for markdown script (google#788)
1 parent 5fd3d8a commit eda722c

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures/markdown-crlf.md eol=crlf

src/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function transformMarkdown(buf: Buffer) {
195195
const jsCodeBlock = /^(```+|~~~+)(js|javascript)$/
196196
const shCodeBlock = /^(```+|~~~+)(sh|bash)$/
197197
const otherCodeBlock = /^(```+|~~~+)(.*)$/
198-
for (let line of source.split('\n')) {
198+
for (let line of source.split(/\r?\n/)) {
199199
switch (state) {
200200
case 'root':
201201
if (/^( {4}|\t)/.test(line) && prevLineIsEmpty) {

test/cli.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ describe('cli', () => {
142142
await $`node build/cli.js test/fixtures/markdown.md`
143143
})
144144

145+
test('markdown scripts are working for CRLF', async () => {
146+
let p = await $`node build/cli.js test/fixtures/markdown-crlf.md`
147+
assert.ok(p.stdout.includes('Hello, world!'))
148+
})
149+
145150
test('exceptions are caught', async () => {
146151
let out1 = await $`node build/cli.js <<<${'await $`wtf`'}`.nothrow()
147152
assert.match(out1.stderr, /Error:/)

test/fixtures/markdown-crlf.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```js
2+
echo`Hello, world!`
3+
```

0 commit comments

Comments
 (0)