| |
1 use regex::{Captures, Regex}; |
| 1 use std::env; |
2 use std::env; |
| 2 use regex::{Regex, Captures}; |
|
| 3 |
3 |
| 4 fn proc<A : AsRef<str>>(re : &str, str : A) -> String { |
4 fn main() { |
| 5 let need_to_escape = Regex::new(r"([_*\\])").unwrap(); |
5 process_readme(); |
| 6 Regex::new(re).unwrap().replace_all(str.as_ref(), |caps : &Captures| { |
6 // Does not seem to be needed now. |
| 7 format!("{}{}{}", |
7 //discover_gsl(); |
| 8 caps.get(1).unwrap().as_str(), |
|
| 9 need_to_escape.replace_all(caps.get(2).unwrap().as_str(), "\\$1"), |
|
| 10 caps.get(3).unwrap().as_str() |
|
| 11 ) |
|
| 12 }).to_string() |
|
| 13 } |
8 } |
| 14 |
9 |
| 15 fn main() { |
10 /* |
| |
11 /// Discover how to link to gsl, as the gsl crate does not provide this information |
| |
12 fn discover_gsl() { |
| |
13 pkg_config::Config::new().probe("gsl").unwrap(); |
| |
14 } |
| |
15 */ |
| |
16 |
| |
17 /// `\`-escape `_`, `*`, and ยด\\` in matches of `re` within `str`. |
| |
18 fn proc<A: AsRef<str>>(re: &str, str: A) -> String { |
| |
19 let need_to_escape = Regex::new(r"([_*\\])").unwrap(); |
| |
20 Regex::new(re) |
| |
21 .unwrap() |
| |
22 .replace_all(str.as_ref(), |caps: &Captures| { |
| |
23 format!( |
| |
24 "{}{}{}", |
| |
25 caps.get(1).unwrap().as_str(), |
| |
26 need_to_escape.replace_all(caps.get(2).unwrap().as_str(), "\\$1"), |
| |
27 caps.get(3).unwrap().as_str() |
| |
28 ) |
| |
29 }) |
| |
30 .to_string() |
| |
31 } |
| |
32 |
| |
33 /// Process the README for inclusion in documentation |
| |
34 fn process_readme() { |
| 16 let out_dir = env::var("OUT_DIR").unwrap(); |
35 let out_dir = env::var("OUT_DIR").unwrap(); |
| 17 |
36 |
| 18 // Since rust is stuck in 80's 7-bit gringo ASCII world, so that rustdoc does not support |
37 // Since rust is stuck in 80's 7-bit gringo ASCII world, so that rustdoc does not support |
| 19 // markdown KaTeX mathematics, we have to process the README to include horrible horrible |
38 // markdown KaTeX mathematics, we have to process the README to include horrible horrible |
| 20 // horrible escapes for the math, and then use an vomit-inducingly ugly javasccript |
39 // horrible escapes for the math, and then use an vomit-inducingly ugly javasccript |
| 21 // workaround to process the math on the fly. |
40 // workaround to process the math on the fly. |
| 22 |
41 |
| 23 println!("cargo:rerun-if-changed=README.md"); |
42 println!("cargo:rerun-if-changed=README.md"); |
| 24 |
43 |
| 25 let readme = std::fs::read_to_string("README.md") |
44 let readme = std::fs::read_to_string("README.md").expect("Error reading README"); |
| 26 .expect("Error reading README"); |
|
| 27 |
45 |
| 28 // Escape _, *, and \ in equations. |
46 // Escape _, *, and \ in equations. |
| 29 let readme_uglified = proc(r"(?m)([^$]\$)([^$]+)(\$[^$])", |
47 let readme_uglified = proc( |
| 30 proc(r"([^$]\$\$)([^$]+)(\$\$[^$])", readme)); |
48 r"(?m)([^$]\$)([^$]+)(\$[^$])", |
| |
49 proc(r"([^$]\$\$)([^$]+)(\$\$[^$])", readme), |
| |
50 ); |
| 31 // Remove the instructions for building the documentation |
51 // Remove the instructions for building the documentation |
| 32 let readme_cut = Regex::new("## Internals(.*|\n)*") |
52 let readme_cut = Regex::new("## Internals(.*|\n)*") |
| 33 .unwrap() |
53 .unwrap() |
| 34 .replace_all(&readme_uglified, ""); |
54 .replace_all(&readme_uglified, ""); |
| 35 |
55 |