fix: per-block direction detection in static mode with dir="auto"#510
Open
shloimy-wiesel wants to merge 1 commit into
Open
fix: per-block direction detection in static mode with dir="auto"#510shloimy-wiesel wants to merge 1 commit into
shloimy-wiesel wants to merge 1 commit into
Conversation
Contributor
|
@shloimy-wiesel is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
f44335c to
0c37738
Compare
When mode="static" and dir="auto", Streamdown now detects text direction per-block (same as streaming mode) instead of once for the entire content. - Static mode with dir="auto" uses parseMarkdownIntoBlocks and per-block detectTextDirection, matching streaming mode behavior - detectTextDirection strips fenced code blocks before detection - Code blocks always render LTR via dir="ltr" on CodeBlockBody - Block dir wrapper uses unicodeBidi:"isolate" instead of display:contents to preserve space-y-4 spacing between blocks
0c37738 to
a46c37f
Compare
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
Fix
dir="auto"in static mode to detect text direction per-block instead of once for the entire content. Previously, mixed RTL/LTR markdown (e.g., Hebrew headings + English paragraphs + code blocks) would all receive a single direction, causing incorrect text alignment. This PR aligns static mode behavior with streaming mode, which already handled per-block direction correctly.Type of Change
Related Issues
Fixes #509
Changes Made
packages/streamdown/index.tsx): Whenmode="static"anddir="auto", the component now usesparseMarkdownIntoBlocks+ per-blockdetectTextDirection, matching the streaming mode behaviorpackages/streamdown/lib/detect-direction.ts):detectTextDirectionnow strips fenced code blocks (```...```) before analyzing text direction, preventing code content from skewing the resultpackages/streamdown/lib/code-block/body.tsx): Addeddir="ltr"to theCodeBlockBodyroot div - code is universally LTR regardless of surrounding content directionpackages/streamdown/index.tsx): Replaceddisplay: contentswithunicodeBidi: "isolate"on the Block dir wrapper to preservespace-y-4spacing between blocksdirconfig to playground (apps/website/.../playground-editor.tsx): Added a configurableDirdropdown (Auto / LTR / RTL) to the playground settings panel, defaulting to Auto, replacing the previous hardcodeddir="auto"Testing
Test Coverage
detect-direction.test.ts- 3 new tests:rtl-support.test.tsx- 4 updated/new tests:unicodeBidi: isolate(notdisplay: contents)dir="auto"renders different directions per blockdir="auto"renders English blocks as LTR within Hebrew contentdir="ltr"Screenshots/Demos
Before Fix (Bug)
After Fix
Checklist
pnpm changeset)Changeset
Additional Notes
parseMarkdownIntoBlocks+detectTextDirectionpipeline that streaming mode already uses - no new direction detection logic was introduceddisplay: contentswas replaced withunicodeBidi: "isolate"becausedisplay: contentsmakes the element invisible to CSS layout, which brokespace-y-4margins between blocksdir="ltr"at the component level (not via detection) becausemarked's Lexer treats a list item with a nested code block as a single token, making per-block detection insufficient for embedded code