Commit 7809c533 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'fj-add-plain-data-field-to-snippet-blob-type-endpoint' into 'master'

Add plain_highlighted_data field to SnippetBlobType

See merge request gitlab-org/gitlab!24856
parents 1e72da63 54d889a6
...@@ -12,6 +12,10 @@ module Types ...@@ -12,6 +12,10 @@ module Types
description: 'Blob highlighted data', description: 'Blob highlighted data',
null: true null: true
field :plain_highlighted_data, GraphQL::STRING_TYPE,
description: 'Blob plain highlighted data',
null: true
field :raw_path, GraphQL::STRING_TYPE, field :raw_path, GraphQL::STRING_TYPE,
description: 'Blob raw content endpoint path', description: 'Blob raw content endpoint path',
null: false null: false
......
...@@ -4,11 +4,13 @@ class SnippetBlobPresenter < BlobPresenter ...@@ -4,11 +4,13 @@ class SnippetBlobPresenter < BlobPresenter
def highlighted_data def highlighted_data
return if blob.binary? return if blob.binary?
if blob.rich_viewer&.partial_name == 'markup' highlight(plain: false)
blob.rendered_markup end
else
highlight def plain_highlighted_data
end return if blob.binary?
highlight(plain: true)
end end
def raw_path def raw_path
......
---
title: Add plain_highlighted_data field to SnippetBlobType
merge_request: 24856
author:
type: changed
...@@ -6777,6 +6777,11 @@ type SnippetBlob { ...@@ -6777,6 +6777,11 @@ type SnippetBlob {
""" """
path: String path: String
"""
Blob plain highlighted data
"""
plainHighlightedData: String
""" """
Blob raw content endpoint path Blob raw content endpoint path
""" """
......
...@@ -7612,6 +7612,20 @@ ...@@ -7612,6 +7612,20 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "plainHighlightedData",
"description": "Blob plain highlighted data",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "rawPath", "name": "rawPath",
"description": "Blob raw content endpoint path", "description": "Blob raw content endpoint path",
......
...@@ -1071,6 +1071,7 @@ Represents the snippet blob ...@@ -1071,6 +1071,7 @@ Represents the snippet blob
| `mode` | String | Blob mode | | `mode` | String | Blob mode |
| `name` | String | Blob name | | `name` | String | Blob name |
| `path` | String | Blob path | | `path` | String | Blob path |
| `plainHighlightedData` | String | Blob plain highlighted data |
| `rawPath` | String! | Blob raw content endpoint path | | `rawPath` | String! | Blob raw content endpoint path |
| `richViewer` | SnippetBlobViewer | Blob content rich viewer | | `richViewer` | SnippetBlobViewer | Blob content rich viewer |
| `simpleViewer` | SnippetBlobViewer! | Blob content simple viewer | | `simpleViewer` | SnippetBlobViewer! | Blob content simple viewer |
......
...@@ -4,10 +4,9 @@ require 'spec_helper' ...@@ -4,10 +4,9 @@ require 'spec_helper'
describe GitlabSchema.types['SnippetBlob'] do describe GitlabSchema.types['SnippetBlob'] do
it 'has the correct fields' do it 'has the correct fields' do
expected_fields = [:highlighted_data, :raw_path, expected_fields = [:highlighted_data, :plain_highlighted_data,
:size, :binary, :name, :path, :raw_path, :size, :binary, :name, :path,
:simple_viewer, :rich_viewer, :simple_viewer, :rich_viewer, :mode]
:mode]
is_expected.to have_graphql_fields(*expected_fields) is_expected.to have_graphql_fields(*expected_fields)
end end
......
...@@ -18,7 +18,7 @@ describe SnippetBlobPresenter do ...@@ -18,7 +18,7 @@ describe SnippetBlobPresenter do
snippet.file_name = 'test.md' snippet.file_name = 'test.md'
snippet.content = '*foo*' snippet.content = '*foo*'
expect(subject).to eq '<p data-sourcepos="1:1-1:5" dir="auto"><em>foo</em></p>' expect(subject).to eq '<span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span>'
end end
it 'returns syntax highlighted content' do it 'returns syntax highlighted content' do
...@@ -33,7 +33,41 @@ describe SnippetBlobPresenter do ...@@ -33,7 +33,41 @@ describe SnippetBlobPresenter do
snippet.file_name = 'test' snippet.file_name = 'test'
snippet.content = 'foo' snippet.content = 'foo'
expect(described_class.new(snippet.blob).highlighted_data).to eq '<span id="LC1" class="line" lang="plaintext">foo</span>' expect(subject).to eq '<span id="LC1" class="line" lang="plaintext">foo</span>'
end
end
describe '#plain_highlighted_data' do
let(:snippet) { build(:personal_snippet) }
subject { described_class.new(snippet.blob).plain_highlighted_data }
it 'returns nil when the snippet blob is binary' do
allow(snippet.blob).to receive(:binary?).and_return(true)
expect(subject).to be_nil
end
it 'returns plain content when snippet file is markup' do
snippet.file_name = 'test.md'
snippet.content = '*foo*'
expect(subject).to eq '<span id="LC1" class="line" lang="">*foo*</span>'
end
it 'returns plain syntax content' do
snippet.file_name = 'test.rb'
snippet.content = 'class Foo;end'
expect(subject)
.to eq '<span id="LC1" class="line" lang="">class Foo;end</span>'
end
it 'returns plain text highlighted content' do
snippet.file_name = 'test'
snippet.content = 'foo'
expect(subject).to eq '<span id="LC1" class="line" lang="">foo</span>'
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment