sphinx-cjk-aware 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sphinx_cjk_aware-0.1.0/.github/dependabot.yml +22 -0
- sphinx_cjk_aware-0.1.0/.github/workflows/ci.yml +80 -0
- sphinx_cjk_aware-0.1.0/.github/workflows/release.yml +85 -0
- sphinx_cjk_aware-0.1.0/.gitignore +27 -0
- sphinx_cjk_aware-0.1.0/.pre-commit-config.yaml +7 -0
- sphinx_cjk_aware-0.1.0/.python-version +1 -0
- sphinx_cjk_aware-0.1.0/CHANGELOG.md +24 -0
- sphinx_cjk_aware-0.1.0/CONTRIBUTING.md +78 -0
- sphinx_cjk_aware-0.1.0/LICENSE +21 -0
- sphinx_cjk_aware-0.1.0/PKG-INFO +167 -0
- sphinx_cjk_aware-0.1.0/README.md +134 -0
- sphinx_cjk_aware-0.1.0/cliff.toml +52 -0
- sphinx_cjk_aware-0.1.0/docs/behaviour.md +48 -0
- sphinx_cjk_aware-0.1.0/docs/conf.py +17 -0
- sphinx_cjk_aware-0.1.0/docs/how-it-works.md +58 -0
- sphinx_cjk_aware-0.1.0/docs/index.md +62 -0
- sphinx_cjk_aware-0.1.0/pyproject.toml +87 -0
- sphinx_cjk_aware-0.1.0/src/sphinx_cjk_aware/__init__.py +18 -0
- sphinx_cjk_aware-0.1.0/src/sphinx_cjk_aware/_charclass.py +62 -0
- sphinx_cjk_aware-0.1.0/src/sphinx_cjk_aware/_doctree.py +134 -0
- sphinx_cjk_aware-0.1.0/src/sphinx_cjk_aware/_extension.py +89 -0
- sphinx_cjk_aware-0.1.0/src/sphinx_cjk_aware/_version.py +7 -0
- sphinx_cjk_aware-0.1.0/src/sphinx_cjk_aware/py.typed +0 -0
- sphinx_cjk_aware-0.1.0/tests/__init__.py +0 -0
- sphinx_cjk_aware-0.1.0/tests/conftest.py +39 -0
- sphinx_cjk_aware-0.1.0/tests/support.py +126 -0
- sphinx_cjk_aware-0.1.0/tests/test_char_class.py +85 -0
- sphinx_cjk_aware-0.1.0/tests/test_doctree_pass.py +104 -0
- sphinx_cjk_aware-0.1.0/tests/test_gettext_extraction.py +66 -0
- sphinx_cjk_aware-0.1.0/tests/test_inline_seams.py +201 -0
- sphinx_cjk_aware-0.1.0/tests/test_package.py +25 -0
- sphinx_cjk_aware-0.1.0/tests/test_translations.py +106 -0
- sphinx_cjk_aware-0.1.0/tests/test_untouched_cases.py +114 -0
- sphinx_cjk_aware-0.1.0/uv.lock +1106 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
|
|
3
|
+
updates:
|
|
4
|
+
- package-ecosystem: "uv"
|
|
5
|
+
directory: "/"
|
|
6
|
+
schedule:
|
|
7
|
+
interval: "weekly"
|
|
8
|
+
groups:
|
|
9
|
+
python-dependencies:
|
|
10
|
+
patterns: ["*"]
|
|
11
|
+
ignore:
|
|
12
|
+
# docutils is constrained by Sphinx (<0.23); Dependabot's update to
|
|
13
|
+
# 0.23 cannot resolve and fails the whole group.
|
|
14
|
+
- dependency-name: "docutils"
|
|
15
|
+
|
|
16
|
+
- package-ecosystem: "github-actions"
|
|
17
|
+
directory: "/"
|
|
18
|
+
schedule:
|
|
19
|
+
interval: "weekly"
|
|
20
|
+
groups:
|
|
21
|
+
github-actions:
|
|
22
|
+
patterns: ["*"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
lint:
|
|
17
|
+
name: Lint
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v7.0.1
|
|
21
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
22
|
+
with:
|
|
23
|
+
enable-cache: auto
|
|
24
|
+
- run: uv sync --locked --all-extras
|
|
25
|
+
- run: uv run ruff check .
|
|
26
|
+
- run: uv run ruff format --check .
|
|
27
|
+
|
|
28
|
+
test:
|
|
29
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
strategy:
|
|
32
|
+
fail-fast: false
|
|
33
|
+
matrix:
|
|
34
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v7.0.1
|
|
37
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
38
|
+
with:
|
|
39
|
+
enable-cache: auto
|
|
40
|
+
python-version: ${{ matrix.python-version }}
|
|
41
|
+
- run: uv sync --locked --all-extras
|
|
42
|
+
- run: uv run pytest --cov --cov-report=term-missing
|
|
43
|
+
|
|
44
|
+
test-minimum:
|
|
45
|
+
name: Test (minimum Sphinx)
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@v7.0.1
|
|
49
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
50
|
+
with:
|
|
51
|
+
enable-cache: auto
|
|
52
|
+
python-version: "3.11"
|
|
53
|
+
- run: uv sync --locked --all-extras
|
|
54
|
+
- run: uv run --with "sphinx<9" --with "docutils<0.22" pytest -q
|
|
55
|
+
|
|
56
|
+
docs:
|
|
57
|
+
name: Docs
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v7.0.1
|
|
61
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
62
|
+
with:
|
|
63
|
+
enable-cache: auto
|
|
64
|
+
- run: uv sync --locked --all-extras
|
|
65
|
+
- run: uv run sphinx-build -W --keep-going -b html docs docs/_build/html
|
|
66
|
+
|
|
67
|
+
build:
|
|
68
|
+
name: Build package
|
|
69
|
+
runs-on: ubuntu-latest
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v7.0.1
|
|
72
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
73
|
+
with:
|
|
74
|
+
enable-cache: auto
|
|
75
|
+
- run: uv build
|
|
76
|
+
- uses: actions/upload-artifact@v7.0.2
|
|
77
|
+
with:
|
|
78
|
+
name: dist
|
|
79
|
+
path: dist/
|
|
80
|
+
if-no-files-found: error
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build distributions
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7.0.1
|
|
16
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
17
|
+
with:
|
|
18
|
+
enable-cache: auto
|
|
19
|
+
- name: Check tag matches package version
|
|
20
|
+
run: |
|
|
21
|
+
python3 - <<'PY'
|
|
22
|
+
import os
|
|
23
|
+
import tomllib
|
|
24
|
+
|
|
25
|
+
with open("pyproject.toml", "rb") as fh:
|
|
26
|
+
version = tomllib.load(fh)["project"]["version"]
|
|
27
|
+
tag = os.environ["GITHUB_REF_NAME"].removeprefix("v")
|
|
28
|
+
if tag != version:
|
|
29
|
+
raise SystemExit(f"tag {tag!r} does not match version {version!r}")
|
|
30
|
+
PY
|
|
31
|
+
- run: uv build
|
|
32
|
+
- uses: actions/upload-artifact@v7.0.2
|
|
33
|
+
with:
|
|
34
|
+
name: dist
|
|
35
|
+
path: dist/
|
|
36
|
+
if-no-files-found: error
|
|
37
|
+
|
|
38
|
+
publish:
|
|
39
|
+
name: Publish to PyPI
|
|
40
|
+
needs: build
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
environment:
|
|
43
|
+
name: pypi
|
|
44
|
+
url: https://pypi.org/p/sphinx-cjk-aware
|
|
45
|
+
permissions:
|
|
46
|
+
contents: read
|
|
47
|
+
id-token: write
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/download-artifact@v8.0.2
|
|
50
|
+
with:
|
|
51
|
+
name: dist
|
|
52
|
+
path: dist/
|
|
53
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
54
|
+
|
|
55
|
+
release:
|
|
56
|
+
name: Create GitHub release
|
|
57
|
+
needs: [build, publish]
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
permissions:
|
|
60
|
+
contents: write
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/checkout@v7.0.1
|
|
63
|
+
with:
|
|
64
|
+
fetch-depth: 0
|
|
65
|
+
- name: Generate release notes
|
|
66
|
+
uses: orhun/git-cliff-action@v4.9.1
|
|
67
|
+
with:
|
|
68
|
+
config: cliff.toml
|
|
69
|
+
args: --latest
|
|
70
|
+
env:
|
|
71
|
+
OUTPUT: RELEASE_NOTES.md
|
|
72
|
+
- name: Create release
|
|
73
|
+
env:
|
|
74
|
+
GH_TOKEN: ${{ github.token }}
|
|
75
|
+
run: |
|
|
76
|
+
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
|
|
77
|
+
echo "Release $GITHUB_REF_NAME already exists, leaving it as is."
|
|
78
|
+
exit 0
|
|
79
|
+
fi
|
|
80
|
+
# git-cliff starts the body with a blank line; drop leading blanks.
|
|
81
|
+
sed -i '/./,$!d' RELEASE_NOTES.md
|
|
82
|
+
gh release create "$GITHUB_REF_NAME" \
|
|
83
|
+
--title "$GITHUB_REF_NAME" \
|
|
84
|
+
--notes-file RELEASE_NOTES.md \
|
|
85
|
+
--verify-tag
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Byte-compiled / cache
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
|
|
5
|
+
# Virtual environments
|
|
6
|
+
.venv/
|
|
7
|
+
.uv/
|
|
8
|
+
|
|
9
|
+
# Build artefacts
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
*.egg-info/
|
|
13
|
+
|
|
14
|
+
# Test and lint caches
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.ruff_cache/
|
|
17
|
+
.coverage
|
|
18
|
+
coverage.xml
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# Documentation build
|
|
22
|
+
docs/_build/
|
|
23
|
+
|
|
24
|
+
# Editors and OS
|
|
25
|
+
.DS_Store
|
|
26
|
+
.idea/
|
|
27
|
+
.vscode/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based
|
|
4
|
+
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-10-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Sphinx extension `sphinx_cjk_aware` that removes artificial spaces around
|
|
12
|
+
inline markup in Chinese and Japanese text.
|
|
13
|
+
- Script-based character classification: Han, kana, bopomofo and their
|
|
14
|
+
punctuation are treated as unspaced; Hangul, Latin, emoji and other scripts
|
|
15
|
+
are not, so Korean word spacing is preserved.
|
|
16
|
+
- Handling for newline-wrapped source, fullwidth space (U+3000), runs of
|
|
17
|
+
spaces and NUL-escaped spaces (`\ `).
|
|
18
|
+
- Passes at `doctree-read` (before navigation snapshotting) and
|
|
19
|
+
`doctree-resolved` (final stage); the `gettext` builder and literal/math
|
|
20
|
+
blocks are skipped.
|
|
21
|
+
- Test suite covering character classes, the doctree pass, rendered HTML,
|
|
22
|
+
`.pot` extraction and a compiled-catalog translation round-trip.
|
|
23
|
+
|
|
24
|
+
[0.1.0]: https://github.com/yufeiminds/sphinx-cjk-aware/releases/tag/v0.1.0
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Development environment
|
|
4
|
+
|
|
5
|
+
This project uses [uv](https://docs.astral.sh/uv/) for environments and
|
|
6
|
+
dependency management, and [ruff](https://docs.astral.sh/ruff/) for linting
|
|
7
|
+
and formatting.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv sync --all-extras
|
|
11
|
+
pre-commit install # optional: run ruff on every commit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Everyday commands
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
uv run pytest --cov # tests and coverage
|
|
18
|
+
uv run ruff check . # lint
|
|
19
|
+
uv run ruff format . # format
|
|
20
|
+
uv run sphinx-build -W -b html docs docs/_build/html # documentation
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Tests
|
|
24
|
+
|
|
25
|
+
The suite builds small Sphinx projects in temporary directories: character
|
|
26
|
+
classification, the doctree pass, rendered HTML, `.pot` extraction (compared
|
|
27
|
+
byte-for-byte with an extension-less build), and a translation round-trip
|
|
28
|
+
with a compiled `.mo` catalog. Korean spacing and literal blocks are covered
|
|
29
|
+
explicitly because they must not change.
|
|
30
|
+
|
|
31
|
+
## Releasing
|
|
32
|
+
|
|
33
|
+
1. Bump `version` in `pyproject.toml` and
|
|
34
|
+
`src/sphinx_cjk_aware/_version.py`, and add an entry to `CHANGELOG.md`.
|
|
35
|
+
2. Commit and push `main`; wait for CI to pass.
|
|
36
|
+
3. Tag and push:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
git tag -s v0.1.0 -m "v0.1.0"
|
|
40
|
+
git push origin v0.1.0
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The `Release` workflow then:
|
|
44
|
+
|
|
45
|
+
- checks that the tag matches the package version;
|
|
46
|
+
- builds the sdist and wheel and publishes them to PyPI;
|
|
47
|
+
- creates the GitHub Release for the tag, with notes generated by
|
|
48
|
+
[git-cliff](https://git-cliff.org/) from the commits since the previous
|
|
49
|
+
release. Entries are grouped by Conventional Commit type (`feat`, `fix`,
|
|
50
|
+
`docs`, …); anything else is listed under “Other”. An existing release
|
|
51
|
+
for the tag is left untouched, so re-running the workflow is safe — and
|
|
52
|
+
curated notes can be edited on GitHub without being overwritten.
|
|
53
|
+
|
|
54
|
+
Preview the notes locally before tagging:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git cliff --unreleased # commits not tagged yet
|
|
58
|
+
git cliff --tag v0.1.1 # simulate the section for a version
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Commit messages are grouped in `cliff.toml`. Following
|
|
62
|
+
[Conventional Commits](https://www.conventionalcommits.org/) (`feat: …`,
|
|
63
|
+
`fix: …`, `docs: …`) keeps the notes tidy; non-conventional messages are
|
|
64
|
+
still included, under “Other”.
|
|
65
|
+
|
|
66
|
+
Publishing uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/)
|
|
67
|
+
— no API token is stored anywhere. Configure it once on PyPI with:
|
|
68
|
+
|
|
69
|
+
| Field | Value |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Owner | `yufeiminds` |
|
|
72
|
+
| Repository | `sphinx-cjk-aware` |
|
|
73
|
+
| Workflow | `release.yml` |
|
|
74
|
+
| Environment | `pypi` |
|
|
75
|
+
|
|
76
|
+
The workflow's `publish` job requests `id-token: write` and uses
|
|
77
|
+
`pypa/gh-action-pypi-publish`, which exchanges that OIDC token for a
|
|
78
|
+
short-lived PyPI credential.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yufei Li
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sphinx-cjk-aware
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CJK-aware inline spacing for Sphinx: remove artificial spaces around inline markup in Chinese and Japanese text
|
|
5
|
+
Project-URL: Homepage, https://github.com/yufeiminds/sphinx-cjk-aware
|
|
6
|
+
Project-URL: Documentation, https://github.com/yufeiminds/sphinx-cjk-aware#readme
|
|
7
|
+
Project-URL: Changelog, https://github.com/yufeiminds/sphinx-cjk-aware/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/yufeiminds/sphinx-cjk-aware/issues
|
|
9
|
+
Author-email: Yufei Li <yufeiminds@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: chinese,cjk,docutils,i18n,inline,japanese,spacing,sphinx
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Framework :: Sphinx :: Extension
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Documentation
|
|
24
|
+
Classifier: Topic :: Documentation :: Sphinx
|
|
25
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: docutils<0.23,>=0.20
|
|
28
|
+
Requires-Dist: sphinx>=8.0
|
|
29
|
+
Provides-Extra: docs
|
|
30
|
+
Requires-Dist: furo>=2024.8.6; extra == 'docs'
|
|
31
|
+
Requires-Dist: myst-parser>=4.0; extra == 'docs'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# sphinx-cjk-aware
|
|
35
|
+
|
|
36
|
+
[](https://github.com/yufeiminds/sphinx-cjk-aware/actions/workflows/ci.yml)
|
|
37
|
+
[](https://pypi.org/project/sphinx-cjk-aware/)
|
|
38
|
+
[](https://pypi.org/project/sphinx-cjk-aware/)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
**CJK-aware inline spacing for Sphinx.** Removes the spaces that inline
|
|
42
|
+
markup needs in order to parse in Chinese and Japanese text, but that those
|
|
43
|
+
typographies do not want to show. Korean is left alone: its spaces are word
|
|
44
|
+
boundaries.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
uv add --dev sphinx-cjk-aware
|
|
50
|
+
# or
|
|
51
|
+
pip install sphinx-cjk-aware
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
# conf.py
|
|
58
|
+
extensions = [
|
|
59
|
+
# ...
|
|
60
|
+
"sphinx_cjk_aware",
|
|
61
|
+
]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
No configuration is required.
|
|
65
|
+
|
|
66
|
+
## The problem
|
|
67
|
+
|
|
68
|
+
reStructuredText — like CommonMark, cf.
|
|
69
|
+
[markdown-cjk-friendly](https://github.com/tats-u/markdown-cjk-friendly) —
|
|
70
|
+
recognises inline markup only when its delimiters sit next to whitespace or
|
|
71
|
+
punctuation. Chinese and Japanese characters count as neither, so emphasis
|
|
72
|
+
has to be padded to parse:
|
|
73
|
+
|
|
74
|
+
```rst
|
|
75
|
+
即它 *为什么* 有效 → 即它 <em>为什么</em> 有效
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The padding then shows on the page. Translations hit the same thing in a
|
|
79
|
+
subtler way: Sphinx re-parses every `msgstr`, so `*...*` in a catalog becomes
|
|
80
|
+
real emphasis — together with the spaces that made it recognisable.
|
|
81
|
+
|
|
82
|
+
With this extension the rendered result is:
|
|
83
|
+
|
|
84
|
+
```html
|
|
85
|
+
即它<em>为什么</em>有效
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## What gets fixed
|
|
89
|
+
|
|
90
|
+
A space is removed at the seam between text and an inline element
|
|
91
|
+
(emphasis, strong, literal, link, role, …) when **both** sides belong to a
|
|
92
|
+
script written without word spaces:
|
|
93
|
+
|
|
94
|
+
| Source (or `msgstr`) | Renders as |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `即它 *为什么* 有效。` | `即它<em>为什么</em>有效。` |
|
|
97
|
+
| `都兼具 **实践表达** 与 **概念把握**。` | `都兼具<strong>实践表达</strong>与<strong>概念把握</strong>。` |
|
|
98
|
+
| `句子 **粗体** 中文。` | `句子<strong>粗体</strong>中文。` |
|
|
99
|
+
| `英文。 **粗体** 结尾。` | `英文。<strong>粗体</strong>结尾。` |
|
|
100
|
+
| `**这些星号。** 都是因为这个句子。` | `<strong>这些星号。</strong>都是因为这个句子。` |
|
|
101
|
+
| `句子 **粗体** (注)结尾。` | `句子<strong>粗体</strong>(注)结尾。` |
|
|
102
|
+
| `**甲** **乙** 并列。` | `<strong>甲</strong><strong>乙</strong>并列。` |
|
|
103
|
+
| `它 *行之有效* —— 无论用户。` | `它<em>行之有效</em>—— 无论用户。` |
|
|
104
|
+
| `这是 ``内嵌代码`` 示例。` | `这是<code>内嵌代码</code>示例。` |
|
|
105
|
+
| `小节 *强调* 标题` | heading and navigation both glued |
|
|
106
|
+
|
|
107
|
+
It also handles source lines wrapped before markup, fullwidth space (U+3000),
|
|
108
|
+
runs of spaces, and NUL-escaped spaces (`\ `, common in translated msgstrs).
|
|
109
|
+
|
|
110
|
+
## What is left alone
|
|
111
|
+
|
|
112
|
+
- **Korean** — `요리를 하는 *동안* 읽는 책` keeps both spaces: they are word
|
|
113
|
+
boundaries, not markup padding.
|
|
114
|
+
- **English and other Latin-script prose**, including the desirable
|
|
115
|
+
CJK↔Latin space: `中文 *English* 中文`.
|
|
116
|
+
- **Wide emoji**, European accented letters, and symbols.
|
|
117
|
+
- **Literal content** — `code-block`, `parsed-literal`, doctest blocks and
|
|
118
|
+
math, where whitespace is significant.
|
|
119
|
+
- **Plain-text spaces** that are not adjacent to inline markup.
|
|
120
|
+
|
|
121
|
+
## What counts as unspaced text
|
|
122
|
+
|
|
123
|
+
Han characters (Chinese, and Japanese kanji — they share code points),
|
|
124
|
+
hiragana, katakana, bopomofo, and CJK punctuation: `。、「」()!:`,
|
|
125
|
+
fullwidth forms, and `—— …… “” ·`. Hangul, Latin, emoji and other scripts do
|
|
126
|
+
not qualify.
|
|
127
|
+
|
|
128
|
+
## How it works
|
|
129
|
+
|
|
130
|
+
Following [sphinx-cjkspace](https://github.com/seisman/sphinx-cjkspace), the
|
|
131
|
+
extension fixes the resolved doctree at the last stage instead of changing
|
|
132
|
+
the parser:
|
|
133
|
+
|
|
134
|
+
- `doctree-read` (priority 490, before the toctree collector snapshots
|
|
135
|
+
section titles) — so headings and the navigation agree;
|
|
136
|
+
- `doctree-resolved` — the last stage before writing.
|
|
137
|
+
|
|
138
|
+
Parsing, sources and message catalogs are never touched: the `gettext`
|
|
139
|
+
builder is skipped, so `.pot` msgids stay verbatim for translators.
|
|
140
|
+
|
|
141
|
+
## Compatibility
|
|
142
|
+
|
|
143
|
+
- Sphinx ≥ 8, docutils 0.20–0.22
|
|
144
|
+
- Python ≥ 3.11
|
|
145
|
+
- No configuration, no extra runtime dependencies
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
uv sync --all-extras # create the environment
|
|
151
|
+
uv run pytest # tests
|
|
152
|
+
uv run ruff check . # lint
|
|
153
|
+
uv run ruff format . # format
|
|
154
|
+
uv run sphinx-build -W -b html docs docs/_build/html # docs
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Releases are published to PyPI from GitHub Actions using
|
|
158
|
+
[Trusted Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC, no
|
|
159
|
+
tokens). The GitHub Release notes are generated by
|
|
160
|
+
[git-cliff](https://git-cliff.org/) from the commits since the previous
|
|
161
|
+
release, grouped by Conventional Commit type. See
|
|
162
|
+
[`.github/workflows/release.yml`](.github/workflows/release.yml) and
|
|
163
|
+
[`cliff.toml`](cliff.toml).
|
|
164
|
+
|
|
165
|
+
## License
|
|
166
|
+
|
|
167
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# sphinx-cjk-aware
|
|
2
|
+
|
|
3
|
+
[](https://github.com/yufeiminds/sphinx-cjk-aware/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/sphinx-cjk-aware/)
|
|
5
|
+
[](https://pypi.org/project/sphinx-cjk-aware/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
**CJK-aware inline spacing for Sphinx.** Removes the spaces that inline
|
|
9
|
+
markup needs in order to parse in Chinese and Japanese text, but that those
|
|
10
|
+
typographies do not want to show. Korean is left alone: its spaces are word
|
|
11
|
+
boundaries.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv add --dev sphinx-cjk-aware
|
|
17
|
+
# or
|
|
18
|
+
pip install sphinx-cjk-aware
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
# conf.py
|
|
25
|
+
extensions = [
|
|
26
|
+
# ...
|
|
27
|
+
"sphinx_cjk_aware",
|
|
28
|
+
]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
No configuration is required.
|
|
32
|
+
|
|
33
|
+
## The problem
|
|
34
|
+
|
|
35
|
+
reStructuredText — like CommonMark, cf.
|
|
36
|
+
[markdown-cjk-friendly](https://github.com/tats-u/markdown-cjk-friendly) —
|
|
37
|
+
recognises inline markup only when its delimiters sit next to whitespace or
|
|
38
|
+
punctuation. Chinese and Japanese characters count as neither, so emphasis
|
|
39
|
+
has to be padded to parse:
|
|
40
|
+
|
|
41
|
+
```rst
|
|
42
|
+
即它 *为什么* 有效 → 即它 <em>为什么</em> 有效
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The padding then shows on the page. Translations hit the same thing in a
|
|
46
|
+
subtler way: Sphinx re-parses every `msgstr`, so `*...*` in a catalog becomes
|
|
47
|
+
real emphasis — together with the spaces that made it recognisable.
|
|
48
|
+
|
|
49
|
+
With this extension the rendered result is:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
即它<em>为什么</em>有效
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## What gets fixed
|
|
56
|
+
|
|
57
|
+
A space is removed at the seam between text and an inline element
|
|
58
|
+
(emphasis, strong, literal, link, role, …) when **both** sides belong to a
|
|
59
|
+
script written without word spaces:
|
|
60
|
+
|
|
61
|
+
| Source (or `msgstr`) | Renders as |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `即它 *为什么* 有效。` | `即它<em>为什么</em>有效。` |
|
|
64
|
+
| `都兼具 **实践表达** 与 **概念把握**。` | `都兼具<strong>实践表达</strong>与<strong>概念把握</strong>。` |
|
|
65
|
+
| `句子 **粗体** 中文。` | `句子<strong>粗体</strong>中文。` |
|
|
66
|
+
| `英文。 **粗体** 结尾。` | `英文。<strong>粗体</strong>结尾。` |
|
|
67
|
+
| `**这些星号。** 都是因为这个句子。` | `<strong>这些星号。</strong>都是因为这个句子。` |
|
|
68
|
+
| `句子 **粗体** (注)结尾。` | `句子<strong>粗体</strong>(注)结尾。` |
|
|
69
|
+
| `**甲** **乙** 并列。` | `<strong>甲</strong><strong>乙</strong>并列。` |
|
|
70
|
+
| `它 *行之有效* —— 无论用户。` | `它<em>行之有效</em>—— 无论用户。` |
|
|
71
|
+
| `这是 ``内嵌代码`` 示例。` | `这是<code>内嵌代码</code>示例。` |
|
|
72
|
+
| `小节 *强调* 标题` | heading and navigation both glued |
|
|
73
|
+
|
|
74
|
+
It also handles source lines wrapped before markup, fullwidth space (U+3000),
|
|
75
|
+
runs of spaces, and NUL-escaped spaces (`\ `, common in translated msgstrs).
|
|
76
|
+
|
|
77
|
+
## What is left alone
|
|
78
|
+
|
|
79
|
+
- **Korean** — `요리를 하는 *동안* 읽는 책` keeps both spaces: they are word
|
|
80
|
+
boundaries, not markup padding.
|
|
81
|
+
- **English and other Latin-script prose**, including the desirable
|
|
82
|
+
CJK↔Latin space: `中文 *English* 中文`.
|
|
83
|
+
- **Wide emoji**, European accented letters, and symbols.
|
|
84
|
+
- **Literal content** — `code-block`, `parsed-literal`, doctest blocks and
|
|
85
|
+
math, where whitespace is significant.
|
|
86
|
+
- **Plain-text spaces** that are not adjacent to inline markup.
|
|
87
|
+
|
|
88
|
+
## What counts as unspaced text
|
|
89
|
+
|
|
90
|
+
Han characters (Chinese, and Japanese kanji — they share code points),
|
|
91
|
+
hiragana, katakana, bopomofo, and CJK punctuation: `。、「」()!:`,
|
|
92
|
+
fullwidth forms, and `—— …… “” ·`. Hangul, Latin, emoji and other scripts do
|
|
93
|
+
not qualify.
|
|
94
|
+
|
|
95
|
+
## How it works
|
|
96
|
+
|
|
97
|
+
Following [sphinx-cjkspace](https://github.com/seisman/sphinx-cjkspace), the
|
|
98
|
+
extension fixes the resolved doctree at the last stage instead of changing
|
|
99
|
+
the parser:
|
|
100
|
+
|
|
101
|
+
- `doctree-read` (priority 490, before the toctree collector snapshots
|
|
102
|
+
section titles) — so headings and the navigation agree;
|
|
103
|
+
- `doctree-resolved` — the last stage before writing.
|
|
104
|
+
|
|
105
|
+
Parsing, sources and message catalogs are never touched: the `gettext`
|
|
106
|
+
builder is skipped, so `.pot` msgids stay verbatim for translators.
|
|
107
|
+
|
|
108
|
+
## Compatibility
|
|
109
|
+
|
|
110
|
+
- Sphinx ≥ 8, docutils 0.20–0.22
|
|
111
|
+
- Python ≥ 3.11
|
|
112
|
+
- No configuration, no extra runtime dependencies
|
|
113
|
+
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
uv sync --all-extras # create the environment
|
|
118
|
+
uv run pytest # tests
|
|
119
|
+
uv run ruff check . # lint
|
|
120
|
+
uv run ruff format . # format
|
|
121
|
+
uv run sphinx-build -W -b html docs docs/_build/html # docs
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Releases are published to PyPI from GitHub Actions using
|
|
125
|
+
[Trusted Publishing](https://docs.pypi.org/trusted-publishers/) (OIDC, no
|
|
126
|
+
tokens). The GitHub Release notes are generated by
|
|
127
|
+
[git-cliff](https://git-cliff.org/) from the commits since the previous
|
|
128
|
+
release, grouped by Conventional Commit type. See
|
|
129
|
+
[`.github/workflows/release.yml`](.github/workflows/release.yml) and
|
|
130
|
+
[`cliff.toml`](cliff.toml).
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT — see [LICENSE](LICENSE).
|