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

https://github.com/unix/rehype-join-line

Resolve line breaks in chinese paragraphs.
https://github.com/unix/rehype-join-line

Last synced: 8 months ago
JSON representation

Resolve line breaks in chinese paragraphs.

Awesome Lists containing this project

README

          

## rehype-join-line

[rehype](https://github.com/rehypejs/rehype) plugin to resolve line breaks in chinese paragraphs.

## What happened?

This is a legacy issue of HTML, you can see more discussion [here](https://stackoverflow.com/questions/8550112/prevent-browser-converting-n-between-lines-into-space-for-chinese-characters).
In short, English needs to add spaces when wrapping paragraphs, but the Chinese characters will be split:

```html


This is
an example

// In English, it will be rendered ->

This is an example


```

```html


这是
一个示例

// In Chinese, it will be rendered ->

这是 一个示例


```

As we can see, there is no need for **spaces** in Chinese paragraphs.

In Markdown or Markdown renderer, this problem also exists. This plug-in is to help `rehype` solve this problem.

## How to use?

### Install

Run `npm install rehype-join-line`.

### Usage

```js
const rehype = require('rehype');
const rehypeJoinLine = require('rehype-join-line');

rehype()
.use(rehypeJoinLine)
.process(/* some html */);
```

### Use in Next.js

```js
// in next.config.js
const withMDX = require('@next/mdx')({
extension: /\.(md|mdx)?$/,
options: {
rehypePlugins: [require('rehype-join-line')],
},
})

module.exports = withMDX({
// next config
})
```

### How to work?

In Chinese: Please **wrap after Chinese punctuation**, all excess white space will be removed automatically.

In English: No impact.

E.g.

```
// before
你好,
这个世界

// it will be rendered ->

你好, 这个世界



// after
你好,
这个世界

// it will be rendered ->

你好,这个世界


```

### LICENSE

Licensed under the [MIT LICENSE.](./LICENSE)