Repository navigation
Add the narrow_nbsp 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. `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 an example shows why that distinction is the whole feature: `gsub` 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.resolve_narrow_target) and reaches the rules as RuleContext#narrow_target, 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 -> 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 examples. The conformance spec now passes the case's own options on 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 spec already spread **opts there, so the change is the new key plus the reason. Verified beyond the suite: all 1245 runnable canonical fixture cases at spec 1.3.0, across all 18 locales and all three modes, pass and are idempotent against this build. 1155 examples pass on Ruby 3.3.8. 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), after polytypo/polytypo-js#16, polytypo/polytypo-python#7 and polytypo/polytypo-go#7.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. An example shows why that is the whole feature:
gsubover the default output gives the same text and is not a fixed point — feed it back through.transformand N2 converts it straight back. The option is resolved once at the call boundary into a code point (Engine.resolve_narrow_target) and reaches the rules asRuleContext#narrow_target.CODE_INVALID_OPTIONis the eighth error code, deliberately general for every option added from 1.3.0 on. Validation order ismode→narrow_nbsp→rules→locale→dialect, and the check runs whether or notnbspis enabled. All four precedence pairs are examples.The conformance spec changed too: spec 1.3.0 makes it contract that the idempotency re-run carries the case's own options. It already spread
**optsthere, so the change is the new key plus the reason.Checks: 1155 examples, 0 failures on Ruby 3.3.8. Beyond the suite: all 1245 runnable canonical 1.3.0 fixture cases across 18 locales and all three modes pass and are idempotent against this build. RuboCop was not run locally (it does not build on this machine); CI covers it.
🤖 Generated with Claude Code