mod assets;
mod code;
mod docx;
mod epub;
mod escape;
mod flow;
mod friendly;
mod hard;
mod hard95;
mod inline_math;
mod latex;
mod markdown;
mod mathml;
mod medium;
mod options;
mod table;
mod zip;
pub(crate) use assets::ImageStore;
pub use docx::{DocxOptions, DocxOutput, render_docx, render_docx_with_images};
pub use epub::{EpubOptions, render_epub};
pub(crate) use escape::*;
pub(crate) use flow::*;
pub use latex::{LatexOptions, LatexOutput, render_latex};
pub use markdown::{MarkdownOptions, MarkdownOutput, render_markdown};
pub(crate) use mathml::math_css;
pub use mathml::math_html;
pub use options::{Equations, HtmlOptions, HtmlOutput, Mode, PageImage};
pub(crate) use table::*;
use crate::analysis::pipeline::Analysis;
use crate::backend::PdfFile;
use crate::model::*;
pub(crate) trait Renderer {
fn render(&self, analysis: &Analysis, images: &mut ImageStore<'_>) -> String;
}
pub(crate) fn font_face(family: &str, style: &str, weight: &str, data: &[u8]) -> String {
use base64::Engine;
format!(
"@font-face{{font-family:\"{family}\";font-style:{style};font-weight:{weight};font-display:swap;\
src:url(data:font/woff2;base64,{}) format(\"woff2\")}}\n",
base64::engine::general_purpose::STANDARD.encode(data)
)
}
fn renderer_for(mode: Mode) -> &'static dyn Renderer {
match mode {
Mode::Friendly => &friendly::Friendly,
Mode::Medium => &medium::Medium,
Mode::Hard => &hard::Hard,
Mode::Hard95 => &hard95::Hard95,
}
}
pub fn render(analysis: &Analysis, pdf: &PdfFile, opts: &HtmlOptions) -> HtmlOutput {
let mut images = ImageStore { opts, jobs: Vec::new() };
let html = renderer_for(opts.mode).render(analysis, &mut images);
images.finish(pdf, html)
}
pub fn render_to(
analysis: &Analysis,
pdf: &PdfFile,
opts: &HtmlOptions,
out: &mut dyn std::io::Write,
file: &mut dyn FnMut(String, Vec<u8>) -> std::io::Result<()>,
) -> std::io::Result<()> {
let mut images = ImageStore { opts, jobs: Vec::new() };
let html = renderer_for(opts.mode).render(analysis, &mut images);
images.finish_into(pdf, &html, out, file)
}