Skip to content

Commit

Permalink
Add support for header tags in Javadoc (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
asfalcone committed Feb 8, 2022
1 parent a3baead commit 176b735
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Expand Up @@ -421,6 +421,9 @@ class JavadocParser(
parsed
}
}
"h1" -> ifChildrenPresent { H1(children) }
"h2" -> ifChildrenPresent { H2(children) }
"h3" -> ifChildrenPresent { H3(children) }
else -> listOf(Text(body = element.ownText()))
}
}
Expand Down
47 changes: 47 additions & 0 deletions plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt
Expand Up @@ -349,4 +349,51 @@ class JavadocParserTest : BaseAbstractTest() {
}
}
}

@Test
fun `header tags are handled properly`() {
val source = """
|/src/main/kotlin/test/Test.java
|package example
|
| /**
| * An example of using the header tags
| * <h1>A header</h1>
| * <h2>A second level header</h2>
| * <h3>A third level header</h3>
| */
| public class Test {}
""".trimIndent()
testInline(
source,
configuration,
) {
documentablesCreationStage = { modules ->
val docs = modules.first().packages.first().classlikes.single().documentation.first().value
val root = docs.children.first().root

kotlin.test.assertEquals(
listOf(
P(children = listOf(Text("An example of using the header tags "))),
H1(
listOf(
Text("A header")
)
),
H2(
listOf(
Text("A second level header")
)
),
H3(
listOf(
Text("A third level header")
)
)
),
root.children
)
}
}
}
}

0 comments on commit 176b735

Please sign in to comment.