Skip to content

Commit 66a5159

Browse files
committed
Prototype of markdown preprocessing of static sites
1 parent cc47c56 commit 66a5159

File tree

6 files changed

+49
-11
lines changed

6 files changed

+49
-11
lines changed

docs/docs/reference/other-new-features/opaques.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
layout: doc-page
32
title: "Opaque Type Aliases"
3+
hasFrame: false
44
---
55

66
Opaque types aliases provide type abstraction without any overhead. Example:

docs/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Scala 3
33
layout: main
4-
hasFrame: false
54
extraCSS:
65
- css/frontpage.css
76
---

scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala

+1-7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,7 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
101101

102102
def renderPage(page: Page, parents: Vector[Link]): Seq[String] =
103103
val newParents = parents :+ page.link
104-
val content = html(
105-
mkHead(page),
106-
body(
107-
if !page.hasFrame then renderContent(page)
108-
else mkFrame(page.link, newParents, renderContent(page))
109-
)
110-
)
104+
val content = renderContent(page)
111105
write(page.link.dri, content) +: page.children.flatMap(renderPage(_, newParents))
112106

113107
private def specificResources(page: Page): Set[String] =

scaladoc/src/dotty/tools/scaladoc/site/common.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.vladsch.flexmark.ext.yaml.front.matter.{AbstractYamlFrontMatterVisito
1414
import com.vladsch.flexmark.parser.{Parser, ParserEmulationProfile}
1515
import com.vladsch.flexmark.util.options.{DataHolder, MutableDataSet}
1616
import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension
17+
import com.vladsch.flexmark.formatter.Formatter
1718

1819
import scala.collection.JavaConverters._
1920

@@ -36,7 +37,7 @@ val defaultMarkdownOptions: DataHolder =
3637
YamlFrontMatterExtension.create(),
3738
StrikethroughExtension.create(),
3839
WikiLinkExtension.create(),
39-
tasty.comments.markdown.SnippetRenderingExtension
40+
tasty.comments.markdown.SnippetFormattingExtension,
4041
))
4142

4243
def emptyTemplate(file: File, title: String): TemplateFile = TemplateFile(

scaladoc/src/dotty/tools/scaladoc/site/templates.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.vladsch.flexmark.ext.yaml.front.matter.{AbstractYamlFrontMatterVisito
1414
import com.vladsch.flexmark.parser.{Parser, ParserEmulationProfile}
1515
import com.vladsch.flexmark.util.options.{DataHolder, MutableDataSet}
1616
import com.vladsch.flexmark.html.HtmlRenderer
17+
import com.vladsch.flexmark.formatter.Formatter
1718
import liqp.Template
1819
import scala.collection.JavaConverters._
1920

@@ -107,7 +108,10 @@ case class TemplateFile(
107108
val parser: Parser = Parser.builder(defaultMarkdownOptions).build()
108109
val parsedMd = parser.parse(rendered)
109110
val processed = FlexmarkSnippetProcessor.processSnippets(parsedMd, ssctx.snippetCompilerArgs.debug, snippetCheckingFunc)(using ssctx.outerCtx)
110-
HtmlRenderer.builder(defaultMarkdownOptions).build().render(processed)
111+
112+
Formatter.builder(defaultMarkdownOptions).build().render(processed)
113+
114+
// HtmlRenderer.builder(defaultMarkdownOptions).build().render(processed)
111115

112116
layoutTemplate match
113117
case None => ResolvedPage(code, resources ++ ctx.resources)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package dotty.tools.scaladoc
2+
package tasty.comments.markdown
3+
4+
import dotty.tools.scaladoc.snippets._
5+
6+
import com.vladsch.flexmark.formatter._
7+
import com.vladsch.flexmark.parser._
8+
import com.vladsch.flexmark.ext.wikilink._
9+
import com.vladsch.flexmark.ext.wikilink.internal.WikiLinkLinkRefProcessor
10+
import com.vladsch.flexmark.util.ast._
11+
import com.vladsch.flexmark.util.options._
12+
import com.vladsch.flexmark.util.sequence.BasedSequence
13+
import com.vladsch.flexmark._
14+
15+
object SnippetFormattingExtension extends Formatter.FormatterExtension:
16+
17+
def rendererOptions(opt: MutableDataHolder): Unit = ()
18+
19+
object ExtendedFencedCodeBlockHandler extends CustomNodeFormatter[ExtendedFencedCodeBlock]:
20+
override def render(node: ExtendedFencedCodeBlock, c: NodeFormatterContext, markdown: MarkdownWriter): Unit =
21+
markdown.append(
22+
SnippetRenderer.renderSnippetWithMessages(
23+
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
24+
node.compilationResult.toSeq.flatMap(_.messages)
25+
)
26+
)
27+
28+
object Format extends NodeFormatter:
29+
override def getNodeFormattingHandlers: JSet[NodeFormattingHandler[?]] =
30+
JSet(
31+
new NodeFormattingHandler(classOf[ExtendedFencedCodeBlock], ExtendedFencedCodeBlockHandler),
32+
)
33+
34+
def getNodeClasses: JSet[Class[?]] = null
35+
36+
object Factory extends NodeFormatterFactory:
37+
override def create(options: DataHolder): NodeFormatter = Format
38+
39+
def extend(formatterBuilder: Formatter.Builder) =
40+
formatterBuilder.nodeFormatterFactory(Factory)

0 commit comments

Comments
 (0)