Skip to content

Commit 5ea846c

Browse files
committed
Create mdbook-spec main.rs.
Switching most of the code to a library to support rustbook upstream.
1 parent 58df571 commit 5ea846c

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

mdbook-spec/src/lib.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use semver::{Version, VersionReq};
88
use std::collections::BTreeMap;
99
use std::io;
1010
use std::path::PathBuf;
11-
use std::process;
1211

1312
mod std_links;
1413

@@ -21,29 +20,7 @@ static ADMONITION_RE: Lazy<Regex> = Lazy::new(|| {
2120
Regex::new(r"(?m)^ *> \[!(?<admon>[^]]+)\]\n(?<blockquote>(?: *> .*\n)+)").unwrap()
2221
});
2322

24-
fn main() {
25-
let mut args = std::env::args().skip(1);
26-
match args.next().as_deref() {
27-
Some("supports") => {
28-
// Supports all renderers.
29-
return;
30-
}
31-
Some(arg) => {
32-
eprintln!("unknown argument: {arg}");
33-
std::process::exit(1);
34-
}
35-
None => {}
36-
}
37-
38-
let preprocessor = Spec::new();
39-
40-
if let Err(e) = handle_preprocessing(&preprocessor) {
41-
eprintln!("{}", e);
42-
process::exit(1);
43-
}
44-
}
45-
46-
fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
23+
pub fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
4724
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
4825

4926
let book_version = Version::parse(&ctx.mdbook_version)?;
@@ -65,7 +42,7 @@ fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
6542
Ok(())
6643
}
6744

68-
struct Spec {
45+
pub struct Spec {
6946
/// Whether or not warnings should be errors (set by SPEC_DENY_WARNINGS
7047
/// environment variable).
7148
deny_warnings: bool,

mdbook-spec/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fn main() {
2+
let mut args = std::env::args().skip(1);
3+
match args.next().as_deref() {
4+
Some("supports") => {
5+
// Supports all renderers.
6+
return;
7+
}
8+
Some(arg) => {
9+
eprintln!("unknown argument: {arg}");
10+
std::process::exit(1);
11+
}
12+
None => {}
13+
}
14+
15+
let preprocessor = mdbook_spec::Spec::new();
16+
17+
if let Err(e) = mdbook_spec::handle_preprocessing(&preprocessor) {
18+
eprintln!("{}", e);
19+
std::process::exit(1);
20+
}
21+
}

0 commit comments

Comments
 (0)