unimarkup_render/
html.rs

1//! Defines the [`Html`] struct that is returned by the [`Render`](crate::render::Render) trait when rendering Unimarkup to HTML.
2
3use logid::capturing::MappedLogId;
4
5use crate::render::RenderBlock;
6
7#[derive(Debug, Default)]
8pub struct Html {
9    pub head: String,
10    pub body: String,
11}
12
13/// Renders all [`RenderBlock`]s and returns the resulting [`Html`] structure.
14///
15/// # Arguments
16///
17/// - `blocks` - array of type [`RenderBlock`]
18///
19/// Returns a [`MappedLogId`], if any of the given blocks return a [`MappedLogId`]
20/// when rendering themself.
21pub fn render_html(blocks: &[RenderBlock]) -> Result<Html, MappedLogId> {
22    let mut html = Html::default();
23
24    for block in blocks {
25        let html_part = block.render_html()?;
26        html.body.push_str(&html_part.body);
27        html.head.push_str(&html_part.head);
28    }
29
30    Ok(html)
31}