blob: a6cc6cba8dd10395dfed775d06d11ac389b4fd16 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.jetbrains.dokka.jekyll
import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.PackageListCreator
import org.jetbrains.dokka.base.renderers.RootCreator
import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProviderFactory
import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
import org.jetbrains.dokka.gfm.GfmPlugin
import org.jetbrains.dokka.gfm.renderer.BriefCommentPreprocessor
import org.jetbrains.dokka.gfm.renderer.CommonmarkRenderer
import org.jetbrains.dokka.pages.ContentPage
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.query
import org.jetbrains.dokka.renderers.PostAction
import org.jetbrains.dokka.transformers.pages.PageTransformer
class JekyllPlugin : DokkaPlugin() {
val jekyllPreprocessors by extensionPoint<PageTransformer>()
private val dokkaBase by lazy { plugin<DokkaBase>() }
private val gfmPlugin by lazy { plugin<GfmPlugin>() }
val renderer by extending {
(CoreExtensions.renderer
providing { JekyllRenderer(it) }
override plugin<GfmPlugin>().renderer)
}
val rootCreator by extending {
jekyllPreprocessors with RootCreator
}
val briefCommentPreprocessor by extending {
jekyllPreprocessors with BriefCommentPreprocessor()
}
val packageListCreator by extending {
jekyllPreprocessors providing {
PackageListCreator(it, RecognizedLinkFormat.DokkaJekyll)
} order { after(rootCreator) }
}
val locationProvider by extending {
dokkaBase.locationProviderFactory providing ::DokkaLocationProviderFactory override listOf(gfmPlugin.locationProvider)
}
internal val alphaVersionNotifier by extending {
CoreExtensions.postActions providing { ctx ->
PostAction {
ctx.logger.info("Jekyll output format is in Alpha version, use at your own risk, expect bugs and migration issues")
}
}
}
}
class JekyllRenderer(
context: DokkaContext
) : CommonmarkRenderer(context) {
override val preprocessors = context.plugin<JekyllPlugin>().query { jekyllPreprocessors }
override fun buildPage(page: ContentPage, content: (StringBuilder, ContentPage) -> Unit): String {
val builder = StringBuilder()
builder.append("---\n")
builder.append("title: ${page.name}\n")
builder.append("---\n")
content(builder, page)
return builder.toString()
}
}
|