Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of var html tag for Javadoc #2617

Merged
merged 1 commit into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions core/api/core.api
Expand Up @@ -4292,6 +4292,7 @@ public final class org/jetbrains/dokka/pages/TextStyle : java/lang/Enum, org/jet
public static final field Strikethrough Lorg/jetbrains/dokka/pages/TextStyle;
public static final field Strong Lorg/jetbrains/dokka/pages/TextStyle;
public static final field UnderCoverText Lorg/jetbrains/dokka/pages/TextStyle;
public static final field Var Lorg/jetbrains/dokka/pages/TextStyle;
public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/dokka/pages/TextStyle;
public static fun values ()[Lorg/jetbrains/dokka/pages/TextStyle;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/pages/ContentNodes.kt
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
4 changes: 4 additions & 0 deletions plugins/base/base-test-utils/api/base-test-utils.api
Expand Up @@ -184,6 +184,10 @@ public final class utils/TestOutputWriterPlugin : org/jetbrains/dokka/plugabilit
public final fun getWriter ()Lutils/TestOutputWriter;
}

public final class utils/Var : utils/Tag {
public fun <init> ([Ljava/lang/Object;)V
}

public final class utils/Wbr : utils/Tag {
public static final field INSTANCE Lutils/Wbr;
}
Expand Down
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
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
Expand Up @@ -254,6 +254,7 @@ open class DocTagToContentConverter : CommentsToContentConverter {
extra = extras
)
)
is Var -> buildChildren(docTag, setOf(TextStyle.Var))

else -> buildChildren(docTag)
}
Expand Down
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
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
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()
}