Skip to content

Commit

Permalink
test: basic marked extension test
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Apr 7, 2024
1 parent 57cd73e commit 81f343b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
24 changes: 22 additions & 2 deletions packages/nuekit/test/nuekit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test('content collection', async () => {
// 5. System files starting with '_' or '.' are excluded.
await write('blog/.item6.md', createFront('Sixth', '2020-01-03'))
await write('blog/_item7.md', createFront('Seventh', '2020-01-03'))

const site = await getSite()
const coll = await site.getContentCollection('blog')
const actual = coll.map(c => {
Expand Down Expand Up @@ -324,4 +324,24 @@ test('the project was started for the first time', async () => {
const html = await readDist(kit.dist, 'index.html')
expect(html).toInclude('hotreload.js')
process.exit()
})
})

test('marked extension config file', async() => {
const marked_config = `export default [{
tokenizer: {
inlineText(src) {
const text = src.replace(/\\.{3}/g, '\\u2026')
return { type: 'text', raw: src, text }
}
}
}]`

await write('marked.config.js', marked_config)
await write('index.md', 'This is a test, right?\n\n...\n\nRight?\n\n.....')

const kit = await getKit()
const html = await kit.gen('index.md')

const ellipsis = '…'
expect(html).toInclude(`<p>This is a test, right?</p>\n<p>${ellipsis}</p>\n<p>Right?</p>\n<p>${ellipsis}..</p>\n`)
})
26 changes: 21 additions & 5 deletions packages/nuemark/test/nuemark.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test('[layout]', () => {
expect(single).toInclude('<p>foo</p>')

const double = tags.layout({ attr, data, content: ['foo', 'bar'] })
expect(double).toInclude('<section id="epic">')
expect(double).toInclude('<section id="epic">')
})

test('[layout] with nested component', () => {
Expand Down Expand Up @@ -376,7 +376,7 @@ test('parseSpecs', () => {
})

test('parse plain args', () => {
const { name, data }= parseComponent('video src="/a.mp4" loop muted')
const { name, data } = parseComponent('video src="/a.mp4" loop muted')
expect(name).toBe('video')
expect(data.loop).toBe(true)
expect(data.muted).toBe(true)
Expand Down Expand Up @@ -422,6 +422,22 @@ test('parseComponent', () => {

})

test('marked extension', async () => {
const ellipsis = '\u2026'
const marked_extensions = [{
tokenizer: {
inlineText(src) {
const text = src.replace(/\.{3}/g, ellipsis)
return { type: 'text', raw: src, text }
}
}
}]

const { html } = renderLines(['This is a test, right?\n', '...\n', 'Right?\n', '.....'], { marked_extensions })

expect(html).toBe(`<p>This is a test, right?</p>\n<p>${ellipsis}</p>\n<p>Right?</p>\n<p>${ellipsis}..</p>\n`)
})

/*
Required:
bun add react
Expand All @@ -437,16 +453,16 @@ test('JSX component', async () => {

// make them compatible with Nuemark
const lib = Object.keys(jsx).map(name => {
return { name, render: (data) => renderToString(jsx[name](data)) }
return { name, render: (data) => renderToString(jsx[name](data)) }
})

// render JSX with Nuemark
const html = nuemarkdown('[my-test]', { lib, data: { message: 'Hello' } })

expect(html).toBe('<h1 style="color:red">Hello</h1>')

// react not imported
// react not imported
} catch (ignored) {
console.info('JSX test skipped')
console.info('JSX test skipped')
}
})

0 comments on commit 81f343b

Please sign in to comment.