diff --git a/scaladoc-js/common/src/code-snippets/CodeSnippets.scala b/scaladoc-js/common/src/code-snippets/CodeSnippets.scala index 6595aa77c372..47f301705f30 100644 --- a/scaladoc-js/common/src/code-snippets/CodeSnippets.scala +++ b/scaladoc-js/common/src/code-snippets/CodeSnippets.scala @@ -179,7 +179,7 @@ class CodeSnippets: val buttonsSection = getButtonsSection(snippet) buttonsSection.foreach(s => s.appendChild(copyButton) - if !snippet.hasAttribute("hasContext") then { + if snippet.hasAttribute("runnable") then { s.appendChild(toScastieButton) s.appendChild(runButton) s.appendChild(exitButton) diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala index 9c95ae06d9ee..65e14fa343c4 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala @@ -5,7 +5,6 @@ import com.vladsch.flexmark.html._ import util.HTML._ import dotty.tools.scaladoc.snippets._ -import dotty.tools.scaladoc.util.HTML._ case class SnippetLine(content: String, lineNo: Int, classes: Set[String] = Set.empty, messages: Seq[String] = Seq.empty, attributes: Map[String, String] = Map.empty): def withClass(cls: String) = this.copy(classes = classes + cls) @@ -134,15 +133,26 @@ object SnippetRenderer: div(cls := "snippet-label")(name) ).toString - def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean): String = + def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], hasContext: Boolean, success: Boolean): String = val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML) val codeHTML = s"""${transformedLines.mkString("")}""" - s"""
$codeHTML
${snippetName.fold("")(snippetLabel(_))}
""" + val isRunnable = !hasContext && success + val attrs = Seq( + Option.when(isRunnable)(Attr("runnable") := "") + ).flatten + div(cls := "snippet", Attr("scala-snippet") := "", attrs)( + div(cls := "buttons")(), + pre( + raw(codeHTML) + ), + raw(snippetName.fold("")(snippetLabel(_))) + ).toString def renderSnippetWithMessages(node: ExtendedFencedCodeBlock): String = renderSnippetWithMessages( node.name, node.codeBlock.getContentChars.toString.split("\n").map(_ + "\n").toSeq, node.compilationResult.toSeq.flatMap(_.messages), - node.hasContext + node.hasContext, + node.compilationResult.fold(false)(_.isSuccessful) )