mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 00:08:53 +08:00
FIX: Do not cook icon with hashtags (#21676)
This commit makes some fundamental changes to how hashtag cooking and icon generation works in the new experimental hashtag autocomplete mode. Previously we cooked the appropriate SVG icon with the cooked hashtag, though this has proved inflexible especially for theming purposes. Instead, we now cook a data-ID attribute with the hashtag and add a new span as an icon placeholder. This is replaced on the client side with an icon (or a square span in the case of categories) on the client side via the decorateCooked API for posts and chat messages. This client side logic uses the generated hashtag, category, and channel CSS classes added in a previous commit. This is missing changes to the sidebar to use the new generated CSS classes and also colors and the split square for categories in the hashtag autocomplete menu -- I will tackle this in a separate PR so it is clearer.
This commit is contained in:
@ -178,13 +178,20 @@ RSpec.describe Oneboxer do
|
||||
expect(preview("/u/#{user.username}")).to include("Thunderland")
|
||||
end
|
||||
|
||||
it "includes hashtag HTML and icons" do
|
||||
it "includes hashtag HTML" do
|
||||
SiteSetting.enable_experimental_hashtag_autocomplete = true
|
||||
category = Fabricate(:category, slug: "random")
|
||||
Fabricate(:tag, name: "bug")
|
||||
tag = Fabricate(:tag, name: "bug")
|
||||
public_post = Fabricate(:post, raw: "This post has some hashtags, #random and #bug")
|
||||
expect(preview(public_post.url).chomp).to include(<<~HTML.chomp)
|
||||
<a class="hashtag-cooked" href="#{category.url}" data-type="category" data-slug="random"><svg class="fa d-icon d-icon-folder svg-icon svg-node"><use href="#folder"></use></svg>#{category.name}</a> and <a class="hashtag-cooked" href="/tag/bug" data-type="tag" data-slug="bug"><svg class="fa d-icon d-icon-tag svg-icon svg-node"><use href="#tag"></use></svg>bug</a>
|
||||
preview =
|
||||
Nokogiri::HTML5
|
||||
.fragment(preview(public_post.url).chomp)
|
||||
.css("blockquote")
|
||||
.inner_html
|
||||
.chomp
|
||||
.strip
|
||||
expect(preview).to eq(<<~HTML.chomp.strip)
|
||||
This post has some hashtags, <a class="hashtag-cooked" href="#{category.url}" data-type="category" data-slug="random" data-id="#{category.id}"><span class="hashtag-icon-placeholder"></span>#{category.name}</a> and <a class="hashtag-cooked" href="#{tag.url}" data-type="tag" data-slug="bug" data-id="#{tag.id}"><span class="hashtag-icon-placeholder"></span>#{tag.name}</a>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user