From eba5a31a9382447e84c38fb1c2ad8ecae6844220 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 30 May 2024 11:58:35 +0200 Subject: [PATCH] fix(mdhtml): oops now really no attrs on closing tags --- mdhtml/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mdhtml/src/lib.rs b/mdhtml/src/lib.rs index 503b34f8..a7a03683 100644 --- a/mdhtml/src/lib.rs +++ b/mdhtml/src/lib.rs @@ -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()),