mdoc icon indicating copy to clipboard operation
mdoc copied to clipboard

How can I convert Scala 3.x code with mdoc CLI?

Open windymelt opened this issue 1 year ago • 5 comments

Hi, thank you for neat and useful software.

My mdoc (v2.6.1) seems not accepting Scala 3.x code from CLI.

For instance, following code does not compile:

```scala mdoc
def fib(n: Int): Int = n match
case 1 => 1
case n => n * fib(n - 1)

fib(5)
```
mdoc --in main.template.md --out main.mdoc.md
info: Compiling 1 file to main.mdoc.md
error: main.template.md:5:1: `{` expected but `case` found
case 1 => 1
^^^^
info: Compiled in 0.2s (1 error)

Can I modify Scala version from CLI?

Of course, creating entire project to compiling just one source code is such a pain...

windymelt avatar Oct 22 '24 09:10 windymelt

Looks like we never added the option, we were mostly focused on sbt and worksheets. It should not be hard to add though.

tgodzik avatar Oct 22 '24 10:10 tgodzik

this feature would be very useful, I'm writing scala 3 documentation for ZIO and wasn't able to type check scala 3 snippets.

scarf005 avatar Dec 27 '24 14:12 scarf005

this feature would be very useful, I'm writing scala 3 documentation for ZIO and wasn't able to type check scala 3 snippets.

Is that done with sbt or CLI indeed?

tgodzik avatar Dec 27 '24 15:12 tgodzik

i used sbt generateReadme.

scarf005 avatar Dec 27 '24 16:12 scarf005

Actually, this seems to work for the CLI, but it's important to install the right mdoc version. We publish cli for both Scala 2 and 3.

image

For sbt I think the docs module must be Scala 3 or cross compiled, since mdoc_3 will only compile Scala 3

tgodzik avatar Dec 27 '24 16:12 tgodzik