Fix highlight class being used in rouge highlighting

pull/6435/head
Oliver Günther 6 years ago
parent ffff5cd258
commit 950515ebe4
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 1
      app/assets/stylesheets/content/_index.sass
  2. 8
      app/assets/stylesheets/content/_search.sass
  3. 9
      app/assets/stylesheets/openproject/_legacy.sass
  4. 2
      app/helpers/search_helper.rb
  5. 12
      spec/helpers/search_helper_spec.rb

@ -66,6 +66,7 @@
@import content/hide_section
@import content/hide_until_initialized
@import content/hidden
@import content/search
@import content/menus/_project_autocompletion
@import content/editor/index

@ -0,0 +1,8 @@
span.search-highlight
background-color: #FCFD8D
&.token-1
background-color: #faa
&.token-2
background-color: #afa
&.token-3
background-color: #aaf

@ -45,15 +45,6 @@ $version-summary-width: 380px
&:hover
opacity: 1
span.highlight
background-color: #FCFD8D
&.token-1
background-color: #faa
&.token-2
background-color: #afa
&.token-3
background-color: #aaf
.contextual
float: right
white-space: nowrap

@ -43,7 +43,7 @@ module SearchHelper
result << h(words.length > 100 ? "#{words.slice(0..44)} ... #{words.slice(-45..-1)}" : words)
else
t = (tokens.index(words.downcase) || 0) % 4
result << content_tag('span', h(words), class: "highlight token-#{t}")
result << content_tag('span', h(words), class: "search-highlight token-#{t}")
end
end
result.html_safe

@ -59,7 +59,7 @@ describe 'search/index', type: :helper do
context 'with single token' do
let(:tokens) { %w(token) }
let(:title) { 'This is a token.' }
let(:expected_title) { 'This is a <span class="highlight token-0">token</span>.' }
let(:expected_title) { 'This is a <span class="search-highlight token-0">token</span>.' }
it { is_expected.to eq expected_title }
end
@ -67,7 +67,7 @@ describe 'search/index', type: :helper do
context 'with multiple tokens' do
let(:tokens) { %w(token another) }
let(:title) { 'This is a token and another token.' }
let(:expected_title) { 'This is a <span class="highlight token-0">token</span> and <span class="highlight token-1">another</span> <span class="highlight token-0">token</span>.' }
let(:expected_title) { 'This is a <span class="search-highlight token-0">token</span> and <span class="search-highlight token-1">another</span> <span class="search-highlight token-0">token</span>.' }
it { is_expected.to eq expected_title }
end
@ -75,7 +75,7 @@ describe 'search/index', type: :helper do
context 'with huge content' do
let(:tokens) { %w(token) }
let(:title) { (('1234567890' * 100) + ' token ') * 100 }
let(:highlighted_token) { '<span class="highlight token-0">token</span>' }
let(:highlighted_token) { '<span class="search-highlight token-0">token</span>' }
it { expect(highlighted_title).to include highlighted_token }
@ -87,7 +87,7 @@ describe 'search/index', type: :helper do
context 'with multibyte title' do
let(:tokens) { %w(token) }
let(:title) { ('й' * 200) + ' token ' + ('й' * 200) }
let(:expected_title) { ('й' * 45) + ' ... ' + ('й' * 44) + ' <span class="highlight token-0">token</span> ' + ('й' * 44) + ' ... ' + ('й' * 45) }
let(:expected_title) { ('й' * 45) + ' ... ' + ('й' * 44) + ' <span class="search-highlight token-0">token</span> ' + ('й' * 44) + ' ... ' + ('й' * 45) }
it { is_expected.to eq expected_title }
end
@ -102,7 +102,7 @@ describe 'search/index', type: :helper do
let(:first) { 'This is a token' }
let(:second) { 'I have some token for you' }
let(:titles) { [first, second] }
let(:first_highlighted) { 'This is a <span class="highlight token-0">token</span>' }
let(:first_highlighted) { 'This is a <span class="search-highlight token-0">token</span>' }
it { is_expected.to eq first_highlighted }
end
@ -111,7 +111,7 @@ describe 'search/index', type: :helper do
let(:first) { 'This is a book' }
let(:second) { 'I have some token for you' }
let(:titles) { [first, second] }
let(:second_highlighted) { 'I have some <span class="highlight token-0">token</span> for you' }
let(:second_highlighted) { 'I have some <span class="search-highlight token-0">token</span> for you' }
it { is_expected.to eq second_highlighted }
end

Loading…
Cancel
Save