From b4bd7c845fad34951f568188205e16727e1d1007 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 29 May 2024 05:04:59 +0200 Subject: [PATCH] fix(mdhtml): dont add stuff on closing tags --- mdhtml/src/lib.rs | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/mdhtml/src/lib.rs b/mdhtml/src/lib.rs index 485d238..503b34f 100644 --- a/mdhtml/src/lib.rs +++ b/mdhtml/src/lib.rs @@ -29,31 +29,32 @@ impl TokenSink for Sink { 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 { 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('>'); }, Token::CharacterTokens(txt) => self.0.push_str(txt.as_ref()),