diff --git a/__tests__/unit/node/markdown/plugins/containers.test.ts b/__tests__/unit/node/markdown/plugins/containers.test.ts index bd48c5814..ffee6c777 100644 --- a/__tests__/unit/node/markdown/plugins/containers.test.ts +++ b/__tests__/unit/node/markdown/plugins/containers.test.ts @@ -8,13 +8,18 @@ import type { MarkdownEnv } from 'node/shared' async function render( src: string, options: MarkdownOptions = {}, - env?: Partial + env?: Partial, + base = '/' ) { disposeMdItInstance() - const md = await createMarkdownRenderer('.', { - highlight: (code) => code, - ...options - }) + const md = await createMarkdownRenderer( + '.', + { + highlight: (code) => code, + ...options + }, + base + ) return md.renderAsync(src, env) } @@ -114,6 +119,48 @@ describe('node/markdown/plugins/containers', () => { `) }) + test.each([ + ['/', true, true, '/guide/start'], + ['./', false, true, '../guide/start.html'], + ['./', true, true, '../guide/start'], + ['./', false, false, '/guide/start.html'] + ])( + 'uses page URL settings in titles (base: %s, cleanUrls: %s, relativizeUrls: %s)', + async (base, cleanUrls, relativizeUrls, href) => { + const src = [ + '::: tip [Guide][guide]', + '[Guide][guide]', + ':::', + '', + '::: details [Guide][guide]', + 'content', + ':::', + '', + '[guide]: /guide/start.md' + ].join('\n') + const html = await render( + src, + {}, + { cleanUrls, relativePath: 'nested/page.md', relativizeUrls }, + base + ) + const link = `Guide` + expect(html).toContain(`

${link}

`) + expect(html).toContain(`${link}`) + expect(html).toContain(`

${link}

`) + } + ) + + test('keeps page footnotes out of container titles', async () => { + const html = await render( + '::: tip [Guide](/guide.md)\nText[^1]\n:::\n\n[^1]: A note' + ) + expect(html).toContain( + '

Guide

' + ) + expect(html.match(/class="footnotes"/g)).toHaveLength(1) + }) + test('respects custom labels from container options', async () => { const src = '::: tip\n提示内容\n:::\n\n::: details\n详情内容\n:::' expect( diff --git a/src/node/markdown/plugins/containers.ts b/src/node/markdown/plugins/containers.ts index 88c7c87bc..1e8925ebd 100644 --- a/src/node/markdown/plugins/containers.ts +++ b/src/node/markdown/plugins/containers.ts @@ -138,7 +138,13 @@ function createOpenRender( if (noTitle) return `
\n` const title = md.renderInline( info || titlesFor(titles, env.localeIndex)[name], - { references: env.references, frontmatter: env.frontmatter } + { + references: env.references, + frontmatter: env.frontmatter, + cleanUrls: env.cleanUrls, + relativePath: env.relativePath, + relativizeUrls: env.relativizeUrls + } ) if (name === 'details') return `
${title}\n`