html_site_generator/html/
line_break.rs

1use std::io::Write;
2
3use anyhow::Result;
4
5use crate::html::{IntoHtmlNode, IsParagraph};
6
7#[derive(Debug)]
8pub struct LineBreak;
9
10impl LineBreak {
11    pub fn new() -> Self {
12        LineBreak
13    }
14}
15
16impl IntoHtmlNode for LineBreak {
17    fn transform_into_html_node(&self, buffer: &mut dyn Write) -> Result<()> {
18        write!(buffer, "<br />")?;
19
20        Ok(())
21    }
22}
23
24// TODO I'm not quit sure if `LineBreak` implements the trait `IsParagraph`.
25// But at the moment this is the only way to use `Hyperlink` in a `Paragraph`
26// Maybe there is another, and better way, to do this?
27// same as `Image`, `Hyperlink`
28impl IsParagraph for LineBreak {
29    fn to_raw(&self) -> String {
30        let mut vec = Vec::new();
31
32        self.transform_into_html_node(&mut vec).unwrap();
33
34        String::from_utf8(vec).unwrap()
35    }
36}