Skip to content

Commit

Permalink
Add support for running piped Markdown sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Nov 15, 2022
1 parent 63dc747 commit 78ea400
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/build/src/main/scala/scala/build/input/Inputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ object Inputs {
Right(Seq(VirtualJavaFile(stdinOpt0.get, "<stdin>-java-file")))
else if ((arg == "-" || arg == "-.sc" || arg == "_.sc") && stdinOpt0.nonEmpty)
Right(Seq(VirtualScript(stdinOpt0.get, "stdin", os.sub / "stdin.sc")))
else if ((arg == "-.md" || arg == "_.md") && stdinOpt0.nonEmpty)
Right(Seq(VirtualMarkdownFile(stdinOpt0.get, "<stdin>-markdown-file", os.sub / "stdin.md")))
else if (arg.endsWith(".zip") && os.exists(os.Path(arg, cwd))) {
val content = os.read.bytes(os.Path(arg, cwd))
Right(resolveZipArchive(content, enableMarkdown))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,21 @@ trait RunPipedSourcesTestDefinitions { _: RunTestDefinitions =>
}
}
}

test("Markdown code with a scala snippet accepted as piped input") {
val expectedOutput = "Hello"
val pipedInput =
s"""# Piped Markdown
|A simple `scala` snippet
|```scala
|println("$expectedOutput")
|```
|""".stripMargin
emptyInputs.fromRoot { root =>
val output = os.proc(TestUtil.cli, "_.md", extraOptions)
.call(cwd = root, stdin = pipedInput)
.out.trim()
expect(output == expectedOutput)
}
}
}

0 comments on commit 78ea400

Please sign in to comment.