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
6 changes: 3 additions & 3 deletions src/components/CodeBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export default {
type: String as PropType<BundledTheme>,
default: 'github-light'
},
/** CSS class for the wrapping table cell. @default 'max-w-0 mso-padding-alt-4' */
/** Extra CSS classes for the wrapping table cell, merged over the base `max-w-0 mso-padding-alt-4`. */
tdClass: {
type: String,
default: 'max-w-0 mso-padding-alt-4'
default: ''
}
},
inheritAttrs: false,
Expand Down Expand Up @@ -59,7 +59,7 @@ export default {
.replace(/<\/code><\/pre>$/, '')

const preClass = twMerge(codeBlockPreClass(bg), attrs.class as string)
const tdClass = twMerge(`bg-[${bg}]`, props.tdClass)
const tdClass = twMerge(`bg-[${bg}] max-w-0 mso-padding-alt-4`, props.tdClass)
const styleAttr = attrs.style ? ` style="${attrs.style}"` : ''

const html = buildCodeBlock(codeContent, bg, { preClass, tdClass, styleAttr })
Expand Down
14 changes: 14 additions & 0 deletions src/tests/components/CodeBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ describe('CodeBlock', () => {
expect(html).toMatch(/<td class="[^"]*\bbg-\[#fff\]/)
})

it('keeps base td-class defaults when a custom td-class is passed', async () => {
const html = await render({ code: '<div>test</div>', 'td-class': 'custom-class' })

expect(html).toMatch(/<td class="[^"]*\bmax-w-0\b/)
expect(html).toMatch(/<td class="[^"]*\bmso-padding-alt-4\b/)
})
Comment on lines +103 to +108

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the custom class is preserved in the additive td-class test.

The test checks base class retention but not that the passed custom class survives merge (Line 104). Add an assertion for custom-class so the additive contract is fully covered.

Suggested test tweak
 it('keeps base td-class defaults when a custom td-class is passed', async () => {
   const html = await render({ code: '<div>test</div>', 'td-class': 'custom-class' })

+  expect(html).toMatch(/<td class="[^"]*\bcustom-class\b/)
   expect(html).toMatch(/<td class="[^"]*\bmax-w-0\b/)
   expect(html).toMatch(/<td class="[^"]*\bmso-padding-alt-4\b/)
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('keeps base td-class defaults when a custom td-class is passed', async () => {
const html = await render({ code: '<div>test</div>', 'td-class': 'custom-class' })
expect(html).toMatch(/<td class="[^"]*\bmax-w-0\b/)
expect(html).toMatch(/<td class="[^"]*\bmso-padding-alt-4\b/)
})
it('keeps base td-class defaults when a custom td-class is passed', async () => {
const html = await render({ code: '<div>test</div>', 'td-class': 'custom-class' })
expect(html).toMatch(/<td class="[^"]*\bcustom-class\b/)
expect(html).toMatch(/<td class="[^"]*\bmax-w-0\b/)
expect(html).toMatch(/<td class="[^"]*\bmso-padding-alt-4\b/)
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/components/CodeBlock.test.ts` around lines 103 - 108, The test
'keeps base td-class defaults when a custom td-class is passed' validates that
base classes are retained but does not verify that the passed custom-class is
actually preserved in the rendered HTML output. Add an assertion using
expect(html).toMatch() to verify that 'custom-class' appears in the td class
attribute, ensuring the additive class merge behavior is fully tested.


it('lets a custom td-class override a conflicting base utility via twMerge', async () => {
const html = await render({ code: '<div>test</div>', 'td-class': 'max-w-full' })

expect(html).toMatch(/<td class="[^"]*\bmax-w-full\b/)
expect(html).not.toMatch(/<td class="[^"]*\bmax-w-0\b/)
})

it('sets the shiki theme background on the wrapping td as a class', async () => {
const html = await render({ code: '<div>test</div>' })

Expand Down
Loading