FIX: Exclude automatic anchors from search index (#16396)
This commit is contained in:
parent
6e9a068e44
commit
df10a27067
|
@ -337,6 +337,10 @@ class SearchIndexer
|
|||
if node["href"] == node.text || MENTION_CLASSES.include?(node["class"])
|
||||
node.remove_attribute("href")
|
||||
end
|
||||
|
||||
if node["class"] == "anchor" && node["href"].starts_with?("#")
|
||||
node.remove_attribute("href")
|
||||
end
|
||||
end
|
||||
|
||||
html_scrubber = new
|
||||
|
|
|
@ -42,6 +42,12 @@ describe SearchIndexer do
|
|||
expect(scrubbed).to eq("http://meta.discourse.org/ link")
|
||||
end
|
||||
|
||||
it 'ignores autogenerated link anchors' do
|
||||
html = "<a class='anchor' href='#something-special'>something special</a>"
|
||||
scrubbed = SearchIndexer::HtmlScrubber.scrub(html)
|
||||
expect(scrubbed).to eq("something special")
|
||||
end
|
||||
|
||||
it 'extracts @username from mentions' do
|
||||
html = '<p><a class="mention" href="/u/%E7%8B%AE%E5%AD%90">@狮子</a> <a class="mention" href="/u/foo">@foo</a></p>'
|
||||
scrubbed = SearchIndexer::HtmlScrubber.scrub(html)
|
||||
|
|
Loading…
Reference in New Issue