Skip to content

Commit 367b016

Browse files
authored
Merge pull request #8 from behitek/claude/blog-code-block-ux-011CV5AMC1pZ5uHgs9FCMemb
Fix blog code blocks and syntax highlighting
2 parents 019ab7a + 5592481 commit 367b016

File tree

13 files changed

+590
-38
lines changed

13 files changed

+590
-38
lines changed

astro.config.mjs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ import { defineConfig } from 'astro/config';
22
import mdx from '@astrojs/mdx';
33
import sitemap from '@astrojs/sitemap';
44
import tailwind from '@astrojs/tailwind';
5+
import remarkDirective from 'remark-directive';
6+
import { visit } from 'unist-util-visit';
7+
import { h } from 'hastscript';
8+
9+
// Custom remark plugin to handle admonitions (:::tip:::, :::warning:::, etc.)
10+
function remarkAdmonitions() {
11+
return (tree) => {
12+
visit(tree, (node) => {
13+
if (
14+
node.type === 'textDirective' ||
15+
node.type === 'leafDirective' ||
16+
node.type === 'containerDirective'
17+
) {
18+
const data = node.data || (node.data = {});
19+
const tagName = node.type === 'textDirective' ? 'span' : 'div';
20+
21+
data.hName = tagName;
22+
data.hProperties = h(tagName, { class: `admonition admonition-${node.name}` }).properties;
23+
}
24+
});
25+
};
26+
}
527

628
// https://astro.build/config
729
export default defineConfig({
@@ -21,13 +43,22 @@ export default defineConfig({
2143
}),
2244
],
2345
markdown: {
46+
remarkPlugins: [remarkDirective, remarkAdmonitions],
2447
shikiConfig: {
25-
theme: 'github-dark',
2648
themes: {
2749
light: 'github-light',
28-
dark: 'github-dark',
50+
dark: 'github-dark-dimmed',
2951
},
3052
wrap: true,
53+
transformers: [
54+
{
55+
name: 'add-copy-button',
56+
pre(node) {
57+
// Add a data attribute to enable copy button
58+
this.addClassToHast(node, 'code-block-wrapper');
59+
},
60+
},
61+
],
3162
},
3263
},
3364
});

0 commit comments

Comments
 (0)