Commit eda722c
Changed files (4)
src/cli.ts
@@ -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) {
test/fixtures/markdown-crlf.md
@@ -0,0 +1,3 @@
+```js
+echo`Hello, world!`
+```
\ No newline at end of file
test/cli.test.js
@@ -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:/)
.gitattributes
@@ -0,0 +1,1 @@
+test/fixtures/markdown-crlf.md eol=crlf
\ No newline at end of file