# @comark/plugin-rangi
[](https://npmx.dev/@comark/plugin-rangi)
[](https://npm.chart.dev/@comark/plugin-rangi)
[](https://github.com/comarkdown/comark/actions/workflows/ci.yml)
[](https://comark.dev/plugins/official/rangi)
[](https://github.com/comarkdown/comark/blob/main/LICENSE)
Syntax highlighting for [Comark](https://comark.dev) with [rangi](https://github.com/pi0/rangi), a tiny, synchronous highlighter. Highlights code blocks and language-tagged inline code in HTML, terminal, Vue, React, Svelte and Angular.
## Features
- `rangi` ships as a dependency, so there is nothing else to install
- Synchronous tokenizing and inline theme colors: no stylesheet for a single theme
- Dual themes through `--shiki-dark*` CSS variables
- Language-tagged inline code: `` `Ref`{lang="ts-type"} ``
- Line highlighting from fence metadata: ```` ```ts {2-3,5} ````
- A Comark grammar for `comark`, `mdc`, `md` and `markdown` fences
## Installation
```bash
npm install @comark/plugin-rangi
# or
pnpm add @comark/plugin-rangi
```
## Usage
```ts
import { parseMarkdown } from 'comark'
import rangi from '@comark/plugin-rangi'
const result = await parseMarkdown(content, {
plugins: [rangi()],
})
```
The plugin is renderer agnostic, so the same import works with every framework renderer:
```vue
{{ content }}
```
### Themes
```ts
import { githubDark, githubLight, github } from 'rangi/themes'
rangi({ theme: githubDark }) // single theme
rangi({ theme: github }) // ready-made light/dark pair
rangi({ theme: { light: githubLight, dark: githubDark } })
```
`rangi` is a dependency of the plugin, so install it directly when you import `rangi/themes` in your own code.
### Comark grammar
`@comark/plugin-rangi/language-comark` exports the grammar without the plugin runtime:
```ts
import { tokenize } from 'rangi'
import { comarkLanguages } from '@comark/plugin-rangi/language-comark'
const tokens = tokenize(source, { lang: 'comark', languages: comarkLanguages })
```
## API
- `rangi(options?)` returns the plugin. Options: `theme`, `lineNumbers`, `classPrefix`, `languages`, `preStyles`, `inlineCode`.
- `tokenizeCode(code, language, languages?)` tokenizes with the Comark grammars registered.
- `resolveRangiLanguage(language)` maps a fence language to a rangi language.
- `rangiCodeBlocks(document, options?)` highlights an existing document.
## Documentation
Full guide and API reference at [comark.dev/plugins/official/rangi](https://comark.dev/plugins/official/rangi).
## License
Made with ❤️
Published under [MIT License](https://github.com/comarkdown/comark/blob/main/LICENSE).