Fix formatting
This commit is contained in:
parent
dacd1d16bc
commit
6f832ed434
|
@ -24,7 +24,8 @@ use topological_sort::TopologicalSort;
|
||||||
|
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::preprocess::{
|
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::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer};
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
|
@ -2,11 +2,11 @@ use crate::errors::*;
|
||||||
|
|
||||||
use super::{Preprocessor, PreprocessorContext};
|
use super::{Preprocessor, PreprocessorContext};
|
||||||
use crate::book::{Book, BookItem, Chapter};
|
use crate::book::{Book, BookItem, Chapter};
|
||||||
use regex::{Captures, Regex};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::io::{BufRead, BufReader};
|
use regex::{Captures, Regex};
|
||||||
use std::fs::File;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
|
|
||||||
const SPLITTER: char = ':';
|
const SPLITTER: char = ':';
|
||||||
|
|
||||||
|
@ -35,12 +35,11 @@ impl DrinkPreprocessor {
|
||||||
\s+ # separating whitespace
|
\s+ # separating whitespace
|
||||||
(?<drink>[A-z0-9_-]+) # drink name
|
(?<drink>[A-z0-9_-]+) # drink name
|
||||||
\}\} # link closing parens",
|
\}\} # link closing parens",
|
||||||
).unwrap()
|
)
|
||||||
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
static NODRINK: Lazy<String> = Lazy::new(|| {
|
static NODRINK: Lazy<String> = Lazy::new(|| "deadbeef".to_string());
|
||||||
"deadbeef".to_string()
|
|
||||||
});
|
|
||||||
|
|
||||||
let res = RE.replace_all(&chapter.content, |caps: &Captures<'_>| {
|
let res = RE.replace_all(&chapter.content, |caps: &Captures<'_>| {
|
||||||
dict.get(&caps["drink"]).unwrap_or(&NODRINK)
|
dict.get(&caps["drink"]).unwrap_or(&NODRINK)
|
||||||
|
@ -59,9 +58,14 @@ impl Preprocessor for DrinkPreprocessor {
|
||||||
|
|
||||||
let drinks: Dict = {
|
let drinks: Dict = {
|
||||||
let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary"));
|
let reader = BufReader::new(File::open(path).expect("Cannot open drinks dictionary"));
|
||||||
reader.lines().filter_map(|l| {
|
reader
|
||||||
l.expect("Cannot read line in drinks dictionary").split_once(SPLITTER).map(|(name, value)| (name.trim().to_owned(), value.trim().to_owned()))
|
.lines()
|
||||||
}).collect::<HashMap<_, _>>()
|
.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| {
|
book.for_each_mut(|section: &mut BookItem| {
|
||||||
|
|
Loading…
Reference in New Issue