attr: fix concat of class attrs on union

This commit is contained in:
Noah Hellman 2023-05-31 20:38:50 +02:00
parent 3e4bb127c7
commit 109e030c71
2 changed files with 32 additions and 1 deletions

View file

@ -145,7 +145,7 @@ impl<'s> Attributes<'s> {
if let Some(attrs0) = &mut self.0 { if let Some(attrs0) = &mut self.0 {
if let Some(mut attrs1) = other.0 { if let Some(mut attrs1) = other.0 {
for (key, val) in attrs1.drain(..) { for (key, val) in attrs1.drain(..) {
if !attrs0.iter().any(|(k, _)| *k == key) { if key == "class" || !attrs0.iter().any(|(k, _)| *k == key) {
attrs0.push((key, val)); attrs0.push((key, val));
} }
} }

View file

@ -1776,6 +1776,37 @@ mod test {
); );
} }
#[test]
fn link_reference_attrs_class() {
test_parse!(
concat!(
"[text][tag]{.link}\n",
"\n",
"{.def}\n",
"[tag]: url\n",
"para\n",
),
Start(Paragraph, Attributes::new()),
Start(
Link("url".into(), LinkType::Span(SpanLinkType::Reference)),
[("class", "link"), ("class", "def")].into_iter().collect(),
),
Str("text".into()),
End(Link("url".into(), LinkType::Span(SpanLinkType::Reference))),
End(Paragraph),
Blankline,
Start(
LinkDefinition { label: "tag" },
[("class", "def")].into_iter().collect()
),
Str("url".into()),
End(LinkDefinition { label: "tag" }),
Start(Paragraph, Attributes::new()),
Str("para".into()),
End(Paragraph),
);
}
#[test] #[test]
fn autolink() { fn autolink() {
test_parse!( test_parse!(