Adding preprocessor for Summary
This commit is contained in:
parent
2fbe3ba930
commit
94bb9c4c2c
|
@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
|
|||
use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
|
||||
use crate::config::BuildConfig;
|
||||
use crate::errors::*;
|
||||
use crate::preprocess::SummaryPreprocessor;
|
||||
use crate::utils::bracket_escape;
|
||||
use log::debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -21,7 +22,9 @@ pub fn load_book<P: AsRef<Path>>(src_dir: P, cfg: &BuildConfig) -> Result<Book>
|
|||
.with_context(|| format!("Couldn't open SUMMARY.md in {:?} directory", src_dir))?
|
||||
.read_to_string(&mut summary_content)?;
|
||||
|
||||
let summary = parse_summary(&summary_content)
|
||||
let preprocessed_summary_content = SummaryPreprocessor::resolve(src_dir, &summary_content);
|
||||
|
||||
let summary = parse_summary(&preprocessed_summary_content)
|
||||
.with_context(|| format!("Summary parsing failed for file={:?}", summary_md))?;
|
||||
|
||||
if cfg.create_missing {
|
||||
|
|
|
@ -71,7 +71,7 @@ impl Preprocessor for LinkPreprocessor {
|
|||
}
|
||||
}
|
||||
|
||||
fn replace_all<P1, P2>(
|
||||
pub(crate) fn replace_all<P1, P2>(
|
||||
s: &str,
|
||||
path: P1,
|
||||
source: P2,
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
pub use self::cmd::CmdPreprocessor;
|
||||
pub use self::index::IndexPreprocessor;
|
||||
pub use self::links::LinkPreprocessor;
|
||||
pub use self::summary::SummaryPreprocessor;
|
||||
|
||||
mod cmd;
|
||||
mod index;
|
||||
mod links;
|
||||
mod summary;
|
||||
|
||||
use crate::book::Book;
|
||||
use crate::config::Config;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
use std::path::Path;
|
||||
|
||||
/// A preprocessor dedicated just to the summary to resolve links
|
||||
#[derive(Default)]
|
||||
pub struct SummaryPreprocessor;
|
||||
|
||||
impl SummaryPreprocessor {
|
||||
/// Preprocess Summary to resolve links.
|
||||
pub fn resolve(src_dir: &Path, content: &str) -> String {
|
||||
let mut title = String::from("SUMMARY.md");
|
||||
super::links::replace_all(content, src_dir, src_dir, 0, &mut title)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue