diff --git a/lib/email/styles.rb b/lib/email/styles.rb index ba2b56fcaf6..cd561eb8b58 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -326,11 +326,10 @@ module Email def decorate_hashtags @fragment.search(".hashtag-cooked").each do |hashtag| - hashtag_text = hashtag.search("span").first - hashtag_text.add_next_sibling(<<~HTML) + hashtag.children.each(&:remove) + hashtag.add_child(<<~HTML) ##{hashtag["data-slug"]} HTML - hashtag_text.remove end end diff --git a/spec/lib/email/styles_spec.rb b/spec/lib/email/styles_spec.rb index 4a6f18bf0ef..62d31c4b479 100644 --- a/spec/lib/email/styles_spec.rb +++ b/spec/lib/email/styles_spec.rb @@ -104,6 +104,15 @@ RSpec.describe Email::Styles do expect(frag.at('a')).to be_present expect(frag.at('a')['href']).to eq(original_url) end + + it "replaces hashtag-cooked text with raw #hashtag" do + hashtag_html = "Dev Zone" + frag = html_fragment(hashtag_html) + expect(frag.at("a").text.chomp).to eq("#dev") + hashtag_html = "Dev Zone" + frag = html_fragment(hashtag_html) + expect(frag.at("a").text.chomp).to eq("#dev") + end end describe "rewriting protocol relative URLs to the forum" do