fix(mdhtml): oops now really no attrs on closing tags

This commit is contained in:
əlemi 2024-05-30 11:58:35 +02:00
parent e1d1e3d470
commit eba5a31a93
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -23,15 +23,14 @@ impl TokenSink for Sink {
) { return TokenSinkResult::Continue } // skip this tag
self.0.push('<');
if !tag.self_closing && matches!(tag.kind, TagKind::EndTag) {
self.0.push('/');
}
self.0.push_str(tag.name.as_ref());
if tag.self_closing {
self.0.push('/');
} else {
if !matches!(tag.kind, TagKind::EndTag) {
match tag.name.as_ref() {
"img" => for attr in tag.attrs {
match attr.name.local.as_ref() {
@ -42,6 +41,7 @@ impl TokenSink for Sink {
}
},
"a" => {
let any_attr = !tag.attrs.is_empty();
for attr in tag.attrs {
match attr.name.local.as_ref() {
"href" => self.0.push_str(&format!(" href=\"{}\"", attr.value.as_ref())),
@ -49,12 +49,18 @@ impl TokenSink for Sink {
_ => {},
}
}
self.0.push_str(" rel=\"nofollow noreferrer\" target=\"_blank\"");
if any_attr {
self.0.push_str(" rel=\"nofollow noreferrer\" target=\"_blank\"");
}
},
_ => {},
}
}
if tag.self_closing {
self.0.push('/');
}
self.0.push('>');
},
Token::CharacterTokens(txt) => self.0.push_str(txt.as_ref()),