|
1 |
| -# Markdown-it Wordless |
2 |
| - |
3 |
| -A [markdown-it](https://markdown-it.github.io) plugin |
4 |
| -to optimize wordless multi-language line-break render. |
5 |
| - |
6 |
| -When a paragraph is long in markdown, we usually separate them into lines, |
7 |
| -and it will finally be rendered into a single line inside HTML. |
8 |
| -But for wordless languages (such as Chinese and Japanese), |
9 |
| -they do not use spaces to separate words, |
10 |
| -that they don't need a space to be added when processing line-break. |
11 |
| - |
12 |
| -If you are only working with a single wordless language, |
13 |
| -you can definitely use the following code, |
14 |
| -which will disable all spaces when line break |
15 |
| -(render single `\n` into an empty string rather than a space): |
16 |
| - |
17 |
| -```ts |
18 |
| -import md from "markdown-it" |
19 |
| -md.renderer.rules.softbreak = () => "" |
20 |
| -``` |
21 |
| - |
22 |
| -But once working with multi-languages, |
23 |
| -especially when there's a mix of wordless and wordful languages, |
24 |
| -such as using Chinese and English in a single markdown document, |
25 |
| -such options cannot handle all cases. |
26 |
| -So here comes this `"markdown-it-wordless"` plugin, |
27 |
| -and you can use it like this: |
28 |
| - |
29 |
| -```ts |
30 |
| -import md from "markdown-it" |
31 |
| -import {Options} from "markdown-it-wordless" |
32 |
| -md.use(wordless) |
33 |
| -``` |
34 |
| - |
35 |
| -## Basic rules |
36 |
| - |
37 |
| -1. Wordful languages (such as English and Arabic) will be rendered as usual. |
38 |
| -2. It won't add a space when line break between the same wordless language. |
39 |
| -3. It will add a space when line break between different wordless languages. |
40 |
| -4. Specially, Chinese and Japanese will be treated as a same language, |
41 |
| - as there are many shared characters between them, |
42 |
| - and their character styles are almost the same. |
43 |
| -5. Although Korean characters are like Chinese and Japanese (CJK), |
44 |
| - Korean is not a wordless language, it uses spaces to separate words. |
45 |
| - |
46 |
| -## Use it with VitePress |
47 |
| - |
48 |
| -[VitePress](https://vitepress.dev) is an excellent static site generator, |
49 |
| -and this package is also inspired when the author using VitePress. |
50 |
| -It's strongly recommended to add such plugin to VitePress |
51 |
| -if you are using wordless languages. And here's how to config: |
52 |
| - |
53 |
| -```ts |
54 |
| -// <root>/.vitepress/config.ts |
55 |
| -import {defineConfig} from "vitepress" |
56 |
| -import {wordless} from "markdown-it-wordless" |
57 |
| - |
58 |
| -export default defineConfig({ |
59 |
| - markdown: { |
60 |
| - config(md) { |
61 |
| - md.use(wordless) |
62 |
| - }, |
63 |
| - }, |
64 |
| - // Other configs... |
65 |
| -}) |
66 |
| -``` |
67 |
| - |
68 |
| -## Customize to optimize performance |
69 |
| - |
70 |
| -The default option will enable optimization |
71 |
| -for all registered wordless languages inside this package. |
72 |
| -If you want to optimize performance, |
73 |
| -you can specify what exactly wordless language you are using. |
74 |
| -You may also specify what wordful language you are using, |
75 |
| -because there's only optimization for wordful languages |
76 |
| -which unicode is less than `0x0dff`. |
77 |
| - |
78 |
| -Here's a simple example |
79 |
| -if you will only use Chinese or Japanese as wordless languages: |
80 |
| - |
81 |
| -```ts |
82 |
| -import md from "markdown-it" |
83 |
| -import {wordless, chineseAndJapanese, Options} from "markdown-it-wordless" |
84 |
| -md.use<Options>(wordless, {supportWordless: [chineseAndJapanese]}) |
85 |
| -``` |
86 |
| - |
87 |
| -Such optimization is unnecessary in most cases, |
88 |
| -because this plugin will not slow down the rendering process a lot |
89 |
| -in common cases (only a few milliseconds). |
90 |
| -And if you do want to customize, |
91 |
| -please make sure you've understand the source code. Please refer to |
92 |
| -[`data.ts`](https://github.com/treeinfra/markdown-it-wordless/blob/main/data.ts) |
93 |
| -for more details, |
94 |
| -and here's documentation for each item in details. |
95 |
| - |
96 |
| -## About the supported languages |
97 |
| - |
98 |
| -You can find all supported languages |
99 |
| -in the source code of |
100 |
| -[`data.ts`](https://github.com/treeinfra/markdown-it-wordless/blob/main/data.ts). |
101 |
| -Each language or language series is an exported const |
102 |
| -that you can import and call. |
103 |
| - |
104 |
| -The languages series are based on the [Unicode](https://unicode.org/charts/). |
105 |
| -Most of the languages are coded manually and some of them are |
106 |
| -generated by several AI models. So that there might be mistakes, |
107 |
| -and the author cannot guarantee the accuracy of the data |
108 |
| -because it's almost impossible for a single person to learn all such languages. |
109 |
| - |
110 |
| -If you are native speaker of one of the those wordless languages |
111 |
| -and you find there are some mistakes, |
112 |
| -or if there's even some wordless languages not included in this package, |
113 |
| -please feel free to open an issue. |
| 1 | +<!-- @include: ../README.md --> |
0 commit comments