From d6ba90c694fe8905aadf02acbbb0ff7e24f30b4e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 1 Dec 2023 17:59:46 +0200 Subject: refactor: move CSS file out of doc.rs Make it easier to edit the CSS file, and also add some styles for upcoming scenario typesetting. Signed-off-by: Lars Wirzenius Sponsored-by: author --- share/subplot.css | 40 ++++++++++++++++++++++++++++++++++++++++ src/doc.rs | 15 +++++++-------- src/error.rs | 4 ++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 share/subplot.css diff --git a/share/subplot.css b/share/subplot.css new file mode 100644 index 0000000..292a5f7 --- /dev/null +++ b/share/subplot.css @@ -0,0 +1,40 @@ +div.toc ol { + list-style-type: none; + padding: 0; + padding-inline-start: 2ch; +} + +pre.file { + background: yellow; + border: 10px black; + padding: 1em; +} + +div.scenario { + background: yellow; + padding: 1em; +} + +span.capture-word { + font-family: monospace; +} +span.capture-text { + font-family: monospace; +} +span.capture-int { + font-weight: bold; +} +span.capture-uint { + font-weight: bold; +} +span.capture-number { + font-weight: bold; +} +span.capture-file { + font-family: monospace; +} + +span.capture-path { + font-family: monospace; + font-weight: bold; +} diff --git a/src/doc.rs b/src/doc.rs index 07831c2..397bb75 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 { - 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())); } diff --git a/src/error.rs b/src/error.rs index 5c72879..7c63ca4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,10 @@ pub enum SubplotError { #[error("Document has {0} warnings.")] Warnings(usize), + /// Subplot could not find its CSS file. + #[error("failed to find CSS file: {0}")] + CssFileNotFound(PathBuf, #[source] std::io::Error), + /// Subplot could not find a file named as a bindings file. #[error("binding file could not be found: {0}")] BindingsFileNotFound(PathBuf, #[source] std::io::Error), -- cgit v1.2.1