Skip to content

Add the narrowNbsp option - #7

Merged
rogulia merged 2 commits into
mainfrom
feat/narrow-nbsp-option
Sep 20, 2026
Merged

rogulia merged 2 commits 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). Fifth and last runtime, after polytypo/polytypo-js#16, polytypo/polytypo-python#7, polytypo/polytypo-go#7 and polytypo/polytypo-ruby#7.

narrowNbsp: '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: str_replace over the default output 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\NarrowTarget) and reaches the rules as RuleContext::$narrowTarget.

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

The conformance runner changed too: spec 1.3.0 makes it contract that the idempotency re-run carries the case's own options. Unlike the other four runtimes' runners, this one named its arguments per call rather than reusing one value, so all three call sites gained the argument explicitly.

Checks: 1148 tests, 2974 assertions, 21 skipped (the markdown cases this runtime declines); PHPStan level 8 and phpcs clean — PHP 8.3.32. 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

rogulia and others added 2 commits September 19, 2026 19:41
Implements spec 1.3.0's nbsp.md 3.1a (polytypo/polytypo@3a2355d, canonical issue
#31), porting polytypo-js@964db2d. `narrowNbsp: '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: str_replace over the default
output 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\NarrowTarget) and reaches the rules as
RuleContext::$narrowTarget, so no rule sees the option's string.

CODE_INVALID_OPTION is the eighth error code, general to every option added from
1.3.0 on. Validation order is mode -> narrowNbsp -> 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
in one test.

The conformance runner now carries the case's own options into the idempotency
re-run, which spec 1.3.0 made contract: a case with narrowNbsp is a fixed point
under that option and not under the defaults. This runner named its arguments on
each call rather than reusing one value, so all three call sites gained the
argument explicitly.

Verified beyond the suite: all 1226 runnable text/html canonical fixture cases at
spec 1.3.0 pass and are idempotent against this build. 1148 tests, 2974
assertions; PHPStan level 8 and phpcs clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rogulia
rogulia merged commit 2404ffe into main Sep 20, 2026
3 checks passed
@rogulia
rogulia deleted the feat/narrow-nbsp-option branch September 20, 2026 09:04
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