Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { bufToString } from './util.ts'

export function transformMarkdown(buf: Buffer | string): string {
const out: string[] = []
const tabRe = /^( +|\t)/
const tabRe = /^( {4,}|\t)/
const fenceRe =
/^(?<indent> {0,3})(?<fence>(`{3,20}|~{3,20}))(?:(?<js>js|javascript|ts|typescript)|(?<bash>sh|shell|bash)|.*)$/

Expand Down
34 changes: 32 additions & 2 deletions test/md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,38 @@ describe('transformMarkdown()', () => {
assert.equal(transformMarkdown('\n'), '// \n// ')
})

test('preserves tab-indented blocks after a blank line (legacy behavior)', () => {
assert.equal(transformMarkdown(' \n '), ' \n ')
test('preserves four-space and tab-indented blocks after a blank line', () => {
assert.equal(
transformMarkdown('\n code\n\tmore'),
'// \n code\n\tmore'
)
})

test('comments two-space indented list continuation prose', () => {
const result = transformMarkdown(`
- on localhost

This assumes you have a local node running.

\`\`\`bash
pnpm run contracts:deploy localhost
\`\`\`
`)

assert.equal(
result,
[
'// ',
'// - on localhost',
'// ',
'// This assumes you have a local node running.',
'// ',
'await $`',
'pnpm run contracts:deploy localhost',
'`',
'// ',
].join('\n')
)
})

test('does not treat a mid-paragraph fence as a fenced block (legacy behavior)', () => {
Expand Down