/// Writes the page contents to HTML
Writes the page contents to HTML
Writes the page contents to HTML
fn render_content_to_html(
        mut dest: &mut String,
        assets: &mut Vec<Asset>,
        ctx: &GeneratorContext,
        content: String,
    ) {
        let mut footnote_no = 0;
        let parser = Parser::new_ext(&content, MarkdownFile::parser_options(true));
        let events = parser.map(|event| match event {
            Event::FootnoteReference(name) => {
                footnote_no += 1;
                let formatted = format!(
                    "<sup class=\"fn\"><a id=\"{}-back\" href=\"#{}\">[{}]</a></sup>",
                    name, name, footnote_no
                );
                Event::Html(formatted.into())
            }
            Event::Start(Tag::Heading(level)) => Event::Html(format!("<h{}>", level + 1).into()),
            Event::End(Tag::Heading(level)) => Event::Html(format!("</h{}>", level + 1).into()),
            Event::Start(Tag::Link(link_type, dest, title)) => {
                rewrite_relative_url(&ctx, link_type, dest, title)
            }
            Event::Start(Tag::Image(link_type, dest, title)) => {
                if is_relative_url(dest.to_string()) {
                    let source = PathBuf::from(dest.into_string());
                    let relative_target_path =
                        format!("static/{}", source.file_name().unwrap().to_str().unwrap());
                    let absolute_url =
                        format!("{}/{}", &ctx.config.base_url, &relative_target_path);
                    assets.push(Asset {
                        source: source.into(),
                        target: PathBuf::from(relative_target_path.clone()),
                    });
                    Event::Start(Tag::Image(link_type, absolute_url.into(), title))
                } else {
                    Event::Start(Tag::Image(link_type, dest, title))
                }
            }
            _ => event,
        });
        html::push_html(&mut dest, events);
    }
fn render_content_to_html ( mut dest : & mut String , assets : & mut Vec < Asset > , ctx : & GeneratorContext , content : String , ) { let mut footnote_no = 0 ; let parser = Parser :: new_ext ( & content , MarkdownFile :: parser_options ( true ) ) ; let events = parser . map ( | event | match event { Event :: FootnoteReference ( name ) => { footnote_no += 1 ; let formatted = format ! ( " \" \" \" \" \" \" " name name footnote_no ) ; Event :: Html ( formatted . into ( ) ) } Event :: Start ( Tag :: Heading ( level ) ) => Event :: Html ( format ! ( " " level 1 ) . into ( ) ) , Event :: End ( Tag :: Heading ( level ) ) => Event :: Html ( format ! ( " " level 1 ) . into ( ) ) , Event :: Start ( Tag :: Link ( link_type , dest , title ) ) => { rewrite_relative_url ( & ctx , link_type , dest , title ) } Event :: Start ( Tag :: Image ( link_type , dest , title ) ) => { if is_relative_url ( dest . to_string ( ) ) { let source = PathBuf :: from ( dest . into_string ( ) ) ; let relative_target_path = format ! ( " " source file_name ( ) unwrap ( ) to_str ( ) unwrap ( ) ) ; let absolute_url = format ! ( " " ctx config base_url relative_target_path ) ; assets . push ( Asset { source : source . into ( ) , target : PathBuf :: from ( relative_target_path . clone ( ) ) , } ) ; Event :: Start ( Tag :: Image ( link_type , absolute_url . into ( ) , title ) ) } else { Event :: Start ( Tag :: Image ( link_type , dest , title ) ) } } _ => event , } ) ; html :: push_html ( & mut dest , events ) ; }
Writes the page contents to HTML
Writes the page contents to HTML
dest
&mut String
assets
&mut Vec<Asset>
ctx
&GeneratorContext
content
String