diff --git a/documentation/docs/static-page/links.md b/documentation/docs/static-page/links.md index 96438dd..fc459dd 100644 --- a/documentation/docs/static-page/links.md +++ b/documentation/docs/static-page/links.md @@ -9,4 +9,9 @@ Our side supports standard markdown links: - TODO Using standard [urls](https://pl.wikipedia.org/wiki/Uniform_Resource_Locator) - TODO To [other (html) pages](/docs/static-page/samples/plain_html_file.html) (or [md based files](/docs/static-page/samples/plain_md_file.md)) in our documentation that using paths relative to root od documentation e.g. `/docs/static-page/sample/plain_html_file.html` for this project - TODO To [other (html) pages](samples/plain_html_file.html) (or [md based files](samples/plain_md_file.md)) in our documentation that using paths relative to this file e.g. using `samples/plain_html_file.html` - - TODO To API using `[fully.quallifty.Name]` + - TODO To API (using `[fully.quallifty.Name]`) + - [package](com.virtuslab.dokka.site) + - [top level fun](com.virtuslab.dokka.site::loadTemplateFile) + - [class](com.virtuslab.dokka.site#ExtendableMarkdownParser) + - [member fun](com.virtuslab.dokka.site#TemplateFile::resolveMarkdown) + - [member fun (no params)](com.virtuslab.dokka.site#ExtendableMarkdownParser::parse) diff --git a/src/main/kotlin/com/virtuslab/dokka/site/processors.kt b/src/main/kotlin/com/virtuslab/dokka/site/processors.kt index 417a363..ca2d070 100644 --- a/src/main/kotlin/com/virtuslab/dokka/site/processors.kt +++ b/src/main/kotlin/com/virtuslab/dokka/site/processors.kt @@ -3,6 +3,7 @@ package com.virtuslab.dokka.site import org.jetbrains.dokka.base.renderers.html.NavigationNode import org.jetbrains.dokka.base.renderers.html.NavigationPage import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter +import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.doc.Text @@ -206,17 +207,7 @@ class SitePagesCreator(cxt: DokkaContext) : BaseStaticSiteProcessor(cxt) { private fun parseMarkdown(page: PreResolvedPage, dri: DRI, allDRIs: Map): ContentNode { val nodes = if (page.hasMarkdown) { - val parser = ExtendableMarkdownParser(page.code) { link -> - val driKey = if (link.startsWith("/")) { - // handle root related links - link.replace('/', '.').removePrefix(".") - } else { - val unSuffixedDri = dri.packageName!!.removeSuffix(".html").removeSuffix(".md") - val parentDri = unSuffixedDri.take(unSuffixedDri.indexOfLast('.'::equals)).removePrefix("_.") - "${parentDri}.${link.replace('/', '.')}" - } - allDRIs[driKey] - } + val parser = ExtendableMarkdownParser(page.code, getExternalDriResolver(dri, allDRIs)) val docTag = try { parser.parse() @@ -244,6 +235,54 @@ class SitePagesCreator(cxt: DokkaContext) : BaseStaticSiteProcessor(cxt) { ) } + private fun getExternalDriResolver( + dri: DRI, + allDRIs: Map + ): (String) -> DRI? = { + if (it.endsWith(".html") || it.endsWith(".md")) { + val driKey = if (it.startsWith("/")) { + // handle root related links + it.replace('/', '.').removePrefix(".") + } else { + // handle relative links + val unSuffixedDri = dri.packageName!!.removeSuffix(".html").removeSuffix(".md") + val parentDri = unSuffixedDri.take(unSuffixedDri.indexOfLast('.'::equals)).removePrefix("_.") + "${parentDri}.${it.replace('/', '.')}" + } + allDRIs[driKey] + } else { + // handle api links + if ('#' in it) { + // member fun + val (packageName, classNameAndRest) = it.split('#') + if ("::" in classNameAndRest) { + val (classNames, callableName) = classNameAndRest.split("::") + DRI( + packageName = packageName, + classNames = classNames, + callable = Callable(name = callableName, params = emptyList()) + ) + } else { + DRI( + packageName = packageName, + classNames = classNameAndRest + ) + } + } else if ("::" in it) { + // top level fun + val (packageName, callableName) = it.split("::") + DRI( + packageName = packageName, + callable = Callable(name = callableName, params = emptyList()) + ) + } else { + // package + DRI(it) + } + } + } + + private fun loadFiles(files: List): List { val all = files.mapNotNull { loadTemplate(it) } fun flatten(it: LoadedTemplate): List =