Skip to content

Commit

Permalink
rust fmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blandger committed Aug 18, 2024
1 parent 69be4a3 commit 56051be
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl MDBook {
pub fn clone_preprocessors(&self) -> Vec<Box<dyn Preprocessor>> {
self.preprocessors.clone()
}
}
}

/// Look at the `Config` and try to figure out what renderers to use.
fn determine_renderers(config: &Config) -> Vec<Box<dyn Renderer>> {
Expand Down
31 changes: 26 additions & 5 deletions src/preprocess/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ impl Preprocessor for LinkPreprocessor {
let mut chapter_title = ch.name.clone();
// run normal link replacement by all content with 'dashed' lines inside present
let content = replace_all(
&ch.content, base, chapter_path, 0, &mut chapter_title, false);
&ch.content,
base,
chapter_path,
0,
&mut chapter_title,
false,
);
ch.content = content;
if chapter_title != ch.name {
ctx.chapter_titles
Expand Down Expand Up @@ -91,7 +97,13 @@ impl Preprocessor for LinkPreprocessor {
// by lined content with removing # dashed lines
let mut chapter_title:String = chapter.name.clone();
let updated_content = replace_all(
&chapter.content.clone(), base, chapter_path, 0, chapter_title.as_mut_string(), true);
&chapter.content.clone(),
base,
chapter_path,
0,
chapter_title.as_mut_string(),
true,
);
trace!("updated_content = {:?}", updated_content.len());
chapter.content = updated_content;
}
Expand Down Expand Up @@ -479,7 +491,10 @@ mod tests {
{{#include file.rs}} << an escaped link!
```";
let mut chapter_title = "test_replace_all_escaped".to_owned();
assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, false), end);
assert_eq!(
replace_all(start, "", "", 0, &mut chapter_title, false),
end
);
}


Expand Down Expand Up @@ -510,7 +525,10 @@ mod tests {
{{#include file.rs}} << an escaped link!
```";
let mut chapter_title = "test_replace_all_escaped_with_cutoff".to_owned();
assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, false), end);
assert_eq!(
replace_all(start, "", "", 0, &mut chapter_title, false),
end
);
}

#[test]
Expand All @@ -522,7 +540,10 @@ mod tests {
# My Chapter
";
let mut chapter_title = "test_set_chapter_title".to_owned();
assert_eq!(replace_all(start, "", "", 0, &mut chapter_title, false), end);
assert_eq!(
replace_all(start, "", "", 0, &mut chapter_title, false),
end
);
assert_eq!(chapter_title, "My Title");
}

Expand Down
5 changes: 4 additions & 1 deletion src/preprocess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ pub trait Preprocessor: PreprocessorClone {

/// Pre-Process only one mutable chapter using context and supplied pre-processor
fn preprocess_chapter(&self, ctx: &PreprocessorContext, chapter: &mut Chapter) -> Result<()> {
println!("preprocess chapter: '{}' by ctx = {}", chapter.name, ctx.renderer);
println!(
"preprocess chapter: '{}' by ctx = {}",
chapter.name, ctx.renderer
);
Ok(())
}

Expand Down
18 changes: 14 additions & 4 deletions src/utils/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@ pub fn take_anchored_lines(s: &str, anchor: &str) -> String {
/// For any lines not in the range, include them but use `#` at the beginning. This will hide the
/// lines from initial display but include them when expanding the code snippet or testing with
/// rustdoc.
pub fn take_rustdoc_include_lines<R: RangeBounds<usize>>(s: &str, range: R, cutoff_commented_lines: bool) -> String {
pub fn take_rustdoc_include_lines<R: RangeBounds<usize>>(
s: &str,
range: R,
cutoff_commented_lines: bool,
) -> String {
let mut output = String::with_capacity(s.len());

for (index, line) in s.lines().enumerate() {
if !range.contains(&index) {
if !cutoff_commented_lines { // do not include 'dashed' lines (for epub format)
if !cutoff_commented_lines {
// do not include 'dashed' lines (for epub format)
output.push_str("# ");
}
}
Expand All @@ -84,7 +89,11 @@ pub fn take_rustdoc_include_lines<R: RangeBounds<usize>>(s: &str, range: R, cuto
/// For any lines not between the anchors, include them but use `#` at the beginning. This will
/// hide the lines from initial display but include them when expanding the code snippet or testing
/// with rustdoc. The cutoff_commented_lines = true, means do not include code lines started with #...
pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str, cutoff_commented_lines: bool) -> String {
pub fn take_rustdoc_include_anchored_lines(
s: &str,
anchor: &str,
cutoff_commented_lines: bool,
) -> String {
let mut output = String::with_capacity(s.len());
let mut within_anchored_section = false;

Expand All @@ -108,7 +117,8 @@ pub fn take_rustdoc_include_anchored_lines(s: &str, anchor: &str, cutoff_comment
within_anchored_section = true;
}
} else if !ANCHOR_END.is_match(l) {
if !cutoff_commented_lines { // do not include 'dashed' lines (for epub format)
if !cutoff_commented_lines {
// do not include 'dashed' lines (for epub format)
output.push_str("# ");
output.push_str(l);
output.push('\n');
Expand Down

0 comments on commit 56051be

Please sign in to comment.