fix(mdhtml): dont add stuff on closing tags

This commit is contained in:
əlemi 2024-05-29 05:04:59 +02:00
parent b097e4a725
commit b4bd7c845f
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -29,31 +29,32 @@ impl TokenSink for Sink {
self.0.push_str(tag.name.as_ref()); self.0.push_str(tag.name.as_ref());
match tag.name.as_ref() {
"img" => for attr in tag.attrs {
match attr.name.local.as_ref() {
"src" => self.0.push_str(&format!(" src=\"{}\"", attr.value.as_ref())),
"title" => self.0.push_str(&format!(" title=\"{}\"", attr.value.as_ref())),
"alt" => self.0.push_str(&format!(" alt=\"{}\"", attr.value.as_ref())),
_ => {},
}
},
"a" => {
for attr in tag.attrs {
match attr.name.local.as_ref() {
"href" => self.0.push_str(&format!(" href=\"{}\"", attr.value.as_ref())),
"title" => self.0.push_str(&format!(" title=\"{}\"", attr.value.as_ref())),
_ => {},
}
}
self.0.push_str(" rel=\"nofollow noreferrer\" target=\"_blank\"");
},
_ => {},
}
if tag.self_closing { if tag.self_closing {
self.0.push('/'); self.0.push('/');
} else {
match tag.name.as_ref() {
"img" => for attr in tag.attrs {
match attr.name.local.as_ref() {
"src" => self.0.push_str(&format!(" src=\"{}\"", attr.value.as_ref())),
"title" => self.0.push_str(&format!(" title=\"{}\"", attr.value.as_ref())),
"alt" => self.0.push_str(&format!(" alt=\"{}\"", attr.value.as_ref())),
_ => {},
}
},
"a" => {
for attr in tag.attrs {
match attr.name.local.as_ref() {
"href" => self.0.push_str(&format!(" href=\"{}\"", attr.value.as_ref())),
"title" => self.0.push_str(&format!(" title=\"{}\"", attr.value.as_ref())),
_ => {},
}
}
self.0.push_str(" rel=\"nofollow noreferrer\" target=\"_blank\"");
},
_ => {},
}
} }
self.0.push('>'); self.0.push('>');
}, },
Token::CharacterTokens(txt) => self.0.push_str(txt.as_ref()), Token::CharacterTokens(txt) => self.0.push_str(txt.as_ref()),