Skip to content

Commit 65687e6

Browse files
omers-oaicodex
andcommitted
Fix RTL compatibility previews
Enable the RTL compatibility samples to exercise compatibility mode, keep HTML block alignment explicit in compatibility mode, and avoid forcing paragraph alignment unless a containing block needs a shared side. Co-authored-by: Codex <noreply@openai.com>
1 parent ea4663f commit 65687e6

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

android-sample/src/main/java/com/zachklipp/richtext/sample/RtlCompatibilityBehaviorSample.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ private fun TableBehaviorPreview() {
102102
BehaviorSection(
103103
title = "Markdown table renders with RTL compatibility enabled",
104104
markdown = tableMarkdown,
105-
richTextRenderOptions = RichTextRenderOptions(enableRtlCompatibility = true),
106105
)
107106
}
108107
}
@@ -139,7 +138,7 @@ private fun BehaviorPreviewColumn(
139138
private fun BehaviorSection(
140139
title: String,
141140
markdown: String,
142-
richTextRenderOptions: RichTextRenderOptions = RichTextRenderOptions(),
141+
richTextRenderOptions: RichTextRenderOptions = rtlCompatibilityOptions,
143142
) {
144143
Column(
145144
modifier = Modifier.fillMaxWidth(),
@@ -169,6 +168,8 @@ private fun BehaviorMarkdown(
169168
}
170169
}
171170

171+
private val rtlCompatibilityOptions = RichTextRenderOptions(enableRtlCompatibility = true)
172+
172173
private val englishStartingQuoteMarkdown = """
173174
> English opens this quote.
174175
> אחר כך מופיעה עברית.

android-sample/src/main/java/com/zachklipp/richtext/sample/RtlCompatibilitySample.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ private fun MarkdownCaseContent(
117117
RichText(modifier = Modifier.fillMaxWidth()) {
118118
Markdown(
119119
content = markdown,
120-
richtextRenderOptions = RichTextRenderOptions(),
120+
richtextRenderOptions = rtlCompatibilityOptions,
121121
)
122122
}
123123
}
124124
}
125125

126+
private val rtlCompatibilityOptions = RichTextRenderOptions(enableRtlCompatibility = true)
127+
126128
private data class PreviewVariant(
127129
val localeLabel: String,
128130
val layoutDirection: LayoutDirection,

richtext-markdown/src/commonMain/kotlin/com/halilibo/richtext/markdown/BasicMarkdown.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,15 @@ private val DefaultAstNodeComposer = object : AstBlockNodeComposer {
412412
}
413413

414414
is AstHtmlBlock -> {
415-
Text(text = richTextString {
416-
appendInlineContent(content = InlineContent {
417-
HtmlBlock(astNodeType.literal)
415+
if (richTextRenderOptions.enableRtlCompatibility) {
416+
HtmlBlock(astNodeType.literal)
417+
} else {
418+
Text(text = richTextString {
419+
appendInlineContent(content = InlineContent {
420+
HtmlBlock(astNodeType.literal)
421+
})
418422
})
419-
})
423+
}
420424
}
421425

422426
is AstLinkReferenceDefinition -> {

richtext-markdown/src/commonMain/kotlin/com/halilibo/richtext/markdown/MarkdownRichText.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ internal fun RichTextScope.MarkdownRichText(
9797
renderOptions = richTextRenderOptions,
9898
sharedAnimationState = markdownAnimationState,
9999
decorations = richTextDecorations,
100-
textAlign = LocalCompatibilityTextAlignOverride.current
101-
?: compatibilityDirection.toCompatibilityTextAlign(),
100+
textAlign = LocalCompatibilityTextAlignOverride.current,
102101
textDirection = textDirection,
103102
)
104103
}

0 commit comments

Comments
 (0)