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, 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: gsub 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.resolve_narrow_target) and reaches the rules as RuleContext#narrow_target.

CODE_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 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 **opts there, 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

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>
@rogulia
rogulia merged commit efc3389 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