Skip to content

Commit 2e91778

Browse files
committed
Turn off not checked and failing snippets
1 parent cfc34a7 commit 2e91778

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,26 @@ object SnippetRenderer:
134134
div(cls := "snippet-label")(name)
135135
).toString
136136

137-
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String =
137+
def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): 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" scala-snippet ${if hasContext then "hasContext" else ""}><div class="buttons"></div><pre>$codeHTML</pre>${snippetName.fold("")(snippetLabel(_))}</div>"""
140+
val isRunnable = !hasContext && success
141+
val attrs = Seq(
142+
Option.when(isRunnable)(Attr("runnable") := "")
143+
).flatten
144+
div(cls := "snippet", Attr("scala-snippet") := "", attrs)(
145+
div(cls := "buttons")(),
146+
pre(
147+
raw(codeHTML)
148+
),
149+
raw(snippetName.fold("")(snippetLabel(_)))
150+
).toString
141151

142152
def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String =
143153
renderSnippetWithMessages(
144154
node.name,
145155
node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq,
146156
node.compilationResult.toSeq.flatMap(_.messages),
147-
node.hasContext
157+
node.hasContext,
158+
node.compilationResult.fold(false)(_.isSuccessful)
148159
)

0 commit comments

Comments
 (0)