Have mdBook not wrap code snippets in "fn main() {}"

I noticed that when I tried to copy a code snippet into the clipboard
that it had some extra code text that I didn't see on the webpage. It
had wrapped the code snippet in a "fn main()" declaration. The code
window on the page also contained arrows in the upper-right corner for
expanding the code so that this hidden declaration could be seen. These
snippets aren't meant to be working samples so treating them as code to
be contained in main() often doesn't make sense. Changing the language
from "rust" to "rust,ignore" on these snippets causes mdBook to not
perform this wrapping.

For example before the following would be copied to clipboard:
```rust
fn main() {
// Exception handler for the SysTick (System Timer) exception
fn SysTick() {
    // ..
}
}
```

After this change, we get the following copied to the clipboard:
```rust
// Exception handler for the SysTick (System Timer) exception
fn SysTick() {
    // ..
}
```
This commit is contained in:
Adam Green
2018-11-16 23:44:23 -08:00
parent 20b30525b0
commit c5caa3b72d
3 changed files with 9 additions and 9 deletions

View File

@@ -10,7 +10,7 @@ handlers.
[`exception`]: https://rust-embedded.github.io/cortex-m-rt/0.6.1/cortex_m_rt_macros/fn.exception.html
``` rust
``` rust,ignore
// Exception handler for the SysTick (System Timer) exception
#[exception]
fn SysTick() {
@@ -26,7 +26,7 @@ would result in a compilation error.
This behavior is pretty much intended and it's required to provide a feature:
`static mut` variables declared *inside* `exception` handlers are *safe* to use.
``` rust
``` rust,ignore
#[exception]
fn SysTick() {
static mut COUNT: u32 = 0;
@@ -141,7 +141,7 @@ handler for a specific exception. If you don't override the handler for a
particular exception it will be handled by the `DefaultHandler` function, which
defaults to:
``` rust
``` rust,ignore
fn DefaultHandler() {
loop {}
}
@@ -153,7 +153,7 @@ This function is provided by the `cortex-m-rt` crate and marked as
It's possible to override this `DefaultHandler` using the `exception` attribute:
``` rust
``` rust,ignore
#[exception]
fn DefaultHandler(irqn: i16) {
// custom default handler

View File

@@ -45,7 +45,7 @@ an application as a single line of code is not only useful as documentation but
can also be used to change the panicking behavior according to the compilation
profile. For example:
``` rust
``` rust,ignore
#![no_main]
#![no_std]

View File

@@ -46,7 +46,7 @@ The functions on the `SYST` struct map pretty closely to the functionality defin
We won't get very far with our embedded software development if we restrict ourselves to only the basic peripherals included with every Cortex-M. At some point, we're going to need to write some code that's specific to the particular micro-controller we're using. In this example, let's assume we have an Texas Instruments TM4C123 - a middling 80MHz Cortex-M4 with 256 KiB of Flash. We're going to pull in the [tm4c123x] crate to make use of this chip.
```rust
```rust,ignore
#![no_std]
#![no_main]
@@ -79,7 +79,7 @@ We've accessed the `PWM0` peripheral in exactly the same way as we accessed the
The `read()` function returns an object which gives read-only access to the various sub-fields within this register, as defined by the manufacturer's SVD file for this chip. You can find all the functions available on special `R` return type for this particular register, in this particular peripheral, on this particular chip, in the [tm4c123x documentation][tm4c123x documentation R].
```rust
```rust,ignore
if pwm.ctl.read().globalsync0().is_set() {
// Do a thing
}
@@ -89,7 +89,7 @@ if pwm.ctl.read().globalsync0().is_set() {
The `write()` function takes a closure with a single argument. Typically we call this `w`. This argument then gives read-write access to the various sub-fields within this register, as defined by the manufacturer's SVD file for this chip. Again, you can find all the functions available on the 'w' for this particular register, in this particular peripheral, on this particular chip, in the [tm4c123x documentation][tm4c123x Documentation W]. Note that all of the sub-fields that we do not set will be set to a default value for us - any existing content in the register will be lost.
```rust
```rust,ignore
pwm.ctl.write(|w| w.globalsync0().clear_bit());
```
@@ -97,7 +97,7 @@ pwm.ctl.write(|w| w.globalsync0().clear_bit());
If we wish to change only one particular sub-field in this register and leave the other sub-fields unchanged, we can use the `modify` function. This function takes a closure with two arguments - one for reading and one for writing. Typically we call these `r` and `w` respectively. The `r` argument can be used to inspect the current contents of the register, and the `w` argument can be used to modify the register contents.
```rust
```rust,ignore
pwm.ctl.modify(|r, w| w.globalsync0().clear_bit());
```