Skip to content

Commit be70cd1

Browse files
authored
Merge pull request #78 from bstoker/bstoker/fix/allow_null_title_in_image
Allow null title in image
2 parents 8badc89 + 4730667 commit be70cd1

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ private val sampleMarkdown = """
243243
244244
## Images
245245
246-
Inline-style:
246+
Inline-style:
247+
248+
![random image](https://picsum.photos/seed/picsum/400/400)
247249
248250
![random image](https://picsum.photos/seed/picsum/400/400 "Text 1")
249251

richtext-commonmark/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ kotlin {
4141
implementation(Commonmark.strikethrough)
4242
}
4343
}
44+
45+
val jvmTest by getting {
46+
kotlin.srcDir("src/commonJvmAndroidTest/kotlin")
47+
dependencies {
48+
implementation(Kotlin.Test.jdk)
49+
}
50+
}
4451
}
4552
}

richtext-commonmark/src/commonJvmAndroid/kotlin/com/halilibo/richtext/markdown/AstNodeConvert.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ internal fun convert(
112112
literal = node.literal
113113
)
114114
is Image -> {
115-
if (node.title == null || node.destination == null) {
115+
if (node.destination == null) {
116116
null
117117
}
118118
else {
119119
AstImage(
120-
title = node.title,
120+
title = node.title ?: "",
121121
destination = node.destination
122122
)
123123
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.halilibo.richtext.markdown
2+
3+
import com.halilibo.richtext.markdown.node.AstImage
4+
import com.halilibo.richtext.markdown.node.AstNode
5+
import com.halilibo.richtext.markdown.node.AstNodeLinks
6+
import org.commonmark.node.Image
7+
import org.junit.Test
8+
import kotlin.test.assertEquals
9+
10+
internal class AstNodeConvertKtTest {
11+
12+
@Test
13+
fun `when image without title is converted, then the content description is empty`() {
14+
val destination = "/url"
15+
val image = Image(destination, null)
16+
17+
val result = convert(image)
18+
19+
assertEquals(
20+
expected = AstNode(
21+
type = AstImage(title = "", destination = destination),
22+
links = AstNodeLinks()
23+
),
24+
actual = result
25+
)
26+
}
27+
}

0 commit comments

Comments
 (0)