Tue, 06 Dec 2022 14:12:20 +0200
v1.0.0-pre-arxiv (missing arXiv links)
6
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | use std::env; |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | use regex::{Regex, Captures}; |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | fn proc<A : AsRef<str>>(re : &str, str : A) -> String { |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | let need_to_escape = Regex::new(r"([_*\\])").unwrap(); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | Regex::new(re).unwrap().replace_all(str.as_ref(), |caps : &Captures| { |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | format!("{}{}{}", |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | caps.get(1).unwrap().as_str(), |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | need_to_escape.replace_all(caps.get(2).unwrap().as_str(), "\\$1"), |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
10 | caps.get(3).unwrap().as_str() |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
11 | ) |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | }).to_string() |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | } |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | fn main() { |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
16 | let out_dir = env::var("OUT_DIR").unwrap(); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | // Since rust is stuck in 80's 7-bit gringo ASCII world, so that rustdoc does not support |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | // markdown KaTeX mathematics, we have to process the README to include horrible horrible |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | // horrible escapes for the math, and then use an vomit-inducingly ugly javasccript |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | // workaround to process the math on the fly. |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | println!("cargo:rerun-if-changed=README.md"); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | let readme = std::fs::read_to_string("README.md") |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | .expect("Error reading README"); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | // Escape _, *, and \ in equations. |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | let readme_uglified = proc(r"(?m)([^$]\$)([^$]+)(\$[^$])", |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | proc(r"([^$]\$\$)([^$]+)(\$\$[^$])", readme)); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | // Remove the instructions for building the documentation |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | let readme_cut = Regex::new("## Internals(.*|\n)*") |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | .unwrap() |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | .replace_all(&readme_uglified, ""); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | std::fs::write(out_dir + "/README_uglified.md", readme_cut.as_bytes()) |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | .expect("Error saving uglified README"); |
bcb508479948
README fine-tuning and build.rs for uglifying it for rustdoc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | } |