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.
- Host: GitHub
- URL: https://github.com/unix/rehype-join-line
- Owner: unix
- License: mit
- Created: 2020-03-09T07:19:16.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T09:29:36.000Z (almost 3 years ago)
- Last Synced: 2025-03-30T06:01:35.379Z (9 months ago)
- Language: JavaScript
- Size: 980 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)