Skip to content

Add the narrow_nbsp option - #7

Merged
rogulia merged 1 commit into
mainfrom
feat/narrow-nbsp-option
Sep 20, 2026
Merged

rogulia merged 1 commit into
mainfrom
feat/narrow-nbsp-option

Conversation

@rogulia

@rogulia rogulia commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Implements spec 1.3.0's nbsp.md §3.1a (polytypo/polytypo@3a2355d, canonical issue polytypo/polytypo#31), after polytypo/polytypo-js#16.

narrow_nbsp="nbsp" makes the engine emit U+00A0 everywhere it would emit U+202F — missing from Manrope, EB Garamond and other common faces, so a browser falls back for that one character and the advance width changes mid-line.

It rewrites the rule's target, it does not post-process. A test shows why that is the whole feature: transform(...).replace(U+202F, U+00A0) gives the same text and is not a fixed point — feed it back through transform and N2 converts it straight back. The option is resolved once at the call boundary into a code point (_engine/narrow_target.py) and reaches the rules as RuleContext["narrow_target"].

POLYTYPO_INVALID_OPTION is the eighth error code, deliberately general for every option added from 1.3.0 on. Validation order is mode → narrow_nbsp → rules → locale → dialect, and the check runs whether or not nbsp is enabled. All four precedence pairs are tests.

The conformance runner changed too. Spec 1.3.0 makes it contract that the idempotency re-run carries the case's own options: a case with narrowNbsp is a fixed point under that option and not under the defaults. This runner already spread **kwargs on the second call, so it was correct by construction — the change is the new key plus the reason written down.

Checks: 1206 tests, packaging 4, ruff, ruff format, mypy --strict clean. Beyond the suite: all 1226 runnable text/html canonical 1.3.0 fixture cases pass and are idempotent against this build.

🤖 Generated with Claude Code

Implements spec 1.3.0's nbsp.md 3.1a (polytypo/polytypo@3a2355d, canonical issue
#31), porting polytypo-js@964db2d. `narrow_nbsp="nbsp"` makes the engine emit
U+00A0 everywhere it would emit U+202F — the narrow no-break space many common
faces do not carry, where a browser falls back mid-line and a PDF renderer with
no fallback drops the glyph.

It rewrites the rule's target rather than post-processing the output, and a test
shows why that distinction is the whole feature: `transform(...).replace(...)`
produces the same text and is not a fixed point — feed it back through transform
and N2 converts it straight back. The option is resolved once at the call
boundary into a code point (_engine/narrow_target.py) and reaches the rules as
RuleContext["narrow_target"], so no rule sees the option's string.

POLYTYPO_INVALID_OPTION is the eighth error code, general to every option added
from 1.3.0 on. Validation order is mode -> narrow_nbsp -> rules -> locale ->
dialect, and the check runs whether or not `nbsp` is enabled — it belongs to the
call, so `rules={"nbsp": False}` does not suppress it. All four precedence pairs
are tests.

The conformance runner now passes the case's own options on the idempotency
re-run, which spec 1.3.0 made contract rather than convenience: a case carrying
`narrowNbsp` is a fixed point under that option and not under the defaults, so a
runner that dropped it would go red on a correct implementation. This runner
already spread **kwargs there, so the change is one line plus the reason.

Verified beyond the suite: all 1226 runnable text/html canonical fixture cases
at spec 1.3.0 pass and are idempotent against this build, the seven new
narrowNbsp cases included. 1206 tests pass, packaging 4, ruff, ruff format and
mypy --strict clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rogulia
rogulia merged commit 3ec4ed9 into main Sep 20, 2026
4 checks passed
@rogulia
rogulia deleted the feat/narrow-nbsp-option branch September 20, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant