aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Formats
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2016-01-12 16:14:21 +0100
committerDmitry Jemerov <yole@jetbrains.com>2016-01-12 16:14:21 +0100
commita3ec2e2afd6f4140ac78f7630fa9c2ca1f8ca8af (patch)
treec0a87789124c2fff312c5b32f1a4e6815129abca /core/src/main/kotlin/Formats
parent99b6196bde4773fd26bd733ecf5e3984ce0a4c63 (diff)
downloaddokka-a3ec2e2afd6f4140ac78f7630fa9c2ca1f8ca8af.tar.gz
dokka-a3ec2e2afd6f4140ac78f7630fa9c2ca1f8ca8af.tar.bz2
dokka-a3ec2e2afd6f4140ac78f7630fa9c2ca1f8ca8af.zip
generate signature-based anchors for overloads; use signature instead of name as an anchor for in-page links
Diffstat (limited to 'core/src/main/kotlin/Formats')
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt5
-rw-r--r--core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt3
-rw-r--r--core/src/main/kotlin/Formats/MarkdownFormatService.kt18
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt12
4 files changed, 17 insertions, 21 deletions
diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt
index f78439ba..f0d7e6c8 100644
--- a/core/src/main/kotlin/Formats/HtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt
@@ -22,8 +22,9 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
return "<span class=\"keyword\">${formatText(text)}</span>"
}
- override fun formatIdentifier(text: String, kind: IdentifierKind): String {
- return "<span class=\"identifier\">${formatText(text)}</span>"
+ override fun formatIdentifier(text: String, kind: IdentifierKind, signature: String?): String {
+ val id = signature?.let { " id=\"$it\"" }.orEmpty()
+ return "<span class=\"identifier\"$id>${formatText(text)}</span>"
}
override fun appendBlockCode(to: StringBuilder, line: String, language: String) {
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
index f869bc75..14157cff 100644
--- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
+++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt
@@ -124,7 +124,8 @@ class KotlinWebsiteFormatService @Inject constructor(locationService: LocationSe
return "<span class=\"keyword\">${formatText(text)}</span>"
}
- override fun formatIdentifier(text: String, kind: IdentifierKind): String {
+ override fun formatIdentifier(text: String, kind: IdentifierKind, signature: String?): String {
+ val id = signature?.let { " id=\"$it\"" }.orEmpty()
return "<span class=\"${identifierClassName(kind)}\">${formatText(text)}</span>"
}
diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
index 4e16b1a8..7a93801e 100644
--- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt
+++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt
@@ -12,20 +12,10 @@ open class MarkdownFormatService
return items.map { formatLink(it) }.joinToString(" / ")
}
- override fun formatText(text: String): String {
- return text.htmlEscape()
- }
-
- override fun formatSymbol(text: String): String {
- return text.htmlEscape()
- }
-
- override fun formatKeyword(text: String): String {
- return text.htmlEscape()
- }
- override fun formatIdentifier(text: String, kind: IdentifierKind): String {
- return text.htmlEscape()
- }
+ override fun formatText(text: String): String = text.htmlEscape()
+ override fun formatSymbol(text: String): String = text.htmlEscape()
+ override fun formatKeyword(text: String): String = text.htmlEscape()
+ override fun formatIdentifier(text: String, kind: IdentifierKind, signature: String?): String = text.htmlEscape()
override fun formatCode(code: String): String {
return "`$code`"
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index 1d464396..9221004c 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -31,7 +31,7 @@ abstract class StructuredFormatService(locationService: LocationService,
abstract fun formatText(text: String): String
abstract fun formatSymbol(text: String): String
abstract fun formatKeyword(text: String): String
- abstract fun formatIdentifier(text: String, kind: IdentifierKind): String
+ abstract fun formatIdentifier(text: String, kind: IdentifierKind, signature: String?): String
fun formatEntity(text: String): String = text
abstract fun formatLink(text: String, href: String): String
open fun formatLink(link: FormatLink): String = formatLink(formatText(link.text), link.href)
@@ -60,7 +60,7 @@ abstract class StructuredFormatService(locationService: LocationService,
is ContentText -> to.append(formatText(content.text))
is ContentSymbol -> to.append(formatSymbol(content.text))
is ContentKeyword -> to.append(formatKeyword(content.text))
- is ContentIdentifier -> to.append(formatIdentifier(content.text, content.kind))
+ is ContentIdentifier -> to.append(formatIdentifier(content.text, content.kind, content.signature))
is ContentNonBreakingSpace -> to.append(formatNonBreakingSpace())
is ContentSoftLineBreak -> to.append(formatSoftLineBreak())
is ContentIndentedSoftLineBreak -> to.append(formatIndentedSoftLineBreak())
@@ -107,7 +107,8 @@ abstract class StructuredFormatService(locationService: LocationService,
fun locationHref(from: Location, to: DocumentationNode): String {
val topLevelPage = to.references(RefKind.TopLevelPage).singleOrNull()?.to
if (topLevelPage != null) {
- return from.relativePathTo(locationService.location(topLevelPage), to.name)
+ val signature = to.detailOrNull(NodeKind.Signature)
+ return from.relativePathTo(locationService.location(topLevelPage), signature?.name ?: to.name)
}
return from.relativePathTo(locationService.location(to))
}
@@ -180,9 +181,12 @@ abstract class StructuredFormatService(locationService: LocationService,
}
}
- private fun formatOverloadGroup(items: MutableList<DocumentationNode>) {
+ private fun formatOverloadGroup(items: List<DocumentationNode>) {
items.forEach {
val rendered = languageService.render(it)
+ it.detailOrNull(NodeKind.Signature)?.let {
+ appendAnchor(to, it.name)
+ }
appendAsSignature(to, rendered) {
to.append(formatCode(formatText(location, rendered)))
it.appendSourceLink()