An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# remark-translit-slug

[![npm](https://img.shields.io/npm/v/remark-translit-slug?style=for-the-badge&logo=npm&logoColor=white&labelColor=CB3837&color=CB3837)](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