diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-06-15 07:56:32 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-06-15 07:56:32 +0300 |
commit | 8802069892c3835181cb506d0deba91eacce225a (patch) | |
tree | 3583752bf424a34c0cc36278cfdb9476adcdd20a /src | |
parent | 9f2198d7c6d323b04d2d6a2ee6bf1cc421a91de5 (diff) | |
download | subplot-8802069892c3835181cb506d0deba91eacce225a.tar.gz |
refactor: change Document::to_html to return a Result
HTML generation uses write!, which can fail, so to_html must return a
Result.
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/subplot.rs | 2 | ||||
-rw-r--r-- | src/doc.rs | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs index ca1ef5d..ced34cc 100644 --- a/src/bin/subplot.rs +++ b/src/bin/subplot.rs @@ -285,7 +285,7 @@ impl Docgen { }; doc.typeset(&mut Warnings::default()); - std::fs::write(&self.output, doc.to_html(&date)) + std::fs::write(&self.output, doc.to_html(&date)?) .map_err(|e| SubplotError::WriteFile(self.output.clone(), e))?; Ok(()) @@ -153,7 +153,7 @@ impl Document { } /// Return Document as an HTML page serialized into HTML text - pub fn to_html(&mut self, date: &str) -> String { + pub fn to_html(&mut self, date: &str) -> Result<String, SubplotError> { let mut head = Element::new(crate::html::ElementTag::Head); let mut title = Element::new(crate::html::ElementTag::Title); title.push_child(crate::html::Content::Text(self.meta().title().into())); @@ -166,7 +166,7 @@ impl Document { body.push_child(Content::Elt(md.root_element().clone())); } let page = HtmlPage::new(head, body); - page.serialize().unwrap() // FIXME + page.serialize().map_err(SubplotError::ParseMarkdown) } fn typeset_meta(&self) -> Element { |