Do you want to display your code snippet like this?
Enhance your Astro syntax highlighter with Rehype Pretty Code to incorporate these features:
Title
Caption
Line Numbers
Line Highlighting
Word Highlighting
Inline Code Highlighting
and more
Upgrade Packages
Make you have latest integration packages. As of the time of writing, we were using the following versions:
astro: 4.1.1
tailwindcss: 3.4.1
@astrojs/tailwind: 5.1.0
Disable The Default Tailwind Integration
Create src/styles/global.css.
Import the style into your base layout, in my AstroMon starter theme this is src/layouts/base.layout.astro.
Edit astro.config.mjs and update tailwind() section.
Install Rehype Pretty Code
Edit astro.config.mjs to disable default syntax highlighter and add rehypePlugins.
You can add additional options inside the {}, checkout their docs for details.
Styling The Code Block
At this point, Astro already highlights your syntax using rehype-pretty-code but is still unstyled. Adjustments are needed in the Tailwind section.
This HTML structure represents the output for your reference:
These styles are a starting point,you may need to customize them to align with your siteβs overall design. Alternatively, if you prefer a pre-made Astro theme, check out the AstroMon starter theme.