Skip to content

Commit

Permalink
Handle api links
Browse files Browse the repository at this point in the history
  • Loading branch information
mkondratek committed Sep 21, 2020
1 parent 6475e0d commit dfa2760
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
7 changes: 6 additions & 1 deletion documentation/docs/static-page/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
61 changes: 50 additions & 11 deletions src/main/kotlin/com/virtuslab/dokka/site/processors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -206,17 +207,7 @@ class SitePagesCreator(cxt: DokkaContext) : BaseStaticSiteProcessor(cxt) {

private fun parseMarkdown(page: PreResolvedPage, dri: DRI, allDRIs: Map<String, DRI>): 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()
Expand Down Expand Up @@ -244,6 +235,54 @@ class SitePagesCreator(cxt: DokkaContext) : BaseStaticSiteProcessor(cxt) {
)
}

private fun getExternalDriResolver(
dri: DRI,
allDRIs: Map<String, DRI>
): (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<File>): List<StaticPageNode> {
val all = files.mapNotNull { loadTemplate(it) }
fun flatten(it: LoadedTemplate): List<String> =
Expand Down

0 comments on commit dfa2760

Please sign in to comment.