Only highlight search results under the highlighting size limit
We should use this limit everywhere, but especially in project search results, where we could be highlighting very long single lines. (Typical examples: minified JavaScript, and JSON data files.)
This commit is contained in:
parent
82f4564fb7
commit
91939161aa
3 changed files with 14 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
module BlobHelper
|
||||
def highlight(blob_name, blob_content, repository: nil, plain: false)
|
||||
plain ||= blob_content.length > Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE
|
||||
highlighted = Gitlab::Highlight.highlight(blob_name, blob_content, plain: plain, repository: repository)
|
||||
|
||||
raw %(<pre class="code highlight"><code>#{highlighted}</code></pre>)
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Only highlight search results under the highlighting size limit
|
||||
merge_request: 16462
|
||||
author:
|
||||
type: performance
|
|
@ -22,6 +22,13 @@ describe BlobHelper do
|
|||
expect(result).to eq(%[<pre class="code highlight"><code><span id="LC1" class="line" lang="">:type "assem"))</span></code></pre>])
|
||||
end
|
||||
|
||||
it 'returns plaintext for long blobs' do
|
||||
stub_const('Blob::MAXIMUM_TEXT_HIGHLIGHT_SIZE', 1)
|
||||
result = helper.highlight(blob_name, blob_content)
|
||||
|
||||
expect(result).to eq(%[<pre class="code highlight"><code><span id="LC1" class="line" lang="">(make-pathname :defaults name</span>\n<span id="LC2" class="line" lang="">:type "assem"))</span></code></pre>])
|
||||
end
|
||||
|
||||
it 'highlights single block' do
|
||||
expected = %Q[<pre class="code highlight"><code><span id="LC1" class="line" lang="common_lisp"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span>
|
||||
<span id="LC2" class="line" lang="common_lisp"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span></code></pre>]
|
||||
|
|
Loading…
Reference in a new issue