Skip to content

Commit e3ad47e

Browse files
committed
Ensure Markdown examples in the docs are being tested by sclicheck
1 parent bb09330 commit e3ad47e

File tree

1 file changed

+55
-33
lines changed

1 file changed

+55
-33
lines changed

website/docs/guides/markdown.md

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ You can enable including non-explicit `.md` inputs by passing the `--enable-mark
1919

2020
You can pass local `.md` inputs by passing their path to Scala CLI (as you would for any other kind of input).
2121

22-
```bash ignore
23-
scala-cli hello.md
22+
````markdown title=dir/hello.md
23+
# Simple snippet
24+
```scala
25+
println("Hello")
26+
```
27+
````
28+
29+
```bash
30+
scala-cli dir/hello.md
2431
```
2532

2633
`.md` sources inside of directories are ignored by default, unless the `--enable-markdown` option is passed.
2734

28-
```bash ignore
29-
scala-cli dir-with-markdown --enable-markdown
35+
```bash
36+
scala-cli dir --enable-markdown
3037
```
3138

3239
### Zipped archives
@@ -147,7 +154,7 @@ top-level.
147154

148155
<ChainedSnippets>
149156

150-
```bash ignore
157+
```bash
151158
scala-cli run Example.md
152159
```
153160

@@ -160,14 +167,29 @@ Hello from Markdown
160167
Similarly to `.sc` scripts, when multiple `.md` files with plain `scala` snippets are being run, each of them will have
161168
its own main class, that can be run.
162169

170+
````markdown title=Main1.md
171+
# Main class 1
172+
```scala
173+
println("1")
174+
```
175+
````
176+
177+
178+
````markdown title=Main2.md
179+
# Main class 2
180+
```scala
181+
println("2")
182+
```
183+
````
184+
163185
<ChainedSnippets>
164186

165-
```bash ignore
166-
scala-cli Example1.md Example2.md
187+
```bash fail
188+
scala-cli Main1.md Main2.md
167189
```
168190

169191
```text
170-
[error] Found several main classes: Example1_md, Example2_md
192+
[error] Found several main classes: Main1_md, Main2_md
171193
```
172194

173195
</ChainedSnippets>
@@ -177,12 +199,12 @@ option.
177199

178200
<ChainedSnippets>
179201

180-
```bash ignore
181-
scala-cli Example1.md Example2.md --main-class Example1_md
202+
```bash
203+
scala-cli Main1.md Main2.md --main-class Main1_md
182204
```
183205

184206
```text
185-
Hello from Markdown
207+
1
186208
```
187209

188210
</ChainedSnippets>
@@ -191,12 +213,12 @@ You can always check what main classes are available in the context with the `--
191213

192214
<ChainedSnippets>
193215

194-
```bash ignore
195-
scala-cli Example1.md Example2.md --list-main-classes
216+
```bash
217+
scala-cli Main1.md Main2.md --list-main-classes
196218
```
197219

198220
```text
199-
Example1_md Example2_md
221+
Main1_md Main2_md
200222
```
201223

202224
</ChainedSnippets>
@@ -222,7 +244,7 @@ object Main extends App {
222244

223245
<ChainedSnippets>
224246

225-
```bash ignore
247+
```bash
226248
scala-cli RawExample.md
227249
```
228250

@@ -255,7 +277,7 @@ class Test extends munit.FunSuite {
255277

256278
<ChainedSnippets>
257279

258-
```bash ignore
280+
```bash
259281
scala-cli test TestExample.md
260282
```
261283

@@ -303,8 +325,8 @@ println(message)
303325

304326
<ChainedSnippets>
305327

306-
```bash ignore
307-
scala-cli test ResetExample.md
328+
```bash
329+
scala-cli ResetExample.md
308330
```
309331

310332
```text
@@ -315,12 +337,12 @@ world
315337

316338
</ChainedSnippets>
317339

318-
## `using` directives and markdown code blocks
340+
## `using` directives and Markdown code blocks
319341

320342
It is possible to define `using` directives at the beginning of a `scala` code block inside a markdown input.
321343
This is supported for all `scala` code block flavours.
322344

323-
````markdown title=UsingDirectives.md
345+
````markdown compile title=UsingDirectives.md
324346
# Using directives in `.md` inputs
325347

326348
## `scala raw` example
@@ -339,7 +361,7 @@ println(os.pwd)
339361

340362
## `scala test` example
341363
```scala test
342-
//> using lib "org.scalameta::munit:0.7.29"
364+
//> using lib "org.scalameta::munit:1.0.0-M7"
343365

344366
class Test extends munit.FunSuite {
345367
test("foo") {
@@ -362,7 +384,7 @@ pprint.pprintln("world")
362384
`scala` snippets inside of a Markdown input are not isolated. Each `using` directive applies to the whole project's
363385
context. A directive defined in a later snippet within the same source may override another defined in an earlier one.
364386

365-
````markdown title="OverriddenDirective.md"
387+
````markdown title=OverriddenDirective.md
366388
## 1
367389

368390
```scala
@@ -383,7 +405,7 @@ be used for both.
383405

384406
<ChainedSnippets>
385407

386-
```bash ignore
408+
```bash
387409
scala-cli OverriddenDirective.md
388410
```
389411

@@ -411,35 +433,35 @@ snippet): `Scope{scopeNumber}`. The `snippetNumber` is omitted for the first scr
411433
the first scope is just `Scope`, the second is `Scope1`, then `Scope2` and so on.
412434

413435
````markdown title=src/markdown/Example.md
414-
## Scope 1
436+
## Scope 0
415437
```scala
416438
def hello: String = "Hello"
417439
```
418440

419-
## Still scope 1, since `reset` wasn't used yet
441+
## Still scope 0, since `reset` wasn't used yet
420442
```scala
421443
def space: String = " "
422444
```
423445

424-
## Scope 2
446+
## Scope 1
425447
```scala reset
426448
def world: String = "world"
427449
```
428450
````
429451

430452
```scala title=Main.scala
431453
object Main extends App {
432-
val hello = src.markdown.Example_md.Scope.hello
433-
val space = src.markdown.Example_md.Scope.space
434-
val world = src.markdown.Example_md.Scope.world
435-
println(s"$hello$space$world)
454+
val hello = markdown.Example_md.Scope.hello
455+
val space = markdown.Example_md.Scope.space
456+
val world = markdown.Example_md.Scope1.world
457+
println(s"$hello$space$world")
436458
}
437459
```
438460

439461
<ChainedSnippets>
440462

441-
```bash ignore
442-
scala-cli . --enable-markdown --main-class Main
463+
```bash
464+
scala-cli src Main.scala --enable-markdown --main-class Main
443465
```
444466

445467
```text
@@ -463,7 +485,7 @@ object Something {
463485

464486
<ChainedSnippets>
465487

466-
```bash ignore
488+
```bash
467489
scala-cli RawSnippetToReferTo.md -e 'println(Something.message)'
468490
```
469491

0 commit comments

Comments
 (0)