mod assets;
mod chunks;
mod code;
mod docx;
mod epub;
pub(crate) mod escape;
mod flow;
mod friendly;
mod hard;
mod hard95;
mod inline_math;
mod json;
mod latex;
mod markdown;
pub(crate) mod mathml;
mod medium;
mod notes;
mod options;
mod table;
pub(crate) mod zip;
#[cfg(test)]
pub(crate) use docx::inline_math as docx_omml_for_tests;
pub(crate) use assets::{ImageStore, Pictures};
pub use chunks::{
Chunk, ChunkOptions, NAMED_TOKENIZERS, TokenCounter, chunks_jsonl, estimate as estimate_tokens, render_chunks,
};
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 json::apply::ContentReport;
pub(crate) use json::apply::apply_content;
pub(crate) use json::figure_lines::figure_svg;
pub use json::{JsonOptions, JsonOutput};
pub(crate) use json::{SourceInfo, render_json};
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: Option<&PdfFile>, opts: &HtmlOptions) -> HtmlOutput {
let mut images = ImageStore {
opts,
jobs: Vec::new(),
vector: true,
};
let numbered = notes::numbered_analysis(analysis);
let html = renderer_for(opts.mode).render(numbered.as_ref().unwrap_or(analysis), &mut images);
images.finish(Pictures::new(pdf, &analysis.doc), html)
}
pub fn render_to(
analysis: &Analysis,
pdf: Option<&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(),
vector: true,
};
let numbered = notes::numbered_analysis(analysis);
let html = renderer_for(opts.mode).render(numbered.as_ref().unwrap_or(analysis), &mut images);
images.finish_into(Pictures::new(pdf, &analysis.doc), &html, out, file)
}