Writing Pelican in Chinese, Japanese, and Korean smoothly.
Newline characters in a paragraph will be kept in the output HTML, then browser will interpret this newline character as a space character. This is fine in English, but it looks weird in CJK. These newline characters will be removed.
- Before:
- 這是第一行 和第二行
- After:
- 這是第一行和第二行
Also, if one of the characters surrounding the newline character is punctuation, it will also be removed.
- Before:
- 句號。 English
- After:
- 句號。English
Insert spaces between a half-width (Alphabets, Numbers, Symbols) word surrounded by CJK characters.
- Before:
- 中間的English Vocabulary單字很Beautiful。
- After:
- 中間的 English Vocabulary 單字很 Beautiful。
Noted that if the neighbor CJK character is punctuation, space will not be added:
- 我會說 English。
- 你如果 Happy,I am happy too。
Auto spacing works on the HTML data without any HTML parser. For simplicity, some less used scenarios are worth noticing:
- The title of an article cannot be changed using the HTML data, so it will not be adjusted.
- If the word is in nested inline markup, no space will be added around
it. This is not possible in reStructuredText, so only Markdown users will be
affected. Examples (in HTML):
Nested<em><strong>行內</strong><em>Markup
: Spaces should be added between Nested, 行內 and Markup. But since 行內 is in nested Markup, spaces won't be added.
- A word in an inline markup immediately after another inline markup will not
be adjusted. Examples:
- 粗體italic
- 程式
foo_bar = 'nice'
寫的不錯
- Text in literal block will also be adjusted. Try not to mix CJK and English in this block.
This is mainly for reStructuredText since it requires a space before and after an inline markup. Because this is more aggressive behavior, it's separated from Auto spacing which you can disable independently.
- Before:
- 中文的 粗體 會有空格。
- After:
- 中文的粗體有空格。
Noted that this has the same limitation as Auto spacing. See Known exceptions and notices for details.
Add this plugin to your pelicanconf.py
. Refer to
pelican-plugins for
more details:
PLUGINS = ['pelican_cjk'] # Change the default the behavior CJK_AUTO_SPACING = False ...
These variables can be used to control the behavior:
CJK_AUTO_SPACING
- Set to
False
to disable Auto spacing. Default toTrue
. CJK_REMOVE_PARAGRAPH_NEWLINE
- Set to
False
to disable Remove newline for CJK paragraph. Default toTrue
. CJK_REMOVE_MARKUP_SPACING
- Set to
False
to disable Remove spacing around inline markups. Default toTrue
.