diff --git a/core/src/main/scala/com/lightbend/paradox/markdown/Directive.scala b/core/src/main/scala/com/lightbend/paradox/markdown/Directive.scala index 8b543b28..d6a1b4d4 100644 --- a/core/src/main/scala/com/lightbend/paradox/markdown/Directive.scala +++ b/core/src/main/scala/com/lightbend/paradox/markdown/Directive.scala @@ -324,6 +324,7 @@ case class ScaladocDirective(ctx: Writer.Context) object JavadocDirective { + type LinkStyle = String val LinkStyleFrames = "frames" val LinkStyleDirect = "direct" @@ -333,6 +334,16 @@ object JavadocDirective { val jdkDependentLinkStyle = if (sys.props.get("java.specification.version").exists(_.startsWith("1."))) LinkStyleFrames else LinkStyleDirect final val JavadocLinkStyleProperty = raw"""javadoc\.(.*).link_style""".r + + private[markdown] def url(link: String, baseUrl: Url, linkStyle: LinkStyle): Url = { + val url = Url(link).base + val path = url.getPath.replaceAll("(\\b[a-z]+)\\.", "$1/") + ".html" + linkStyle match { + case LinkStyleFrames => baseUrl.withEndingSlash.withQuery(path).withFragment(url.getFragment) + case LinkStyleDirect => (baseUrl / path).withFragment(url.getFragment) + } + } + } case class JavadocDirective(ctx: Writer.Context) @@ -353,12 +364,8 @@ case class JavadocDirective(ctx: Writer.Context) val packagesDeepestFirst = packages.reverse val baseUrl = packagesDeepestFirst.collectFirst(baseUrls).getOrElse(defaultBaseUrl).resolve() val linkStyle = packagesDeepestFirst.collectFirst(packageLinkStyle).getOrElse(rootLinkStyle) - val url = Url(link).base - val path = url.getPath.replace('.', '/') + ".html" - linkStyle match { - case LinkStyleFrames => baseUrl.withEndingSlash.withQuery(path).withFragment(url.getFragment) - case LinkStyleDirect => (baseUrl / path).withFragment(url.getFragment) - } + url(link, baseUrl, linkStyle) + } } diff --git a/tests/src/test/scala/com/lightbend/paradox/markdown/JavadocDirectiveSpec.scala b/tests/src/test/scala/com/lightbend/paradox/markdown/JavadocDirectiveSpec.scala index 8efab9f9..7e03fc4d 100644 --- a/tests/src/test/scala/com/lightbend/paradox/markdown/JavadocDirectiveSpec.scala +++ b/tests/src/test/scala/com/lightbend/paradox/markdown/JavadocDirectiveSpec.scala @@ -20,6 +20,8 @@ import com.lightbend.paradox.ParadoxException class JavadocDirectiveSpec extends MarkdownBaseSpec { + import JavadocDirective._ + implicit val context = writerContextWithProperties( "javadoc.base_url" -> "http://www.reactive-streams.org/reactive-streams-1.0.0-javadoc/", "javadoc.link_style" -> "frames", @@ -115,4 +117,20 @@ class JavadocDirectiveSpec extends MarkdownBaseSpec { |Direct: Publisher

""".stripMargin) } + it should "correctly link to an inner JRE class" in { + url( + "java.util.concurrent.Flow.Subscriber", + Url("https://docs.oracle.com/en/java/javase/11/docs/api/java.base/"), + LinkStyleDirect + ) should be(Url("https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/Flow.Subscriber.html")) + } + + it should "correctly link to an inner Akka class" in { + url( + "akka.actor.testkit.typed.Effect.MessageAdapter", + Url("https://doc.akka.io/japi/akka/current/"), + LinkStyleDirect + ) should be(Url("https://doc.akka.io/japi/akka/current/akka/actor/testkit/typed/Effect.MessageAdapter.html")) + } + }