#![forbid(unsafe_code)]
use ironpress::HtmlConverter;
use std::fmt;
pub struct Font {
pub family: String,
pub ttf: Vec<u8>,
}
#[derive(Debug)]
pub struct RenderError(String);
impl fmt::Display for RenderError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.0)
}
}
impl std::error::Error for RenderError {}
pub fn render(html: &str, fonts: Vec<Font>) -> Result<Vec<u8>, RenderError> {
let mut converter = HtmlConverter::new().sanitize(true);
for font in fonts {
converter = converter.add_font(&font.family, font.ttf);
}
converter
.convert(html)
.map_err(|error| RenderError(error.to_string()))
}