diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-10-30 18:55:47 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-10-30 19:12:15 +0200 |
commit | ad26e9d84925532ae5522aad8def5d764fe0ffbe (patch) | |
tree | 0fd717f54feddf2975ff134d2f32c343dc2cc28b | |
parent | 5a84e1bde773bdc782c1db5a633ef8765f220253 (diff) | |
download | subplot-ad26e9d84925532ae5522aad8def5d764fe0ffbe.tar.gz |
feat: allow adding CSS URLs to HTML output
This is in the meta data field "css_urls".
Signed-off-by: Lars Wirzenius <liw@liw.fi>
Sponsored-by: author
-rw-r--r-- | src/doc.rs | 8 | ||||
-rw-r--r-- | src/metadata.rs | 14 | ||||
-rw-r--r-- | subplot.md | 34 |
3 files changed, 56 insertions, 0 deletions
@@ -160,6 +160,14 @@ impl Document { } head.push_child(Content::Elt(css)); + for css_url in self.meta.css_urls() { + let mut link = Element::new(ElementTag::Link); + link.push_attribute(Attribute::new("rel", "stylesheet")); + link.push_attribute(Attribute::new("type", "text/css")); + link.push_attribute(Attribute::new("href", css_url)); + head.push_child(Content::Elt(link)); + } + self.meta.set_date(date.into()); let mut body_content = Element::new(crate::html::ElementTag::Div); diff --git a/src/metadata.rs b/src/metadata.rs index dc28ac4..e382840 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -51,6 +51,7 @@ pub struct YamlMetadata { #[serde(default)] impls: BTreeMap<String, Vec<PathBuf>>, css_embed: Option<Vec<PathBuf>>, + css_urls: Option<Vec<String>>, } impl YamlMetadata { @@ -169,6 +170,7 @@ pub struct Metadata { /// Extra class names which should be considered 'correct' for this document classes: Vec<String>, css_embed: Vec<String>, + css_urls: Vec<String>, } #[derive(Debug)] @@ -221,6 +223,12 @@ impl Metadata { } } + let css_urls = if let Some(urls) = &yaml.css_urls { + urls.clone() + } else { + vec![] + }; + let meta = Self { basedir: basedir.as_ref().to_path_buf(), title: yaml.title().into(), @@ -232,6 +240,7 @@ impl Metadata { impls, classes, css_embed, + css_urls, }; trace!("metadata: {:#?}", meta); @@ -297,6 +306,11 @@ impl Metadata { pub fn css_embed(&self) -> impl Iterator<Item = &str> { self.css_embed.iter().map(Deref::deref) } + + /// List of CSS urls to add to the HTML output. + pub fn css_urls(&self) -> impl Iterator<Item = &str> { + self.css_urls.iter().map(Deref::deref) + } } impl DocumentImpl { @@ -3683,6 +3683,40 @@ html { } ~~~ +### CSS URLs + +_Requirement:_ The user can specify CSS URLs to add in the HTML +output. + +Justification: We want to allow users to specify non-embedded CSS. + +~~~scenario +given file css-urls.subplot +given file css-urls.md +given file b.yaml +given an installed subplot +when I run subplot docgen css-urls.subplot -o foo.html +then file foo.html contains "https://example.com/flushing.css" +~~~ + +~~~{#css-urls.subplot .file .yaml .numberLines} +title: Embedded CSS +markdowns: + - css-urls.md +bindings: + - b.yaml +css_urls: + - https://example.com/flushing.css +~~~ + +~~~~~~{#css-urls.md .file .markdown .numberLines} +# This is a title + +~~~scenario +given precondition +~~~ +~~~~~~ + ## Running Subplot |