diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-10-08 09:47:31 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-10-09 18:27:23 +0300 |
commit | 3c59880e533af059299a4c5848d32d9d623073b1 (patch) | |
tree | d40e863210a3f4ce34f74f8584ca4fc24f9958a9 /src | |
parent | 5d4e16236a3f6a6e726273a6bec344de1b5f0645 (diff) | |
download | subplot-3c59880e533af059299a4c5848d32d9d623073b1.tar.gz |
fix: drop unwanted, custom attributes that Subplot uses
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/html.rs | 9 | ||||
-rw-r--r-- | src/md.rs | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/html.rs b/src/html.rs index 3232724..23579f9 100644 --- a/src/html.rs +++ b/src/html.rs @@ -281,6 +281,13 @@ impl Element { self.attrs.push(attr); } + /// Drop all attributes with a given name. + pub fn drop_attributes(&mut self, unwanted: &[&str]) { + for uw in unwanted { + self.attrs.retain(|a| a.name() != *uw); + } + } + /// Append a new child to the element. pub fn push_child(&mut self, child: Content) { self.children.push(child); @@ -508,7 +515,7 @@ impl Attributes { if let Some(new_value) = attr.value() { if let Some(old_value) = self.attrs.get_mut(attr.name()) { assert!(!old_value.is_empty()); - old_value.push(','); + old_value.push(' '); old_value.push_str(new_value); } else { self.attrs.insert(attr.name().into(), new_value.into()); @@ -324,6 +324,7 @@ fn extract_scenario(e: &[StructureElement]) -> Result<(Option<Scenario>, usize), } mod typeset { + const UNWANTED_ATTRS: &[&str] = &["add-newline"]; use crate::html::{Attribute, Content, Element, ElementTag}; // use crate::parser::parse_scenario_snippet; @@ -338,7 +339,7 @@ mod typeset { use base64::prelude::{Engine as _, BASE64_STANDARD}; pub(crate) fn typeset_element(e: &Element) -> Result<Element, SubplotError> { - match e.tag() { + let new = match e.tag() { ElementTag::Pre if e.has_attr("class", "scenario") => typeset_scenario(e), ElementTag::Pre if e.has_attr("class", "file") => typeset_file(e), ElementTag::Pre if e.has_attr("class", "example") => typeset_example(e), @@ -360,7 +361,10 @@ mod typeset { } Ok(new) } - } + }; + let mut new = new?; + new.drop_attributes(UNWANTED_ATTRS); + Ok(new) } fn typeset_scenario(e: &Element) -> Result<Element, SubplotError> { |