Sphinx "cjkspacer" extension
Project description
sphinxcontrib-cjkspacer
A Sphinx extension, which inserts spacer elements between the Chinese Japanese Korean (CJK) characters and the other characters.
Some of the word processors, e.g., Microsoft® Word and TeX (at least in the case of pTeX), adjust the distances between the CJK characters and the others automatically (c.f. Requirements for Japanese Text Layout#spacing between characters).
Unfortunately, however, HTML with CSS does not have this function as of CSS3 (See the text-spacing
property discussed in some old versions of W3C® Working Draft, e.g., 1 September 2011 and 19 January 2012).
This Sphinx extension provides an alternative function to adjust such distances.
Note
This extension is inspired by sphinxcontrib-trimblank.
The combination betweeen sphinxcontrib-trimblank
and sphinxcontrib-cjkspacer
should work well for the html
builders:
sphinxcontrib-trimblank
removes redundant spaces caused by the limitation of the reStructuredText syntax, and then sphinxcontrib-cjkspacer
adjusts distances between characters (See demo).
Install
pip install sphinxcontrib-cjkspacer
Usage
Add sphinxcontrib.cjkspacer
in the extensions
list in conf.py
.
extensions += ['sphinxcontrib.cjkspacer']
Example
-
In
conf.py
extensions += ['sphinxcontrib.trimblank', 'sphinxcontrib.cjkspacer'] html_css_files = ['custom.css']
-
In
_static/custom.css
.cjkspacer { padding-right: 0.13em; }
Configuration
-
cjkspacer_spacer
: (default:{'html':'<span class="cjkspacer"></span>'}
)A dictionary which has
format
:spacer_string
pairs. Thespacer_string
will be inserted between the CJK characters and the others when the format of the builder isformat
.By using the default value, you can use
.cjkspacer
class in your custom css. For example,.cjkspacer { padding-right: 0.13em; }
If the use of the thin space character is sufficient, this can be achieved by
cjkspacer_spacer_str = {'html': ' '}
This however causes selectable spaces in the text.
-
cjkspacer_cjk_characters
: (default:r'\u2E80-\u9FFF\uF900-\uFAFF\uFF00-\uFF60\uFFE0-\uFFE6\U00020000-\U0003FFFF'
) -
cjkspacer_before_exception
: (default:r'\s\n({\['
) -
cjkspacer_after_exception
: (default:r'\s\n)}\],.'
)These three elements decide the boundaries between the CJK characters and the others characters.
If regular expressions
f'[^{cjkspacer_before_exception}{cjkspacer_cjk_characters}][{cjkspacer_cjk_characters}']
or
f'[{cjkspacer_cjk_characters}'][^{cjkspacer_after_exception}{cjkspacer_cjk_characters}]
match parts of texts, they are regarded as the boundaries.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sphinxcontrib-cjkspacer-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 052d3723cd079233c2aec4ce5b481892f084d5597ddef1536e198b8a7e5823a9 |
|
MD5 | 09cc83c624dfaa212981cb0b70622616 |
|
BLAKE2b-256 | 9e86587451740c7ef0981df676484383557ca5ce78daa778bb5fd7ce6b9fed45 |
Hashes for sphinxcontrib_cjkspacer-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca4429089a97f4f4bc435ba842186f14cc1cb2bf085aef2cf4c4e8a95ed833b |
|
MD5 | 9d5dda8eac98f2391da56f4524c22f41 |
|
BLAKE2b-256 | 48cd904eb51b673eecb44cab4d9e23b362991cd45e944aba05da26dcbc14e3ef |