diff --git a/src/book/mod.rs b/src/book/mod.rs index de5d9eab..de24e4c9 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -24,7 +24,8 @@ use topological_sort::TopologicalSort; use crate::errors::*; use crate::preprocess::{ - CmdPreprocessor, DrinkPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext, + CmdPreprocessor, DrinkPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, + PreprocessorContext, }; use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer}; use crate::utils; diff --git a/src/preprocess/drinks.rs b/src/preprocess/drinks.rs index f2cd2c08..7e756738 100644 --- a/src/preprocess/drinks.rs +++ b/src/preprocess/drinks.rs @@ -2,15 +2,15 @@ use crate::errors::*; use super::{Preprocessor, PreprocessorContext}; use crate::book::{Book, BookItem, Chapter}; -use regex::{Captures, Regex}; use once_cell::sync::Lazy; -use std::io::{BufRead, BufReader}; -use std::fs::File; +use regex::{Captures, Regex}; use std::collections::HashMap; +use std::fs::File; +use std::io::{BufRead, BufReader}; const SPLITTER: char = ':'; -type Dict=HashMap; +type Dict = HashMap; /// DRY Links - A preprocessor for using centralized links collection: /// @@ -29,18 +29,17 @@ impl DrinkPreprocessor { fn replace_drinks(&self, chapter: &mut Chapter, dict: &Dict) -> Result { static RE: Lazy = Lazy::new(|| { Regex::new( - r"(?x) # insignificant whitespace mode + r"(?x) # insignificant whitespace mode \{\{\s* # link opening parens and whitespace \#(drink) # drink marker \s+ # separating whitespace (?[A-z0-9_-]+) # drink name \}\} # link closing parens", - ).unwrap() + ) + .unwrap() }); - static NODRINK: Lazy = Lazy::new(|| { - "deadbeef".to_string() - }); + static NODRINK: Lazy = Lazy::new(|| "deadbeef".to_string()); let res = RE.replace_all(&chapter.content, |caps: &Captures<'_>| { dict.get(&caps["drink"]).unwrap_or(&NODRINK) @@ -59,9 +58,14 @@ impl Preprocessor for DrinkPreprocessor { let drinks: Dict = { let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary")); - reader.lines().filter_map(|l| { - l.expect("Cannot read line in drinks dictionary").split_once(SPLITTER).map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned())) - }).collect::>() + reader + .lines() + .filter_map(|l| { + l.expect("Cannot read line in drinks dictionary") + .split_once(SPLITTER) + .map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned())) + }) + .collect::>() }; book.for_each_mut(|section: &mut BookItem| {