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
5 changes: 4 additions & 1 deletion packages/comark/src/plugins/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ const markdownItComarkBlock: PluginSimple = (md) => {

const line = state.src.slice(start, state.eMarks[startLine])

const { name, props } = parseBlockParams(line.slice(1))
const slotParams = line.slice(1)
if (!isValidComponentName(slotParams.trimStart())) return false
const { name, props, remaining } = parseBlockParams(slotParams)
if (remaining) return false

if (silent) return true

Expand Down
29 changes: 29 additions & 0 deletions packages/comark/test/component-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,33 @@ describe('component name validation', () => {
expect(tree.nodes).toEqual([['alert', {}, 'Hello']])
})
})

describe('component slots', () => {
it('does not throw on a malformed slot marker #[]', async () => {
const tree = await parseMarkdown('::Component\n#[]\n::')
expect(tree.nodes).toEqual([['Component', {}, ['p', {}, '#[]']]])
})

it('does not throw on a malformed slot marker #{}', async () => {
const tree = await parseMarkdown('::Component\n#{}\n::')
expect(tree.nodes).toEqual([['Component', {}, ['p', {}, '#{}']]])
})

it('does not throw on a malformed slot marker #name!', async () => {
const tree = await parseMarkdown('::Component\n#slot!\n::')
expect(tree.nodes).toEqual([['Component', {}, ['p', {}, '#slot!']]])
})

it('does not throw on a malformed slot marker #name!', async () => {
const tree = await parseMarkdown('::Component\n#slot!\n::')
expect(tree.nodes).toEqual([['Component', {}, ['p', {}, '#slot!']]])
})

it('still parses a valid slot marker #name', async () => {
const tree = await parseMarkdown('::Component\n#slot\nhello\n::')
expect(tree.nodes).toEqual([['Component', {}, ['template', { '#slot': 'true' }, ['p', {}, 'hello']]]])
})
})
})