Skip to content

Commit

Permalink
Support of var html tag for JavaDoc
Browse files Browse the repository at this point in the history
Fix #2358
  • Loading branch information
atyrin committed Aug 9, 2022
1 parent efed96e commit 48f438d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/kotlin/pages/ContentNodes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ enum class TokenStyle : Style {
enum class TextStyle : Style {
Bold, Italic, Strong, Strikethrough, Paragraph,
Block, Span, Monospace, Indented, Cover, UnderCoverText, BreakableAfter, Breakable, InlineComment, Quotation,
FloatingRight
FloatingRight, Var
}

enum class ContentStyle : Style {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BlockQuote(vararg matchers: Any) : Tag("blockquote", *matchers)
class Dl(vararg matchers: Any) : Tag("dl", *matchers)
class Dt(vararg matchers: Any) : Tag("dt", *matchers)
class Dd(vararg matchers: Any) : Tag("dd", *matchers)
class Var(vararg matchers: Any) : Tag("var", *matchers)
object Wbr : Tag("wbr")
object Br : Tag("br")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ open class HtmlRenderer(
TextStyle.Italic -> i { body() }
TextStyle.Strikethrough -> strike { body() }
TextStyle.Strong -> strong { body() }
TextStyle.Var -> htmlVar { body() }
is TokenStyle -> span("token " + styleToApply.toString().toLowerCase()) { body() }
else -> body()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ open class DocTagToContentConverter : CommentsToContentConverter {
extra = extras
)
)
is Var -> buildChildren(docTag, setOf(TextStyle.Var))

else -> buildChildren(docTag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class JavadocParser(
"h1" -> ifChildrenPresent { H1(children) }
"h2" -> ifChildrenPresent { H2(children) }
"h3" -> ifChildrenPresent { H3(children) }
"var" -> ifChildrenPresent { Var(children) }
else -> listOf(Text(body = element.ownText()))
}
}
Expand Down
32 changes: 32 additions & 0 deletions plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,36 @@ class JavadocParserTest : BaseAbstractTest() {
}
}
}

@Test
fun `var tag is handled properly`() {
val source = """
|/src/main/kotlin/test/Test.java
|package example
|
| /**
| * An example of using var tag: <var>variable</var>
| */
| 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 var tag: "),
Var(children = listOf(Text("variable"))),
)),
),
root.children
)
}
}
}
}
12 changes: 12 additions & 0 deletions plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ class TextStylesTest : HtmlRenderingOnlyTestBase() {
renderedContent.match(BlockQuote("blockquote text"))
}

@Test
fun `should include var`() {
val page = testPage {
group(styles = setOf(TextStyle.Var)) {
text("variable")
}
}
HtmlRenderer(context).render(page)
println(renderedContent)
renderedContent.match(Var("variable"))
}

override val renderedContent: Element
get() = files.contents.getValue("test-page.html").let { Jsoup.parse(it) }.select("#content").single()
}

0 comments on commit 48f438d

Please sign in to comment.