Fix formatting
This commit is contained in:
parent
dacd1d16bc
commit
6f832ed434
|
@ -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;
|
||||
|
|
|
@ -2,11 +2,11 @@ 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 = ':';
|
||||
|
||||
|
@ -35,12 +35,11 @@ impl DrinkPreprocessor {
|
|||
\s+ # separating whitespace
|
||||
(?<drink>[A-z0-9_-]+) # drink name
|
||||
\}\} # link closing parens",
|
||||
).unwrap()
|
||||
)
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
static NODRINK: Lazy<String> = Lazy::new(|| {
|
||||
"deadbeef".to_string()
|
||||
});
|
||||
static NODRINK: Lazy<String> = 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::<HashMap<_, _>>()
|
||||
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::<HashMap<_, _>>()
|
||||
};
|
||||
|
||||
book.for_each_mut(|section: &mut BookItem| {
|
||||
|
|
Loading…
Reference in New Issue