]>
git.proxmox.com Git - rustc.git/blob - src/doc/book/tools/src/bin/remove_markup.rs
3 use regex
::{Captures, Regex}
;
5 use std
::io
::{Read, Write}
;
8 write_md(remove_markup(read_md()));
11 fn read_md() -> String
{
12 let mut buffer
= String
::new();
13 match io
::stdin().read_to_string(&mut buffer
) {
15 Err(error
) => panic
!("{}", error
),
19 fn write_md(output
: String
) {
20 write
!(io
::stdout(), "{}", output
).unwrap();
23 fn remove_markup(input
: String
) -> String
{
25 Regex
::new(r
#"\A<span class="filename">(.*)</span>\z"#).unwrap();
26 // Captions sometimes take up multiple lines.
27 let caption_start_regex
=
28 Regex
::new(r
#"\A<span class="caption">(.*)\z"#).unwrap();
29 let caption_end_regex
= Regex
::new(r
#"(.*)</span>\z"#).unwrap();
30 let regexen
= vec
![filename_regex
, caption_start_regex
, caption_end_regex
];
32 let lines
: Vec
<_
> = input
35 // Remove our syntax highlighting and rustdoc markers.
36 if line
.starts_with("```") {
37 Some(String
::from("```"))
38 // Remove the span around filenames and captions.
41 regexen
.iter().fold(line
.to_string(), |result
, regex
| {
43 .replace_all(&result
, |caps
: &Captures
<'_
>| {
44 caps
.get(1).unwrap().as_str().to_string()