fix: detect static text direction per block - #569
Open
CodeinScrubs wants to merge 1 commit into
Open
Conversation
Contributor
|
Someone is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
CodeinScrubs
marked this pull request as ready for review
July 30, 2026 09:16
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.
Description
Static mode currently resolves dir=auto once for the complete Markdown string. A mixed Hebrew/Arabic/Persian and English response therefore gives every block the same base direction, while code can inherit RTL.
This change keeps static content as one Markdown document but adds a rehype pass that assigns direction to each semantic block. Keeping one parse preserves cross-block references and footnotes. The public detector now uses strong-character content majority, with first-strong as the tie-breaker, so RTL-majority technical prose such as an answer beginning with an English identifier is not forced LTR. Rendered code-block containers are explicitly LTR.
Type of Change
Related Issues
Fixes #509
Changes Made
Testing
Test Coverage
pnpm --filter streamdown test: 73 files, 985 tests passedpnpm --filter streamdown build: ESM and declaration build passedgit diff --check: passedScreenshots/Demos
Not included. The regression is asserted against the rendered DOM: no document-level auto direction in static mode, per-block
dirvalues, and an LTR code-block container.Checklist
pnpm changeset)Changeset
Additional Notes
I maintain the MIT-licensed BidiLens project and used its per-semantic-block/content-majority model as design input. This PR intentionally implements the small policy natively instead of adding BidiLens as a dependency: Streamdown supports Node 18, while BidiLens 0.3 declares Node 22.12+, so a direct dependency would unnecessarily raise the host's runtime floor.
The Vercel preview check requires authorization from a Vercel team member because this PR comes from an external fork. Socket security and Vercel Agent Review passed; the preview authorization state is not a build or test failure in this patch.