From bb0c878e06b82d1f8dc4fe6910ae66639739b59a Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Fri, 1 Jan 2016 01:57:21 +0100 Subject: [PATCH] #29 update doc with an example of runnable rust code --- book-example/src/SUMMARY.md | 1 + book-example/src/format/example.rs | 6 +++++ book-example/src/format/rust.md | 42 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 book-example/src/format/example.rs create mode 100644 book-example/src/format/rust.md diff --git a/book-example/src/SUMMARY.md b/book-example/src/SUMMARY.md index d3e5172f..560e2f8b 100644 --- a/book-example/src/SUMMARY.md +++ b/book-example/src/SUMMARY.md @@ -13,6 +13,7 @@ - [index.hbs](format/theme/index-hbs.md) - [Syntax highlighting](format/theme/syntax-highlighting.md) - [MathJax Support](format/mathjax.md) + - [Rust code specific features](format/rust.md) - [Rust Library](lib/lib.md) ----------- [Contributors](misc/contributors.md) diff --git a/book-example/src/format/example.rs b/book-example/src/format/example.rs new file mode 100644 index 00000000..6b49705c --- /dev/null +++ b/book-example/src/format/example.rs @@ -0,0 +1,6 @@ +fn main() { + println!("Hello World!"); +# +# // You can even hide lines! :D +# println!("I am hidden! Expand the code snippet to see me"); +} diff --git a/book-example/src/format/rust.md b/book-example/src/format/rust.md new file mode 100644 index 00000000..0129bac7 --- /dev/null +++ b/book-example/src/format/rust.md @@ -0,0 +1,42 @@ +# Rust code specific features + +## Hiding code lines + +There is a feature in mdBook that let's you hide code lines by prepending them with a `#`. + +```bash +#fn main() { + let x = 5; + let y = 6; + + println!("{}", x + y); +#} +``` + +Will render as + +```rust +#fn main() { + let x = 5; + let y = 7; + + println!("{}", x + y); +#} +``` + + +## Inserting runnable Rust files + +With the following syntax, you can insert runnable Rust files into your book: + +```hbs +\{{#playpen file.rs}} +``` + +The path to the Rust file has to be relative from the current source file. + +When play is clicked, the code snippet will be send to the [Rust Playpen]() to be compiled and run. The result is send back and displayed directly underneath the code. + +Here is what a rendered code snippet looks like: + +{{#playpen example.rs}}