mirror of
https://github.com/lise-henry/crowbook
synced 2024-06-13 05:06:22 +02:00
Run clippy on src
This commit is contained in:
parent
9185ba7e27
commit
6752f1566a
|
@ -681,8 +681,7 @@ impl BookOptions {
|
|||
"cover" | "html.icon" => {
|
||||
// Translate according to resources.base_path.images
|
||||
let base = self.get_path("resources.base_path.images").unwrap();
|
||||
let new_path = Path::new(&base).join(path);
|
||||
new_path
|
||||
Path::new(&base).join(path)
|
||||
}
|
||||
|
||||
"output.epub" |
|
||||
|
@ -696,15 +695,13 @@ impl BookOptions {
|
|||
"output.proofread.pdf" => {
|
||||
// Translate according to output.base_path
|
||||
let base = self.get_path("output.base_path").unwrap();
|
||||
let new_path = Path::new(&base).join(path);
|
||||
new_path
|
||||
Path::new(&base).join(path)
|
||||
}
|
||||
|
||||
key if self.valid_tpls.contains(&key) => {
|
||||
// Translate according to resources.base_path.template
|
||||
let base = self.get_path("resources.base_path.templates").unwrap();
|
||||
let new_path = Path::new(&base).join(path);
|
||||
new_path
|
||||
Path::new(&base).join(path)
|
||||
}
|
||||
|
||||
_ => self.root.join(path),
|
||||
|
|
|
@ -109,11 +109,10 @@ impl French {
|
|||
impl Cleaner for French {
|
||||
/// Puts non breaking spaces before/after `:`, `;`, `?`, `!`, `«`, `»`, `—`
|
||||
fn clean<'a>(&self, s: Cow<'a, str>, latex: bool) -> Cow<'a, str> {
|
||||
let s = if latex {
|
||||
if latex {
|
||||
self.formatter.format_tex(s)
|
||||
} else {
|
||||
self.formatter.format(s)
|
||||
};
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ impl<'a> HtmlRenderer<'a> {
|
|||
|
||||
/// Creates a new HTML renderer
|
||||
pub fn new(book: &'a Book) -> HtmlRenderer<'a> {
|
||||
let (highlight, syntax) = Self::get_highlight(&book);
|
||||
let (highlight, syntax) = Self::get_highlight(book);
|
||||
|
||||
let mut html = HtmlRenderer {
|
||||
book: book,
|
||||
|
@ -216,9 +216,6 @@ impl<'a> HtmlRenderer<'a> {
|
|||
self.render_vec(&Parser::new().parse_inline(s)?)
|
||||
});
|
||||
res?
|
||||
} else if n == 1 && self.current_numbering >= 0 {
|
||||
let p_title = self.render_vec(vec)?;
|
||||
p_title
|
||||
} else if self.current_numbering >= n {
|
||||
format!("{} {}", self.get_numbers(), self.render_vec(vec)?)
|
||||
} else {
|
||||
|
@ -290,13 +287,11 @@ impl<'a> HtmlRenderer<'a> {
|
|||
}
|
||||
if i != 1 || !self.book.options.get_bool("rendering.chapter.roman_numerals").unwrap() {
|
||||
output.push_str(&format!("{}.", self.current_chapter[i])); //todo
|
||||
} else if self.current_chapter[i] >= 1 {
|
||||
output.push_str(&format!("{:X}.", Roman::from(self.current_chapter[i] as i16)));
|
||||
} else {
|
||||
if self.current_chapter[i] >= 1 {
|
||||
output.push_str(&format!("{:X}.", Roman::from(self.current_chapter[i] as i16)));
|
||||
} else {
|
||||
self.book.logger.error(lformat!("can not use roman numerals with zero or negative chapter numbers ({n})",
|
||||
self.book.logger.error(lformat!("can not use roman numerals with zero or negative chapter numbers ({n})",
|
||||
n = self.current_chapter[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
output
|
||||
|
@ -366,13 +361,13 @@ impl<'a> HtmlRenderer<'a> {
|
|||
Token::Annotation(ref annotation, ref v) => {
|
||||
let content = this.as_mut().render_vec(v)?;
|
||||
if this.as_ref().proofread {
|
||||
match annotation {
|
||||
&Data::GrammarError(ref s) => {
|
||||
match *annotation {
|
||||
Data::GrammarError(ref s) => {
|
||||
Ok(format!("<span title = \"{}\" class = \"grammar-error\">{}</span>",
|
||||
escape::quotes(s.as_str()),
|
||||
content))
|
||||
}
|
||||
&Data::Repetition(ref colour) => {
|
||||
Data::Repetition(ref colour) => {
|
||||
if !this.as_ref().verbatim {
|
||||
Ok(format!("<span class = \"repetition\" \
|
||||
style = \"text-decoration-line: underline; \
|
||||
|
|
|
@ -292,12 +292,10 @@ impl<'a> Renderer for LatexRenderer<'a> {
|
|||
} else {
|
||||
return Ok(r#"\section*{}"#.to_owned());
|
||||
}
|
||||
} else {
|
||||
if let Number::Specified(n) = self.current_chapter {
|
||||
content.push_str(r"\setcounter{chapter}{");
|
||||
content.push_str(&format!("{}", n - 1));
|
||||
content.push_str("}\n");
|
||||
}
|
||||
} else if let Number::Specified(n) = self.current_chapter {
|
||||
content.push_str(r"\setcounter{chapter}{");
|
||||
content.push_str(&format!("{}", n - 1));
|
||||
content.push_str("}\n");
|
||||
}
|
||||
}
|
||||
match n {
|
||||
|
@ -379,15 +377,13 @@ impl<'a> Renderer for LatexRenderer<'a> {
|
|||
let url = escape::tex(url.as_ref());
|
||||
if &content == &url {
|
||||
Ok(format!("\\url{{{}}}", content))
|
||||
} else if self.book.options.get_bool("tex.links_as_footnotes").unwrap() {
|
||||
Ok(format!("\\href{{{}}}{{{}}}\\protect\\footnote{{\\url{{{}}}}}",
|
||||
url,
|
||||
content,
|
||||
url))
|
||||
} else {
|
||||
if self.book.options.get_bool("tex.links_as_footnotes").unwrap() {
|
||||
Ok(format!("\\href{{{}}}{{{}}}\\protect\\footnote{{\\url{{{}}}}}",
|
||||
url,
|
||||
content,
|
||||
url))
|
||||
} else {
|
||||
Ok(format!("\\href{{{}}}{{{}}}", url, content))
|
||||
}
|
||||
Ok(format!("\\href{{{}}}{{{}}}", url, content))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ impl Output {
|
|||
return Output::Terminal(term)
|
||||
}
|
||||
}
|
||||
return Output::Stderr(io::stderr())
|
||||
Output::Stderr(io::stderr())
|
||||
}
|
||||
|
||||
/// Print a msg prefixed by a coloured `level` message
|
||||
|
|
|
@ -263,27 +263,25 @@ fn collapse(ast: &mut Vec<Token>) {
|
|||
|
||||
let mut i = 0;
|
||||
while i < ast.len() {
|
||||
if ast[i].is_str() {
|
||||
if i < ast.len() - 1 {
|
||||
if ast[i + 1].is_str() {
|
||||
// Two consecutives Str, concatenate them
|
||||
let token = ast.remove(i + 1);
|
||||
if let (&mut Token::Str(ref mut dest), Token::Str(ref source)) = (&mut ast[i],
|
||||
token) {
|
||||
// dest.push(' ');
|
||||
dest.push_str(source);
|
||||
continue;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
} else if ast[i + 1] == Token::SoftBreak {
|
||||
ast.remove(i + 1);
|
||||
if let &mut Token::Str(ref mut dest) = &mut ast[i] {
|
||||
dest.push(' ');
|
||||
continue;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
if ast[i].is_str() && i < ast.len() - 1 {
|
||||
if ast[i + 1].is_str() {
|
||||
// Two consecutives Str, concatenate them
|
||||
let token = ast.remove(i + 1);
|
||||
if let (&mut Token::Str(ref mut dest), Token::Str(ref source)) = (&mut ast[i],
|
||||
token) {
|
||||
// dest.push(' ');
|
||||
dest.push_str(source);
|
||||
continue;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
} else if ast[i + 1] == Token::SoftBreak {
|
||||
ast.remove(i + 1);
|
||||
if let &mut Token::Str(ref mut dest) = &mut ast[i] {
|
||||
dest.push(' ');
|
||||
continue;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,15 +252,13 @@ pub fn insert_annotation(tokens: &mut Vec<Token>,
|
|||
tokens.insert(i + 1, new_token);
|
||||
}
|
||||
return None;
|
||||
} else if found_left.is_none() && found_right.is_none() {
|
||||
return Some(pos);
|
||||
} else {
|
||||
if found_left.is_none() && found_right.is_none() {
|
||||
return Some(pos);
|
||||
} else {
|
||||
Logger::display_warning(lformat!("ignored annotation {:?} as it wasn't compatible \
|
||||
with the Markdown structure",
|
||||
annotation));
|
||||
return None;
|
||||
}
|
||||
Logger::display_warning(lformat!("ignored annotation {:?} as it wasn't compatible \
|
||||
with the Markdown structure",
|
||||
annotation));
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue