Skip to content

Commit 0c21898

Browse files
committed
fix(code-block): apply shiki theme bg to wrapping td
The Shiki theme background only landed on the `<pre>`, leaving the td's mso-padding-alt-4 area to show through as white in Outlook — visible as a white frame around dark themes.
1 parent 10bc2cd commit 0c21898

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/components/CodeBlock.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
const baseStyles = `background-color:${bg};padding:16px;overflow:auto;white-space:pre;word-wrap:normal;word-break:normal;word-spacing:normal`
6262
const styles = [baseStyles, attrs.style].filter(Boolean).join(';')
6363
64-
const html = `<table class="w-full"><tr><td class="${props.tdClass}"><pre class="${classes}" style="${styles}"><code>${codeContent}</code></pre></td></tr></table>`
64+
const html = `<table class="w-full"><tr><td class="${props.tdClass}" style="background-color:${bg}"><pre class="${classes}" style="${styles}"><code>${codeContent}</code></pre></td></tr></table>`
6565
6666
return () => createStaticVNode(html, 1)
6767
}

src/tests/components/CodeBlock.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,27 @@ describe('CodeBlock', () => {
7474
it('uses default td-class', async () => {
7575
const html = await render({ code: '<div>test</div>' })
7676

77-
expect(html).toContain('<td class="max-w-0 mso-padding-alt-4">')
77+
expect(html).toContain('<td class="max-w-0 mso-padding-alt-4"')
7878
})
7979

8080
it('accepts custom td-class', async () => {
8181
const html = await render({ code: '<div>test</div>', 'td-class': 'custom-class' })
8282

83-
expect(html).toContain('<td class="custom-class">')
83+
expect(html).toContain('<td class="custom-class"')
84+
})
85+
86+
it('sets the shiki theme background on the wrapping td', async () => {
87+
const html = await render({ code: '<div>test</div>' })
88+
89+
// github-light bg is #fff — must appear on the td so Outlook's td
90+
// padding doesn't show through as white on a dark theme.
91+
expect(html).toMatch(/<td[^>]*style="background-color:#fff"/)
92+
})
93+
94+
it('uses the dark theme bg on the wrapping td', async () => {
95+
const html = await render({ code: '<div>test</div>', theme: 'github-dark' })
96+
97+
expect(html).toMatch(/<td[^>]*style="background-color:#24292e"/)
8498
})
8599
})
86100

0 commit comments

Comments
 (0)