diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-07-31 10:55:11 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-07-31 10:55:11 +0300 |
commit | b51e5bf01794732b61b9402eceabce457f2120c9 (patch) | |
tree | 0ff64d37f06b455abe2a156f14af95b81bf6524a | |
parent | bc9493725346d909c305fcaacd06c448e303cd05 (diff) | |
download | riki-b51e5bf01794732b61b9402eceabce457f2120c9.tar.gz |
refactor: allow HTML generation to produce fatal errors
It doesn't, yet, but will need to, eventually.
Sponsored-by: author
-rw-r--r-- | src/bin/riki.rs | 4 | ||||
-rw-r--r-- | src/html.rs | 4 | ||||
-rw-r--r-- | src/page.rs | 12 |
3 files changed, 10 insertions, 10 deletions
diff --git a/src/bin/riki.rs b/src/bin/riki.rs index 1455b45..86d9fcf 100644 --- a/src/bin/riki.rs +++ b/src/bin/riki.rs @@ -76,9 +76,9 @@ impl Build { for page in site.markdown_pages() { let htmlpage = if self.plain_body { - page.body_to_html() + page.body_to_html()? } else { - page.to_html() + page.to_html()? }; let output = page.meta().destination_filename(&destdir); debug!("writing: {}", output.display()); diff --git a/src/html.rs b/src/html.rs index b4e4c45..90bf9d5 100644 --- a/src/html.rs +++ b/src/html.rs @@ -60,7 +60,7 @@ impl HtmlPage { } } -pub fn parse(markdown: &str) -> Element { +pub fn parse(markdown: &str) -> Result<Element, SiteError> { let mut options = Options::empty(); options.insert(Options::ENABLE_HEADING_ATTRIBUTES); options.insert(Options::ENABLE_STRIKETHROUGH); @@ -179,7 +179,7 @@ pub fn parse(markdown: &str) -> Element { let mut body = stack.pop(); assert!(stack.is_empty()); body.fix_up_img_alt(); - body + Ok(body) } fn as_plain_text(content: &[Content]) -> String { diff --git a/src/page.rs b/src/page.rs index d0ba861..c00aa54 100644 --- a/src/page.rs +++ b/src/page.rs @@ -97,23 +97,23 @@ impl MarkdownPage { &self.meta } - pub fn body_to_html(&self) -> HtmlPage { + pub fn body_to_html(&self) -> Result<HtmlPage, SiteError> { let head = Element::new(ElementTag::Head); - let body = parse(self.markdown()); - HtmlPage::new(head, body) + let body = parse(self.markdown())?; + Ok(HtmlPage::new(head, body)) } - pub fn to_html(&self) -> HtmlPage { + pub fn to_html(&self) -> Result<HtmlPage, SiteError> { let mut title = Element::new(ElementTag::Title); title.push_child(Content::Text(self.meta.title().into())); let mut head = Element::new(ElementTag::Head); head.push_child(Content::Elt(title)); - let body = parse(self.markdown()); + let body = parse(self.markdown())?; trace!("MarkdownPage::to_html: head={:?}", head); - HtmlPage::new(head, body) + Ok(HtmlPage::new(head, body)) } } |