Skip to content

Commit f1872da

Browse files
committed
fixing broken behavior with latest JSoup
1 parent 48b9b4e commit f1872da

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ class DocumentationPreprocessor : KotlinIntegration {
5656
.applyWithin("<code>", "</code>", String::escapeHtml)
5757
.applyWithin("<pre>", "</pre>", String::escapeHtml)
5858
val parsed = Jsoup.parse(sanitized)
59+
60+
fun Node.emptyOrBlank(): Boolean = when {
61+
this is TextNode -> isBlank
62+
else -> childNodes().all { it.emptyOrBlank() }
63+
}
5964

6065
parsed.body().filterDescendants(
6166
// Jsoup will preserve newlines between elements as blank text nodes. These have zero bearing on the content
6267
// of the document to begin with and only serve to complicate traversal.
6368
{ it is TextNode && it.isBlank },
6469
// Some docs contain empty definition terms, which we render as section headers. An empty section header
6570
// (literal "## \n" is invalid markdown according to dokka.
66-
{ it.nodeName() == "dt" && it.childNodes().isEmpty() },
71+
{ it.nodeName() == "dt" && it.emptyOrBlank() },
6772
)
6873

6974
return parsed

0 commit comments

Comments
 (0)