summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/doc.rs b/src/doc.rs
index 07831c2..1e48e40 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -5,6 +5,7 @@ use crate::html::Attribute;
use crate::html::HtmlPage;
use crate::html::{Content, Element, ElementTag};
use crate::md::Markdown;
+use crate::resource;
use crate::EmbeddedFile;
use crate::EmbeddedFiles;
use crate::MatchedScenario;
@@ -25,6 +26,9 @@ use std::path::{Path, PathBuf};
use log::{error, trace};
+/// Name of standard Subplot CSS file.
+const CSS: &str = "subplot.css";
+
/// The set of known (special) classes which subplot will always recognise
/// as being valid.
static SPECIAL_CLASSES: &[&str] = &[
@@ -140,13 +144,8 @@ impl Document {
/// Return Document as an HTML page serialized into HTML text
pub fn to_html(&mut self, date: &str) -> Result<String, SubplotError> {
- const CSS: &str = r#"
- div.toc ol {
- list-style-type: none;
- padding: 0;
- padding-inline-start: 2ch;
- }
- "#;
+ let css_file = resource::read_as_string(CSS, None)
+ .map_err(|e| SubplotError::CssFileNotFound(CSS.into(), e))?;
let mut head = Element::new(crate::html::ElementTag::Head);
let mut title = Element::new(crate::html::ElementTag::Title);
@@ -154,7 +153,7 @@ impl Document {
head.push_child(crate::html::Content::Elt(title));
let mut css = Element::new(ElementTag::Style);
- css.push_child(Content::Text(CSS.into()));
+ css.push_child(Content::Text(css_file));
for css_file in self.meta.css_embed() {
css.push_child(Content::Text(css_file.into()));
}
@@ -527,7 +526,12 @@ impl Document {
for scenario in scenarios {
for step in scenario.steps() {
for captured in step.parts() {
- if let PartialStep::CapturedText { name, text } = captured {
+ if let PartialStep::CapturedText {
+ name,
+ text,
+ kind: _,
+ } = captured
+ {
if matches!(step.types().get(name.as_str()), Some(CaptureType::File))
&& !filenames.contains(&text.to_lowercase())
{
@@ -563,7 +567,12 @@ impl Document {
for scenario in scenarios {
for step in scenario.steps() {
for captured in step.parts() {
- if let PartialStep::CapturedText { name, text } = captured {
+ if let PartialStep::CapturedText {
+ name,
+ text,
+ kind: _,
+ } = captured
+ {
if matches!(step.types().get(name.as_str()), Some(CaptureType::File)) {
filenames.remove(&text.to_lowercase());
}
@@ -608,10 +617,15 @@ impl Document {
}
/// Typeset a Subplot document.
- pub fn typeset(&mut self, warnings: &mut Warnings) {
+ pub fn typeset(
+ &mut self,
+ warnings: &mut Warnings,
+ template: Option<&str>,
+ ) -> Result<(), SubplotError> {
for md in self.markdowns.iter_mut() {
- warnings.push_all(md.typeset(self.style.clone(), self.meta.bindings()));
+ warnings.push_all(md.typeset(self.style.clone(), template, self.meta.bindings()));
}
+ Ok(())
}
/// Return all scenarios in a document.