Skip to content

Commit a0cbf63

Browse files
committed
doc: Switch the tutorial to pandoc's method of tagging code blocks
Instead of '## tag', it's '~~~ {.tag}'
1 parent 237cd44 commit a0cbf63

File tree

3 files changed

+25
-43
lines changed

3 files changed

+25
-43
lines changed

doc/prep.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ var out = outfile ? fs.createWriteStream(outfile) : process.stdout;
3939

4040
while ((line = lines[cur++]) != null) {
4141
if (/^~~~/.test(line)) {
42-
var block = "", bline, isRust = true;
42+
var block = "", bline;
43+
var isRust = !/notrust/.test(line);
4344
while ((bline = lines[cur++]) != null) {
44-
if (/^\s*## notrust/.test(bline)) isRust = false;
45-
else if (/^~~~/.test(bline)) break;
45+
if (/^~~~/.test(bline)) break;
4646
if (!/^\s*##? /.test(bline)) block += bline + "\n";
4747
}
4848
if (!highlight || !isRust)

doc/tutorial.md

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ prerequisites, something along these lines should work. Building from source on
9696
Windows requires some extra steps: please see the
9797
[getting started][wiki-get-started] page on the Rust wiki.
9898

99-
~~~~
100-
## notrust
99+
~~~~ {.notrust}
101100
$ wget http://dl.rust-lang.org/dist/rust-0.1.tar.gz
102101
$ tar -xzf rust-0.1.tar.gz
103102
$ cd rust-0.1
@@ -144,8 +143,7 @@ If you modify the program to make it invalid (for example, change the
144143
function to an unknown name), and then compile it, you'll see an error
145144
message like this:
146145

147-
~~~~
148-
## notrust
146+
~~~~ {.notrust}
149147
hello.rs:2:4: 2:16 error: unresolved name: io::print_it
150148
hello.rs:2 io::print_it("hello world from '" + args[0] + "'!");
151149
^~~~~~~~~~~~
@@ -511,8 +509,7 @@ BSD-style license). Finally, you can have a name followed by a
511509
comma-separated list of nested attributes, as in the `cfg` example
512510
above, or in this [crate](#modules-and-crates) metadata declaration:
513511

514-
~~~~
515-
## ignore
512+
~~~~ {.ignore}
516513
#[link(name = "std",
517514
vers = "0.1",
518515
url = "http://rust-lang.org/src/std")];
@@ -1595,8 +1592,7 @@ parameter `T`, can you copy values of that type? In Rust, you can't,
15951592
unless you explicitly declare that type parameter to have copyable
15961593
'kind'. A kind is a type of type.
15971594

1598-
~~~~
1599-
## ignore
1595+
~~~~ {.ignore}
16001596
// This does not compile
16011597
fn head_bad<T>(v: [T]) -> T { v[0] }
16021598
// This does
@@ -1687,8 +1683,7 @@ It is also possible to include multiple files in a crate. For this
16871683
purpose, you create a `.rc` crate file, which references any number of
16881684
`.rs` code files. A crate file could look like this:
16891685

1690-
~~~~
1691-
## ignore
1686+
~~~~ {.ignore}
16921687
#[link(name = "farm", vers = "2.5", author = "mjh")];
16931688
mod cow;
16941689
mod chicken;
@@ -1707,8 +1702,7 @@ later.
17071702
To have a nested directory structure for your source files, you can
17081703
nest mods in your `.rc` file:
17091704

1710-
~~~~
1711-
## ignore
1705+
~~~~ {.ignore}
17121706
mod poultry {
17131707
mod chicken;
17141708
mod turkey;
@@ -1736,8 +1730,7 @@ crate library with the right name.
17361730
It is possible to provide more specific information when using an
17371731
external crate.
17381732

1739-
~~~~
1740-
## ignore
1733+
~~~~ {.ignore}
17411734
use myfarm (name = "farm", vers = "2.7");
17421735
~~~~
17431736

@@ -1750,8 +1743,7 @@ local name `myfarm`.
17501743

17511744
Our example crate declared this set of `link` attributes:
17521745

1753-
~~~~
1754-
## ignore
1746+
~~~~ {.ignore}
17551747
#[link(name = "farm", vers = "2.5", author = "mjh")];
17561748
~~~~
17571749

@@ -1780,8 +1772,7 @@ these two files:
17801772
fn world() -> str { "world" }
17811773
~~~~
17821774

1783-
~~~~
1784-
## ignore
1775+
~~~~ {.ignore}
17851776
// main.rs
17861777
use std;
17871778
use mylib;
@@ -1790,8 +1781,7 @@ fn main() { io::println("hello " + mylib::world()); }
17901781

17911782
Now compile and run like this (adjust to your platform if necessary):
17921783

1793-
~~~~
1794-
## notrust
1784+
~~~~ {.notrust}
17951785
> rustc --lib mylib.rs
17961786
> rustc main.rs -L .
17971787
> ./main
@@ -2133,8 +2123,7 @@ hash of its first command-line argument, which it then converts to a
21332123
hexadecimal string and prints to standard output. If you have the
21342124
OpenSSL libraries installed, it should 'just work'.
21352125

2136-
~~~~
2137-
## xfail-test
2126+
~~~~ {.xfail-test}
21382127
use std;
21392128
21402129
native mod crypto {
@@ -2164,8 +2153,7 @@ fn main(args: [str]) {
21642153
Before we can call `SHA1`, we have to declare it. That is what this
21652154
part of the program is responsible for:
21662155

2167-
~~~~
2168-
## xfail-test
2156+
~~~~ {.xfail-test}
21692157
native mod crypto {
21702158
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
21712159
}
@@ -2180,8 +2168,7 @@ in a platform-specific way (`libcrypto.so` on Linux, for example), and
21802168
link that in. If you want the module to have a different name from the
21812169
actual library, you can use the `"link_name"` attribute, like:
21822170

2183-
~~~~
2184-
## xfail-test
2171+
~~~~ {.xfail-test}
21852172
#[link_name = "crypto"]
21862173
native mod something {
21872174
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
@@ -2213,8 +2200,7 @@ or `"stdcall"`. Other conventions may be defined in the future.
22132200
The native `SHA1` function is declared to take three arguments, and
22142201
return a pointer.
22152202

2216-
~~~~
2217-
## xfail-test
2203+
~~~~ {.xfail-test}
22182204
# native mod crypto {
22192205
fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8;
22202206
# }
@@ -2547,8 +2533,7 @@ When you compile the program normally, the `test_twice` function will
25472533
not be included. To compile and run such tests, compile with the
25482534
`--test` flag, and then run the result:
25492535

2550-
~~~~
2551-
## notrust
2536+
~~~~ {.notrust}
25522537
> rustc --test twice.rs
25532538
> ./twice
25542539
running 1 tests
@@ -2559,8 +2544,7 @@ result: ok. 1 passed; 0 failed; 0 ignored
25592544
Or, if we change the file to fail, for example by replacing `x + x`
25602545
with `x + 1`:
25612546

2562-
~~~~
2563-
## notrust
2547+
~~~~ {.notrust}
25642548
running 1 tests
25652549
test test_twice ... FAILED
25662550
failures:

src/etc/extract-tests.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@
2929
chapter = re.sub(r"\W", "_", chap.group(1)).lower()
3030
chapter_n = 1
3131
elif re.match("~~~", line):
32+
# Parse the tags that open a code block in the pandoc format:
33+
# ~~~ {.tag1 .tag2}
34+
tags = re.findall("\.([\w-]*)", line)
3235
block = ""
33-
ignore = False
34-
xfail = False
36+
ignore = "notrust" in tags or "ignore" in tags
37+
xfail = "xfail-test" in tags
3538
while cur < len(lines):
3639
line = lines[cur]
3740
cur += 1
38-
if re.match(r"\s*## (notrust|ignore)", line):
39-
ignore = True
40-
elif re.match(r"\s*## xfail-test", line):
41-
xfail = True
42-
elif re.match("~~~", line):
41+
if re.match("~~~", line):
4342
break
4443
else:
4544
block += re.sub("^# ", "", line)
@@ -60,4 +59,3 @@
6059
f = open(filename, 'w')
6160
f.write(block)
6261
f.close()
63-

0 commit comments

Comments
 (0)