Repository navigation
Add the narrowNbsp option - #7
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_replaceover the default output gives the same text and is not a fixed point — feed it back throughtransform()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 asRuleContext::$narrowTarget.CODE_INVALID_OPTIONis the eighth error code, deliberately general for every option added from 1.3.0 on. Validation order ismode→narrowNbsp→rules→locale→dialect, and the check runs whether or notnbspis 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