Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/src/main/java/com/zhousl/aether/ui/MarkdownRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDirection
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
Expand Down Expand Up @@ -1180,7 +1181,7 @@ private fun MarkdownText(
if (!hasLinks) {
Text(
text = text,
style = style,
style = style.copy(textDirection = TextDirection.Content),
color = color,
modifier = modifier,
)
Expand All @@ -1189,7 +1190,7 @@ private fun MarkdownText(

ClickableText(
text = text,
style = style.copy(color = color),
style = style.copy(color = color, textDirection = TextDirection.Content),
modifier = modifier,
) { offset ->
text.getStringAnnotations(
Expand Down Expand Up @@ -1944,7 +1945,7 @@ private fun parseInlineMarkdownLink(
)
}

private fun inlineMarkdown(
internal fun inlineMarkdown(
text: String,
sourceOffset: Int,
fadeSpan: MarkdownFadeSpan?,
Expand Down
12 changes: 12 additions & 0 deletions app/src/test/java/com/zhousl/aether/ui/MarkdownRendererTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import org.junit.Assert.assertTrue
import org.junit.Test

class MarkdownRendererTest {
@Test
fun inlineMarkdownDoesNotInjectBidiControlsIntoSelectableText() {
val rendered = inlineMarkdown(
text = "سلام `printf('%s', value)` دنیا",
sourceOffset = 0,
fadeSpan = null,
)

assertEquals("سلام printf('%s', value) دنیا", rendered.text)
assertFalse(rendered.text.any { it in "\u2066\u2067\u2068\u2069" })
}

@Test(timeout = 1_000L)
fun parseMarkdownTreatsIncompleteTableLineAsParagraph() {
val blocks = parseMarkdownBlocks("| Effort | Share |")
Expand Down
Loading