diff --git a/__tests__/unit/node/markdown/plugins/containers.test.ts b/__tests__/unit/node/markdown/plugins/containers.test.ts index f3005c9b8..d84bc6ca4 100644 --- a/__tests__/unit/node/markdown/plugins/containers.test.ts +++ b/__tests__/unit/node/markdown/plugins/containers.test.ts @@ -32,25 +32,25 @@ describe('node/markdown/plugins/containers', () => { .map((t) => `::: ${t}\ncontent of ${t}\n:::`) .join('\n\n') expect(await render(src)).toMatchInlineSnapshot(` - "

TIP

+ "

TIP

content of tip

-

INFO

+

INFO

content of info

-

WARNING

+

WARNING

content of warning

-

DANGER

+

DANGER

content of danger

-

NOTE

+

NOTE

content of note

-

IMPORTANT

+

IMPORTANT

content of important

-

CAUTION

+

CAUTION

content of caution

" @@ -60,11 +60,11 @@ describe('node/markdown/plugins/containers', () => { test('renders details as a disclosure with summary', async () => { expect(await render('::: details\nhidden content\n:::')) .toMatchInlineSnapshot(` - "
Details -

hidden content

-
- " - `) + "
Details +

hidden content

+
+ " + `) }) test('renders custom titles, including inline markdown', async () => { @@ -84,13 +84,13 @@ describe('node/markdown/plugins/containers', () => { ':::' ].join('\n') expect(await render(src)).toMatchInlineSnapshot(` - "

STOP

+ "

STOP

Danger zone, do not proceed

-

A bold title with code

+

A bold title with code

content

-
Click me to toggle the code +
Click me to toggle the code
js
console.log('hi')
       
@@ -107,7 +107,7 @@ describe('node/markdown/plugins/containers', () => { '[guide]: /guide/' ].join('\n') expect(await render(src)).toMatchInlineSnapshot(` - "

See the guide

+ "

See the guide

content

" @@ -121,10 +121,10 @@ describe('node/markdown/plugins/containers', () => { container: { tipLabel: '提示', detailsLabel: '详细信息' } }) ).toMatchInlineSnapshot(` - "

提示

+ "

提示

提示内容

-
详细信息 +
详细信息

详情内容

" @@ -146,10 +146,10 @@ describe('node/markdown/plugins/containers', () => { container: { customContainers: { success: 'SUCCESS' } } }) ).toMatchInlineSnapshot(` - "

SUCCESS

+ "

SUCCESS

You have completed the walkthrough!

-
+

content

" @@ -175,10 +175,10 @@ describe('node/markdown/plugins/containers', () => { ':::' ].join('\n') expect(await render(src)).toMatchInlineSnapshot(` - "
Click me + "
Click me

content

-

Custom

+

Custom

content

" @@ -188,11 +188,11 @@ describe('node/markdown/plugins/containers', () => { test('supports quoted and bare attr values on the fence line', async () => { expect(await render('::: tip Custom {data-a="b c" data-d=e}\ncontent\n:::')) .toMatchInlineSnapshot(` - "

Custom

-

content

-
- " - `) + "

Custom

+

content

+
+ " + `) }) test('skips the title element with a no-title attr', async () => { @@ -210,26 +210,42 @@ describe('node/markdown/plugins/containers', () => { ':::' ].join('\n') expect(await render(src)).toMatchInlineSnapshot(` - "
+ "

content

-
+

content

-
Details +
Details

still needs its summary

" `) }) + // FIXME: enable after attrs plugin version bump + test.skip('respects attrs plugin options on the fence line', async () => { + const delimiters = await render( + '::: tip Custom %(.extra-class)%\ncontent\n:::', + { attrs: { left: '%(', right: ')%' } } + ) + expect(delimiters).toContain('
') + + const allowed = await render( + '::: tip Custom {.extra-class data-x=1}\ncontent\n:::', + { attrs: { allowed: ['class'] } } + ) + expect(allowed).toContain('
') + expect(allowed).not.toContain('data-x') + }) + test('keeps fence line braces verbatim when attrs are disabled', async () => { expect( await render('::: details Click me {open}\ncontent\n:::', { attrs: false }) ).toMatchInlineSnapshot(` - "
Click me {open} + "
Click me {open}

content

" @@ -293,9 +309,9 @@ describe('node/markdown/plugins/containers', () => { '::::' ].join('\n') expect(await render(src)).toMatchInlineSnapshot(` - "

Outer

+ "

Outer

outer content

-
Inner +
Inner

inner content

@@ -306,16 +322,16 @@ describe('node/markdown/plugins/containers', () => { test('auto-closes unclosed containers', async () => { expect(await render('::: warning\nno closing fence')) .toMatchInlineSnapshot(` - "

WARNING

-

no closing fence

-
- " - `) + "

WARNING

+

no closing fence

+
+ " + `) }) test('parses fences without a space before the name', async () => { expect(await render(':::tip\ncontent\n:::')).toMatchInlineSnapshot(` - "

TIP

+ "

TIP

content

" @@ -507,13 +523,13 @@ describe('node/markdown/plugins/containers (locales)', () => { '::: tip\n内容\n:::\n\n::: details\n内容\n:::\n\n::: success\n内容\n:::' expect(await render(src, options, { localeIndex: 'zh' })) .toMatchInlineSnapshot(` - "

提示

+ "

提示

内容

-
详细信息 +
详细信息

内容

-

成功

+

成功

内容

" @@ -525,7 +541,7 @@ describe('node/markdown/plugins/containers (locales)', () => { const root = await render(src, options) expect(await render(src, options, { localeIndex: 'es' })).toBe(root) expect(root).toMatchInlineSnapshot(` - "

ROOT TIP

+ "

ROOT TIP

content

" @@ -538,7 +554,7 @@ describe('node/markdown/plugins/containers (locales)', () => { localeIndex: 'zh' }) ).toMatchInlineSnapshot(` - "

Custom Title

+ "

Custom Title

内容

" diff --git a/src/node/markdown/plugins/containers.ts b/src/node/markdown/plugins/containers.ts index 47124fefc..77cf6d872 100644 --- a/src/node/markdown/plugins/containers.ts +++ b/src/node/markdown/plugins/containers.ts @@ -138,7 +138,7 @@ function createOpenRender( // details always needs its summary, so no-title is ignored there const noTitle = attrPop(token, 'no-title') === '' && name !== 'details' token.attrJoin('class', `${name} custom-block`) - const renderedAttrs = md.renderer.renderAttrs(token) + const renderedAttrs = md.renderer.renderAttrs(token).trim() if (noTitle) return `
\n` const title = md.renderInline( info || titlesFor(titles, env.localeIndex)[name],