From 85a3ae7626810113816fd31a0e26d44d48308ed2 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 20 Feb 2015 14:08:30 +0100 Subject: support in-page anchors in locations --- src/Locations/LocationService.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/Locations/LocationService.kt') diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 96cd0c51..500b89f2 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -4,7 +4,7 @@ import java.io.File public trait Location { val path: String get - fun relativePathTo(other: Location): String + fun relativePathTo(other: Location, anchor: String? = null): String } /** @@ -19,12 +19,13 @@ public data class FileLocation(val file: File): Location { override val path : String get() = file.path - override fun relativePathTo(other: Location): String { + override fun relativePathTo(other: Location, anchor: String?): String { if (other !is FileLocation) { throw IllegalArgumentException("$other is not a FileLocation") } val ownerFolder = file.getParentFile()!! - return ownerFolder.getRelativePath(other.file).path + val relativePath = ownerFolder.getRelativePath(other.file).path + return if (anchor == null) relativePath else relativePath + "#" + anchor } } @@ -62,5 +63,5 @@ public fun identifierToFilename(path: String): String { * Returns relative location between two nodes. Used for relative links in documentation. */ fun LocationService.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { - return location(owner).relativePathTo(location(node)) + return location(owner).relativePathTo(location(node), null) } -- cgit