This project is based on the Astro framework and uses @shikijs/transformers for advanced code highlighting and formatting.
This project combines Astro's powerful static site generation capabilities with Shiki's advanced code highlighting features. By adding @shikijs/transformers, you can create richer and more interactive code blocks compared to plain Shiki.
You can run this project directly in your browser without any local setup:
This StackBlitz link allows you to instantly explore and experiment with the project in a live development environment.
Using @shikijs/transformers, you can leverage advanced code representation features such as:
- Diff Highlighting: Visually display code changes
- Line Highlighting: Emphasize specific code lines
- Focus: Draw attention to important parts of the code
These features make code examples clearer and easier to understand.
If you prefer to run the project locally:
-
Clone this repository:
git clone https://github.com/EasyDevv/astro-shiki-transformers.git
-
Navigate to the project directory:
cd astro-shiki-transformers
-
Install dependencies:
npm install
-
Run the development server:
npm run dev
-
Open
http://localhost:4321
in your browser to view the project.
Shiki Transformers are configured in the astro.config.mjs
file. Here's an example of setting up some useful transformers:
import { defineConfig } from 'astro/config';
import {
transformerNotationDiff,
transformerNotationHighlight,
transformerNotationWordHighlight,
transformerNotationFocus,
transformerNotationErrorLevel,
transformerMetaHighlight,
transformerMetaWordHighlight,
transformerRenderWhitespace,
} from '@shikijs/transformers';
export default defineConfig({
markdown: {
syntaxHighlight: 'shiki',
shikiConfig: {
theme: 'github-dark',
transformers: [
transformerNotationDiff(),
transformerNotationHighlight(),
transformerNotationWordHighlight(),
transformerNotationFocus(),
transformerNotationErrorLevel(),
transformerMetaHighlight(),
transformerMetaWordHighlight(),
transformerRenderWhitespace(),
],
},
},
});
After this configuration, you can use it in your markdown files like this:
```ts
console.log('hewwo') // [!code --]
console.log('hello') // [!code ++]
console.log('goodbye')
```
This project is distributed under the MIT License. See the LICENSE
file for more details.