Skip to content

Commit 4b3e218

Browse files
committed
Turn off not checked and failing snippets
1 parent 4babac0 commit 4b3e218

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

scaladoc-js/common/src/code-snippets/CodeSnippets.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class CodeSnippets:
179179
val buttonsSection = getButtonsSection(snippet)
180180
buttonsSection.foreach(s =>
181181
s.appendChild(copyButton)
182-
if !snippet.hasAttribute("hasContext") then {
182+
if snippet.hasAttribute("runnable") then {
183183
s.appendChild(toScastieButton)
184184
s.appendChild(runButton)
185185
s.appendChild(exitButton)

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.vladsch.flexmark.html._
55
import util.HTML._
66

77
import dotty.tools.scaladoc.snippets._
8-
import dotty.tools.scaladoc.util.HTML._
98

109
case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty, attributes: Map[String, String] = Map.empty):
1110
def withClass(cls: String) = this.copy(classes = classes + cls)
@@ -134,15 +133,26 @@ object SnippetRenderer:
134133
div(cls := "snippet-label")(name)
135134
).toString
136135

137-
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String =
136+
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): String =
138137
val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML)
139138
val codeHTML = s"""<code class="language-scala">${transformedLines.mkString("")}</code>"""
140-
s"""<div class="snippet" scala-snippet ${if hasContext then "hasContext" else ""}><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
139+
val isRunnable = !hasContext && success
140+
val attrs = Seq(
141+
Option.when(isRunnable)(Attr("runnable") := "")
142+
).flatten
143+
div(cls := "snippet", Attr("scala-snippet") := "", attrs)(
144+
div(cls := "buttons")(),
145+
pre(
146+
raw(codeHTML)
147+
),
148+
raw(snippetName.fold("")(snippetLabel(_)))
149+
).toString
141150

142151
def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String =
143152
renderSnippetWithMessages(
144153
node.name,
145154
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
146155
node.compilationResult.toSeq.flatMap(_.messages),
147-
node.hasContext
156+
node.hasContext,
157+
node.compilationResult.fold(false)(_.isSuccessful)
148158
)

0 commit comments

Comments
 (0)