Skip to content

Commit 9f6a35c

Browse files
committed
Apply requested changes
1 parent c5889f1 commit 9f6a35c

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object MyMath:
3030

3131
end MyMath
3232
```
33-
33+
xc
3434
This introduces `Logarithm` as a new abstract type, which is implemented as `Double`.
3535
The fact that `Logarithm` is the same as `Double` is only known in the scope where
3636
`Logarithm` is defined which in the above example corresponds to the object `MyMath`.

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,14 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
121121
BooleanSetting("-Yapi-subdirectory", "Put the API documentation pages inside a directory `api/`", false)
122122

123123
val projectFormat: Setting[String] =
124-
StringSetting("-format", "format of the static site output", "Format of the static site output", "html")
124+
ChoiceSetting(
125+
"-format",
126+
"format of the static site output",
127+
"Format of the static site output. The default value is html, which converts all static articles into a webpage. " +
128+
"The md format only preprocess markdown files and should not be used as a direct output, but rather as a sources generator for an outer templating engine like Jekyll",
129+
List("html", "md"),
130+
"html"
131+
)
125132

126133
def scaladocSpecificSettings: Set[Setting[_]] =
127134
Set(sourceLinks, syntax, revision, externalDocumentationMappings, socialLinks, skipById, skipByRegex, deprecatedSkipPackages, docRootContent, snippetCompiler, generateInkuire)

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetFormattingExtension.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import com.vladsch.flexmark.util.options._
1212
import com.vladsch.flexmark.util.sequence.BasedSequence
1313
import com.vladsch.flexmark._
1414

15+
/**
16+
* SnippetFormattingExtension is a clone of the [[SnippetRenderingExtension]] used as a fallback strategy when the `-format` setting is set up to `md`
17+
*/
1518
object SnippetFormattingExtension extends Formatter.FormatterExtension:
1619

1720
def rendererOptions(opt: MutableDataHolder): Unit = ()
1821

1922
object ExtendedFencedCodeBlockHandler extends CustomNodeFormatter[ExtendedFencedCodeBlock]:
2023
override def render(node: ExtendedFencedCodeBlock, c: NodeFormatterContext, markdown: MarkdownWriter): Unit =
2124
markdown.append(
22-
SnippetRenderer.renderSnippetWithMessages(
23-
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
24-
node.compilationResult.toSeq.flatMap(_.messages)
25-
)
25+
SnippetRenderer.renderSnippetWithMessages(node)
2626
)
2727

2828
object Format extends NodeFormatter:

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,11 @@ object SnippetRenderer:
137137
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage]): String =
138138
val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML)
139139
val codeHTML = s"""<code class="language-scala">${transformedLines.mkString("")}</code>"""
140-
s"""<div class="snippet"><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
140+
s"""<div class="snippet"><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
141+
142+
def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String =
143+
renderSnippetWithMessages(
144+
node.name,
145+
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
146+
node.compilationResult.toSeq.flatMap(_.messages)
147+
)

scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderingExtension.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ import com.vladsch.flexmark.util.options._
1313
import com.vladsch.flexmark.util.sequence.BasedSequence
1414
import com.vladsch.flexmark._
1515

16+
/**
17+
* SnippetRenderingExtension is responsible for running an analysis for scala codeblocks in the static documentation/scaladoc comments.
18+
* For each codeblock we run compiler to check whether snippet works in the newest scala version and to produce rich html codeblocks with
19+
* compiler warnings/errors for IDE-like live experience.
20+
*/
1621
object SnippetRenderingExtension extends HtmlRenderer.HtmlRendererExtension:
1722
def rendererOptions(opt: MutableDataHolder): Unit = ()
1823
object ExtendedFencedCodeBlockHandler extends CustomNodeRenderer[ExtendedFencedCodeBlock]:
1924
override def render(node: ExtendedFencedCodeBlock, c: NodeRendererContext, html: HtmlWriter): Unit =
2025
html.raw(
21-
SnippetRenderer.renderSnippetWithMessages(
22-
node.name,
23-
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
24-
node.compilationResult.toSeq.flatMap(_.messages)
25-
)
26+
SnippetRenderer.renderSnippetWithMessages(node)
2627
)
2728

2829
object Render extends NodeRenderer:
@@ -35,4 +36,4 @@ object SnippetRenderingExtension extends HtmlRenderer.HtmlRendererExtension:
3536
override def create(options: DataHolder): NodeRenderer = Render
3637

3738
def extend(htmlRendererBuilder: HtmlRenderer.Builder, tpe: String): Unit =
38-
htmlRendererBuilder.nodeRendererFactory(Factory)
39+
htmlRendererBuilder.nodeRendererFactory(Factory)

0 commit comments

Comments
 (0)