Skip to content

Commit 163beaf

Browse files
committed
Migrate remaning parts of Site Renderer
1 parent 57fdfb7 commit 163beaf

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import dotty.dokka.model.api.Link
2020
import dotty.dokka.model.api.HierarchyGraph
2121
import org.jetbrains.dokka.base.resolvers.local.LocationProvider
2222
import dotty.dokka.site.StaticPageNode
23+
import dotty.dokka.site.PartiallyRenderedContent
2324

2425
class SignatureRenderer(pageContext: ContentPage, sourceSetRestriciton: JSet[DisplaySourceSet], locationProvider: LocationProvider):
2526
def link(dri: DRI): Option[String] = Option(locationProvider.resolve(dri, sourceSetRestriciton, pageContext))
@@ -37,7 +38,7 @@ class SignatureRenderer(pageContext: ContentPage, sourceSetRestriciton: JSet[Dis
3738

3839
def renderElement(e: String | (String, DRI) | Link) = renderElementWith(e)
3940

40-
class ScalaHtmlRenderer(ctx: DokkaContext) extends HtmlRenderer(ctx) { // TODO migrate from dokka site!
41+
class ScalaHtmlRenderer(ctx: DokkaContext) extends HtmlRenderer(ctx) {
4142

4243
// Implementation below is based on Kotlin bytecode and we will try to migrate it to dokka
4344
// TODO (https://github.com/lampepfl/scala3doc/issues/232): Move this method to dokka
@@ -206,6 +207,7 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends HtmlRenderer(ctx) { // TODO m
206207
pageContext: ContentPage,
207208
): Unit = {
208209
// we cannot use Scalatags, because we need to call buildContentNode
210+
// TODO rewrite it to using HTML
209211
import kotlinx.html.{Gen_consumer_tagsKt => dsl}
210212
val c = f.getConsumer
211213

@@ -231,6 +233,30 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends HtmlRenderer(ctx) { // TODO m
231233
).toString()
232234
)
233235

236+
private def render(c: PartiallyRenderedContent, p: ContentPage): String =
237+
val parsed = if (!c.page.hasMarkdown) c.page.code else
238+
div(raw(
239+
buildWithKotlinx{ div =>
240+
c.getChildren.forEach(build(_, div, p, /*sourceSetRestriction=*/null))
241+
U
242+
}
243+
)).toString
244+
245+
return c.page.render(parsed).code
246+
247+
248+
override def buildPageContent(context: FlowContent, page: ContentPage): Unit =
249+
page match
250+
case s: StaticPageNode if !s.hasFrame() =>
251+
case _ => buildNavigation(context, page)
252+
253+
page.getContent match
254+
case prc: PartiallyRenderedContent =>
255+
withHtml(context, render(prc, page))
256+
case content =>
257+
build(content, context, page, /*sourceSetRestriction=*/null)
258+
259+
234260
override def buildHtml(page: PageNode, resources: JList[String], kotlinxContent: FlowContentConsumer): String =
235261
val (pageTitle, pageResources, fromTemplate) = page match
236262
case static: StaticPageNode =>
@@ -316,5 +342,4 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends HtmlRenderer(ctx) { // TODO m
316342
null,
317343
func
318344
).toString.stripPrefix("<div>").stripSuffix("</div>\n")
319-
320345
}

0 commit comments

Comments
 (0)