Skip to content

Commit 9da5a10

Browse files
committed
feat: add collapsable code block sections
1 parent 93e204e commit 9da5a10

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

astro.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @ts-check
2+
import { pluginCollapsibleSections } from '@expressive-code/plugin-collapsible-sections';
23
import { serendipity } from './src/lib/shiki/serendipity-shiki';
34
import { rehypeGithubAlerts } from 'rehype-github-alerts';
45
import expressiveCode from 'astro-expressive-code';
@@ -28,6 +29,11 @@ export default defineConfig({
2829
svelte(),
2930
sitemap(),
3031
expressiveCode({
32+
plugins: [pluginCollapsibleSections()],
33+
defaultProps: {
34+
collapseStyle: 'collapsible-auto',
35+
},
36+
3137
themes: [serendipity],
3238
shiki: {
3339
langs: [await shikiLang('caddyfile')],
@@ -58,6 +64,11 @@ export default defineConfig({
5864
inlineButtonBackgroundHoverOrFocusOpacity: '1',
5965
inlineButtonBackgroundActiveOpacity: '1',
6066
},
67+
collapsibleSections: {
68+
openBackgroundColorCollapsible:
69+
'var(--background-tertiary)',
70+
closedBackgroundColor: 'var(--background-tertiary)',
71+
},
6172
},
6273
}),
6374
],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@astrojs/rss": "^4.0.12",
2020
"@astrojs/sitemap": "^3.4.1",
2121
"@astrojs/svelte": "7.1.0",
22+
"@expressive-code/plugin-collapsible-sections": "^0.41.3",
2223
"@fortawesome/free-brands-svg-icons": "^6.7.2",
2324
"@fortawesome/free-solid-svg-icons": "^6.7.2",
2425
"astro": "^5.8.2",

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/layouts/post.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,10 @@
132132
background: transparent;
133133
border-radius: 4px;
134134
}
135+
136+
// Fix collapsable code allignment
137+
.ec-section summary :is(.expand, .collapse) {
138+
vertical-align: middle;
139+
}
135140
}
136141
}

0 commit comments

Comments
 (0)