Skip to content

Commit fe6e667

Browse files
committed
fix: documentation trait handling empty list items
1 parent f0df363 commit fe6e667

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/lang/DocumentationPreprocessor.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ class DocumentationPreprocessor : KotlinIntegration {
3939
val parsed = parseClean(doc)
4040

4141
val renderer = MarkdownRenderer()
42-
parsed.body().traverse(renderer)
42+
try {
43+
parsed.body().traverse(renderer)
44+
} catch (e: IndexOutOfBoundsException) {
45+
throw Exception("These are the docs causing issues: \n" + doc)
46+
}
4347
return renderer.text()
4448
}
4549

@@ -102,9 +106,11 @@ class DocumentationPreprocessor : KotlinIntegration {
102106
}
103107
}
104108
"li" -> {
109+
val childNode = if (node.childNodes().isNotEmpty()) node.childNode(0) else null
110+
105111
// If this list item holds a sublist, then we essentially just want to line break right away and
106112
// render the nested list as normal.
107-
val prefix = if (node.childNode(0).nodeName() == "ul") "\n" else ""
113+
val prefix = if (childNode?.nodeName() == "ul") "\n" else ""
108114
builder.append("$listPrefix+ $prefix")
109115
}
110116
"ul", "ol" -> {

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/lang/DocumentationPreprocessorTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ class DocumentationPreprocessorTest {
9494
inputTest(input, expected)
9595
}
9696

97+
@Test
98+
fun `it renders lists with empty list items`() {
99+
val input = "<p>an unordered list with empty list items:</p><ul><li></li><li></li></ul>"
100+
val expected = """
101+
an unordered list with empty list items:
102+
+
103+
+
104+
""".trimIndent()
105+
inputTest(input, expected)
106+
}
107+
97108
@Test
98109
fun `it renders basic formatters`() {
99110
val input = "<strong>bold text</strong><br/><em>italic text</em>"

0 commit comments

Comments
 (0)