Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for ignore keyword in snippets in md #2898

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions website/docs/guides/power/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,46 @@ world

</ChainedSnippets>

### `ignore` in `scala` snippets

You can mark a `scala` code block with the `ignore` keyword, indicating that this snippet should not be run. This block will be ignored completely and will not be compiled or executed.

Below is an example of an `.md` file with an ignored `scala` snippet:

````markdown title=IgnoreExample.md
# `ignore` example
## Normal snippet
```scala
val message = "Hello world!"
println(message)
```

## Ignored snippet
```scala ignore
val message = "This must be ignored"
println(message)
1 / 0
```

````

<ChainedSnippets>

```bash
scala-cli --power IgnoreExample.md
```

We see output only from the `scala` snippet:

```text
Hello world!
```

</ChainedSnippets>

After execution of the above example, you can see that the ignored snippet was not run.
All errors and exceptions that would have been thrown by the `ignore` snippet are also absent.

## `shebang` header and Markdown code blocks
The `shebang` line in `scala` code blocks inside a markdown input are always ignored.
You can use them (i.e. to give an example of their usage), but they do not change how the code is handled.
Expand Down
Loading