https://github.com/pilaton/remark-translit-slug
A remark plugin that transliterates headers into slug-IDs.
https://github.com/pilaton/remark-translit-slug
Last synced: 3 months ago
JSON representation
A remark plugin that transliterates headers into slug-IDs.
- Host: GitHub
- URL: https://github.com/pilaton/remark-translit-slug
- Owner: Pilaton
- License: mit
- Created: 2025-02-09T14:06:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-15T14:28:17.000Z (7 months ago)
- Last Synced: 2025-12-19T08:09:36.592Z (6 months ago)
- Language: TypeScript
- Homepage: https://npmjs.com/package/remark-translit-slug
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# remark-translit-slug
[](https://www.npmjs.com/package/remark-translit-slug)
A plugin for [remark](https://github.com/remarkjs/remark) that transliterates headers into slug identifiers.
Most major languages are supported. The full list can be [seen here](https://github.com/sindresorhus/transliterate#supported-languages).
## Install
```bash
npm install remark-translit-slug
```
## Usage
Plug the plugin into your remark processing chain:
```js
import { remark } from "remark";
import remarkTranslitSlug from "remark-translit-slug";
import remarkToc from "remark-toc";
const file = await remark()
.use(remarkTranslitSlug, {
separator: "-", // Separator for slug (default '-')
lowercase: true, // Make the slug lowercase (defaults to true)
decamelize: false, // Convert camelcase to separate words. Internally it does fooBar → foo bar. (defaults to false)
preserveExistingIds: true, // Keep user-defined ids instead of overwriting them (defaults to true)
})
.use(remarkToc);
```
Example usage with `next.js --turbopack` + `@next/mdx`:
```js
import createMdx from "@next/mdx";
// nextConfig ...
const withMdx = createMdx({
options: {
remarkPlugins: [
[
"remark-translit-slug",
{
separator: "-",
lowercase: true,
},
],
[
"remark-toc",
{
heading: "table-of-contents",
tight: true,
maxDepth: 3,
},
],
],
},
});
export default withMdx(nextConfig);
```
## Result
Source markdown:
```md
# Hello world!
## Table of contents
---
## Hello in English
## Dobrý den v češtině
## مرحباً بالعربية
## Привет на русском
## Witam w języku polskim
```
The result is this html:
```html
Hello world!
Table of contents
Hello in English
Dobrý den v češtině
مرحباً بالعربية
Привет на русском
Witam w języku polskim
```
This example shows the simultaneous operation of the `remark-translit-slug` plugin and the `remark-toc` plugin.
The [remark-toc](https://github.com/remarkjs/remark-toc) plugin automatically created a «Table of contents» for us with the correct links that have undergone transliteration.
## API
The plugin is set up so that the basic configuration will work for most and will not require reconfiguration.
But if you do need to make changes, the options are fully consistent with the [Slugify](https://github.com/sindresorhus/slugify) plugin. You can read more about them [here](https://github.com/sindresorhus/slugify?tab=readme-ov-file#api).
## License
MIT