Skip to content
Merged
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
10 changes: 10 additions & 0 deletions packages/comark/test/auto-close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,16 @@ describe('attributes scope', () => {
})
})

describe('dollar-prefixed tokens without math (#136)', () => {
it.each([
'$skill-name',
'[$imagegen](/Users/user01/.codex/skills/.system/imagegen/SKILL.md)',
'Codex uses [$imagegen](/Users/user01/.codex/skills/.system/imagegen/SKILL.md) and $skill-name.',
])('should leave %s unchanged', (input) => {
expect(autoCloseMarkdown(input)).toBe(input)
})
})

describe('inline code spans as literal regions', () => {
it('should not count asterisks inside a closed code span', () => {
const input = 'text `a*b` and **bold'
Expand Down
34 changes: 34 additions & 0 deletions packages/comark/test/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,37 @@ Inline \(E = mc^2\) and \[x^2\] end.`
expect(await renderMarkdown(document)).toBe(source)
})
})

describe('dollar-prefixed tokens and auto-close (#136)', () => {
const href = '/Users/user01/.codex/skills/.system/imagegen/SKILL.md'

it('keeps a trailing `$skill-name` as plain text without the math plugin', async () => {
const document = await parseMarkdown('$skill-name')

expect(document.nodes).toEqual([['p', {}, '$skill-name']])
expect(await renderMarkdown(document)).toBe('$skill-name')
})

it('keeps `$` inside link text without the math plugin', async () => {
const source = `[$imagegen](${href})`
const document = await parseMarkdown(source)

expect(document.nodes).toEqual([['p', {}, ['a', { href }, '$imagegen']]])
expect(await renderMarkdown(document)).toBe(source)
})

it('keeps a link and a trailing `$skill-name.` intact without the math plugin', async () => {
const source = `Codex uses [$imagegen](${href}) and $skill-name.`
const document = await parseMarkdown(source)

expect(document.nodes).toEqual([['p', {}, 'Codex uses ', ['a', { href }, '$imagegen'], ' and $skill-name.']])
expect(await renderMarkdown(document)).toBe(source)
})

it('auto-closes a trailing unclosed `$` when the math plugin is registered', async () => {
const document = await parseMarkdown('Value $x', { plugins: [math()] })

expect(document.nodes).toEqual([['p', {}, 'Value ', ['math', { class: 'math inline', content: 'x' }, 'x']]])
expect(await renderMarkdown(document)).toBe('Value $x$')
})
})
Loading