Skip to content

Commit

Permalink
Apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkingBad committed Jan 17, 2022
1 parent a9c8e8d commit a3c9a6a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/src/main/kotlin/utilities/Html.kt
Expand Up @@ -7,9 +7,9 @@ import java.net.URLEncoder
* Replaces symbols reserved in HTML with their respective entities.
* Replaces & with &amp;, < with &lt; and > with &gt;
*/
fun String.htmlEscape(): String = replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
fun String.htmlEscape(): String = replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")

fun String.urlEncoded(): String = URLEncoder.encode(this, "UTF-8")

fun String.formatToEndWithHtml() =
if (endsWith(".html") || contains(Regex("\\.html#"))) this else "$this.html"
if (endsWith(".html") || contains(Regex("\\.html#"))) this else "$this.html"
Expand Up @@ -306,7 +306,7 @@ private class DokkaDescriptorVisitor(
val classlikes = async { descriptorsWithKind.classlikes.visitClasslikes(driWithPlatform) }

DEnumEntry(
dri = driWithPlatform.dri.copy(extra = DRIExtraContainer().also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode()),
dri = driWithPlatform.dri.copy(extra = DRIExtraContainer(driWithPlatform.dri.extra).also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode()),
name = descriptor.name.asString(),
documentation = descriptor.resolveDescriptorData(),
functions = functions.await(),
Expand Down
Expand Up @@ -269,7 +269,7 @@ class DefaultPsiToDocumentableTranslator(
name.orEmpty(),
fields.filterIsInstance<PsiEnumConstant>().map { entry ->
DEnumEntry(
dri.withClass(entry.name).copy(extra = DRIExtraContainer().also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode()),
dri.withClass(entry.name).copy(extra = DRIExtraContainer(dri.extra).also { it[EnumEntryDRIExtra] = EnumEntryDRIExtra }.encode()),
entry.name,
javadocParser.parseDocumentation(entry).toSourceSetDependent(),
null,
Expand Down
Expand Up @@ -326,7 +326,7 @@ class JavadocParser(
dri.toString()
} ?: UNRESOLVED_PSI_ELEMENT

return """<a data-dri="${dri.replace("\"", "&quot;")}">${label.ifBlank{ defaultLabel().text }}</a>"""
return """<a data-dri="${dri.htmlEscape()}">${label.ifBlank{ defaultLabel().text }}</a>"""
}

private fun convertInlineDocTag(
Expand Down
@@ -1,6 +1,8 @@
package linking

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRIExtraContainer
import org.jetbrains.dokka.links.EnumEntryDRIExtra
import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.model.doc.DocumentationLink
import org.jetbrains.dokka.pages.ContentDRILink
Expand All @@ -13,7 +15,7 @@ import java.nio.file.Paths
import utils.TestOutputWriterPlugin
import java.lang.AssertionError

class EnumValuesLinking : BaseAbstractTest() {
class EnumValuesLinkingTest : BaseAbstractTest() {

@Test
fun `check if enum values are correctly linked`() {
Expand Down Expand Up @@ -41,6 +43,7 @@ class EnumValuesLinking : BaseAbstractTest() {
is DocumentationLink -> kotlinLink.dri.run {
assertEquals("KotlinEnum.ON_CREATE", this.classNames)
assertEquals(null, this.callable)
assertNotNull(DRIExtraContainer(extra)[EnumEntryDRIExtra])
}
else -> throw AssertionError("Link node is not DocumentationLink type")
}
Expand All @@ -49,6 +52,7 @@ class EnumValuesLinking : BaseAbstractTest() {
is DocumentationLink -> javaLink.dri.run {
assertEquals("JavaEnum.ON_DECEIT", this.classNames)
assertEquals(null, this.callable)
assertNotNull(DRIExtraContainer(extra)[EnumEntryDRIExtra])
}
else -> throw AssertionError("Link node is not DocumentationLink type")
}
Expand All @@ -60,6 +64,7 @@ class EnumValuesLinking : BaseAbstractTest() {
is DocumentationLink -> kotlinLink.dri.run {
assertEquals("KotlinEnum.ON_CREATE", this.classNames)
assertEquals(null, this.callable)
assertNotNull(DRIExtraContainer(extra)[EnumEntryDRIExtra])
}
else -> throw AssertionError("Link node is not DocumentationLink type")
}
Expand All @@ -68,6 +73,7 @@ class EnumValuesLinking : BaseAbstractTest() {
is DocumentationLink -> javaLink.dri.run {
assertEquals("JavaEnum.ON_DECEIT", this.classNames)
assertEquals(null, this.callable)
assertNotNull(DRIExtraContainer(extra)[EnumEntryDRIExtra])
}
else -> throw AssertionError("Link node is not DocumentationLink type")
}
Expand Down
Expand Up @@ -149,13 +149,13 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
val map = allPagesOfType<JavadocClasslikePageNode>().first { it.name == "TestClass" }.templateMap
assertEquals("TestClass", map["name"])
val signature = assertIsInstance<Map<String, Any?>>(map["signature"])
assertEquals("@<a href=Author.html>Author</a>(name = \"Benjamin Franklin\")", signature["annotations"])
assertEquals("@<a href=Author.html>Author</a>(name = &quot;Benjamin Franklin&quot;)", signature["annotations"])

val methods = assertIsInstance<Map<Any, Any?>>(map["methods"])
val ownMethods = assertIsInstance<List<*>>(methods["own"])
val method = assertIsInstance<Map<String, Any?>>(ownMethods.single())
val methodSignature = assertIsInstance<Map<String, Any?>>(method["signature"])
assertEquals("@<a href=Author.html>Author</a>(name = \"Franklin D. Roosevelt\")", methodSignature["annotations"])
assertEquals("@<a href=Author.html>Author</a>(name = &quot;Franklin D. Roosevelt&quot;)", methodSignature["annotations"])
}
}

Expand Down

0 comments on commit a3c9a6a

Please sign in to comment.