Struct mdbook_cmdrun::cmdrun::CmdRun
source · pub struct CmdRun;Implementations§
source§impl CmdRun
impl CmdRun
sourcepub fn run_on_content(content: &str, working_dir: &str) -> Result<String>
pub fn run_on_content(content: &str, working_dir: &str) -> Result<String>
Examples found in repository?
src/cmdrun.rs (line 50)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn run_on_chapter(chapter: &mut Chapter) -> Result<()> {
let working_dir = match &chapter.path {
None => String::new(),
Some(pathbuf) => {
let pathbuf = Path::new("src").join(pathbuf);
match pathbuf.parent() {
None => String::new(),
Some(parent) => match parent.to_str() {
None => String::new(),
Some(s) => String::from(s),
},
}
}
};
chapter.content = CmdRun::run_on_content(&chapter.content, &working_dir)?;
Ok(())
}sourcepub fn run_cmdrun(command: String, working_dir: &str) -> Result<String>
pub fn run_cmdrun(command: String, working_dir: &str) -> Result<String>
Examples found in repository?
src/cmdrun.rs (line 62)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
pub fn run_on_content(content: &str, working_dir: &str) -> Result<String> {
let re = Regex::new(r"<!--[ ]*cmdrun (.*)-->\n").unwrap();
let mut err = None;
let content = re
.replace_all(content, |caps: &Captures| {
match CmdRun::run_cmdrun(caps[1].to_string(), working_dir) {
Ok(s) => s,
Err(e) => {
err = Some(e);
String::new()
}
}
})
.to_string();
match err {
None => Ok(content),
Some(err) => Err(err),
}
}