sphinx-cjk-aware
CJK-aware inline spacing for Sphinx. Removes the spaces that inline markup needs in order to parse in Chinese and Japanese text, but that those typographies do not want to show. Korean is left alone: its spaces are word boundaries.
Installation
uv add --dev sphinx-cjk-aware
# or
pip install sphinx-cjk-aware
Usage
# conf.py
extensions = [
# ...
"sphinx_cjk_aware",
]
No configuration is required.
The problem
reStructuredText — like CommonMark, cf. markdown-cjk-friendly — recognises inline markup only when its delimiters sit next to whitespace or punctuation. Chinese and Japanese characters count as neither, so emphasis has to be padded to parse:
即它 *为什么* 有效 → 即它 <em>为什么</em> 有效
The padding then shows on the page. Translations hit the same thing in a
subtler way: Sphinx re-parses every msgstr, so *...* in a catalog becomes
real emphasis — together with the spaces that made it recognisable.
With this extension the rendered result is:
即它<em>为什么</em>有效
What gets fixed
A space is removed at the seam between text and an inline element (emphasis, strong, literal, link, role, …) when both sides belong to a script written without word spaces:
Source (or msgstr) |
Renders as |
|---|---|
即它 *为什么* 有效。 |
即它<em>为什么</em>有效。 |
都兼具 **实践表达** 与 **概念把握**。 |
都兼具<strong>实践表达</strong>与<strong>概念把握</strong>。 |
句子 **粗体** 中文。 |
句子<strong>粗体</strong>中文。 |
英文。 **粗体** 结尾。 |
英文。<strong>粗体</strong>结尾。 |
**这些星号。** 都是因为这个句子。 |
<strong>这些星号。</strong>都是因为这个句子。 |
句子 **粗体** (注)结尾。 |
句子<strong>粗体</strong>(注)结尾。 |
**甲** **乙** 并列。 |
<strong>甲</strong><strong>乙</strong>并列。 |
它 *行之有效* —— 无论用户。 |
它<em>行之有效</em>—— 无论用户。 |
这是 ``内嵌代码`` 示例。 |
这是<code>内嵌代码</code>示例。 |
小节 *强调* 标题 |
heading and navigation both glued |
It also handles source lines wrapped before markup, fullwidth space (U+3000),
runs of spaces, and NUL-escaped spaces (\ , common in translated msgstrs).
What is left alone
- Korean —
요리를 하는 *동안* 읽는 책keeps both spaces: they are word boundaries, not markup padding. - English and other Latin-script prose, including the desirable
CJK↔Latin space:
中文 *English* 中文. - Wide emoji, European accented letters, and symbols.
- Literal content —
code-block,parsed-literal, doctest blocks and math, where whitespace is significant. - Plain-text spaces that are not adjacent to inline markup.
What counts as unspaced text
Han characters (Chinese, and Japanese kanji — they share code points),
hiragana, katakana, bopomofo, and CJK punctuation: 。、「」()!:,
fullwidth forms, and —— …… “” ·. Hangul, Latin, emoji and other scripts do
not qualify.
How it works
Following sphinx-cjkspace, the extension fixes the resolved doctree at the last stage instead of changing the parser:
doctree-read(priority 490, before the toctree collector snapshots section titles) — so headings and the navigation agree;doctree-resolved— the last stage before writing.
Parsing, sources and message catalogs are never touched: the gettext
builder is skipped, so .pot msgids stay verbatim for translators.
Compatibility
- Sphinx ≥ 8, docutils 0.20–0.22
- Python ≥ 3.11
- No configuration, no extra runtime dependencies
Development
uv sync --all-extras # create the environment
uv run pytest # tests
uv run ruff check . # lint
uv run ruff format . # format
uv run sphinx-build -W -b html docs docs/_build/html # docs
Releases are published to PyPI from GitHub Actions using
Trusted Publishing (OIDC, no
tokens). The GitHub Release notes are generated by
git-cliff from the commits since the previous
release, grouped by Conventional Commit type. See
.github/workflows/release.yml and
cliff.toml.
License
MIT — see LICENSE.
Metadata
Release files for sphinx-cjk-aware 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sphinx_cjk_aware-0.1.0.tar.gz | 81.5 kB | With provenance | Details for sphinx_cjk_aware-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sphinx_cjk_aware-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sphinx_cjk_aware-0.1.0-py3-none-any.whl |
Total release size: 92.3 kB
Release files / sphinx_cjk_aware-0.1.0.tar.gz
| Download URL | sphinx_cjk_aware-0.1.0.tar.gz |
|---|---|
| Size | 81.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19b01849e9715528741c5285b8a9662432e9e4295012a8088f68aea07d695380
|
|
BLAKE2b-256 checksum How to use checksums |
23f4bf4a3f2682eb2b7a2c43d8d5655eb7846c070c687c8af79fee46aa54778f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / sphinx_cjk_aware-0.1.0-py3-none-any.whl
| Download URL | sphinx_cjk_aware-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3a8657a887ea5bb98088d6dbdbd10c5466783ee4f03cd7a02c01e2361bee1b7
|
|
BLAKE2b-256 checksum How to use checksums |
595f60329a7837889cd9f284415c54b9cb8ab3191af70506382caef2642816ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for sphinx-cjk-aware 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sphinx_cjk_aware-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.