diff options
Diffstat (limited to 'src/md.rs')
-rw-r--r-- | src/md.rs | 62 |
1 files changed, 5 insertions, 57 deletions
@@ -3,7 +3,7 @@ use crate::{ html::{parse, Attribute, Content, Element, ElementTag}, parse_scenario_snippet, Bindings, EmbeddedFile, EmbeddedFiles, Scenario, ScenarioStep, Style, - SubplotError, Warnings, YamlMetadata, + SubplotError, Warnings, }; use log::trace; use std::collections::HashSet; @@ -13,7 +13,6 @@ use std::path::{Path, PathBuf}; #[derive(Debug)] pub struct Markdown { html: Element, - meta: Option<YamlMetadata>, } impl Markdown { @@ -32,63 +31,12 @@ impl Markdown { } fn new(html: Element) -> Self { - Self { html, meta: None } + Self { html } } - /// Set document metadata from subplot. - pub fn set_metadata(&mut self, meta: &YamlMetadata) { - self.meta = Some(meta.clone()); - } - - /// Set date. - pub fn set_date(&mut self, date: String) { - if let Some(meta) = &mut self.meta { - meta.set_date(date); - } - } - - /// Return parsed HTML of the markdown. - pub fn to_html(&self) -> Element { - if let Some(meta) = &self.meta { - let mut div = Element::new(ElementTag::Div); - div.push_child(Content::Elt(Self::title(meta.title()))); - if let Some(authors) = meta.authors() { - div.push_child(Content::Elt(Self::authors(authors))); - } - if let Some(date) = meta.date() { - div.push_child(Content::Elt(Self::date(date))); - } - div.push_child(Content::Elt(self.html.clone())); - div - } else { - self.html.clone() - } - } - - fn title(title: &str) -> Element { - let mut e = Element::new(ElementTag::H1); - e.push_child(Content::Text(title.into())); - e - } - - fn authors(authors: &[String]) -> Element { - let mut list = Element::new(ElementTag::P); - list.push_child(Content::Text("By: ".into())); - let mut first = true; - for a in authors { - if !first { - list.push_child(Content::Text(", ".into())); - } - list.push_child(Content::Text(a.into())); - first = false; - } - list - } - - fn date(date: &str) -> Element { - let mut e = Element::new(ElementTag::P); - e.push_child(Content::Text(date.into())); - e + /// Return root element of markdown. + pub fn root_element(&self) -> &Element { + &self.html } /// Find included images. |