Package Exports
- @astropub/code
- @astropub/code/prism
- @astropub/code/types
Readme
Astro Code 
Astro Code enables code syntax highlighting and rendering in Astro projects.
- Syntax Highlighting: Beautifully highlight code blocks in various programming languages.
- Syntax highlighting for popular languages like JavaScript, TypeScript, HTML, CSS, and more.
- Lightweight: Minimal dependency footprint for faster builds.
- A fully optimized ESM version of Prism for modern web apps.
- Customizable: Easily adapt the component to your project's needs.
- Customize styles and themes using your own CSS.
Installation
Install the component via npm:
npm install @astropub/codeImport and use the component in your Astro files:
---
import Code from "@astropub/code"
---
<Code lang="js" code="const str = 'string'">Usage
To display a syntax-highlighted code block:
---
import Code from "@astropub/code"
---
<Code lang="html" code="<h1>Hello, Astro!</h1>"></Code>Multi-Line Code
Pass an array of strings to the code prop:
---
import Code from "@astropub/code"
---
<Code lang="css" code={[
"body {",
" margin: 0;",
"}"
]}></Code>Supported Languages
Out of the box, Astro Code supports these languages via Prism.js:
| Language | Type Value |
|---|---|
| Scripting | js jsx ts tsx |
| Content | html svg xml |
| Styling | css |
| Shell | sh |
API Reference
| Atttribute | Type | Description |
|---|---|---|
code |
string string[] |
Code to render. |
lang |
string |
Language of highlighting. |
License
Licensed under the MIT-0 License.
Enjoy!