Fix bug rendering BlobType markdown data

parent 66acda99
...@@ -8,11 +8,11 @@ module Types ...@@ -8,11 +8,11 @@ module Types
description 'Represents the snippet blob' description 'Represents the snippet blob'
present_using SnippetBlobPresenter present_using SnippetBlobPresenter
field :highlighted_data, GraphQL::STRING_TYPE, field :rich_data, GraphQL::STRING_TYPE,
description: 'Blob highlighted data', description: 'Blob highlighted data',
null: true null: true
field :plain_highlighted_data, GraphQL::STRING_TYPE, field :plain_data, GraphQL::STRING_TYPE,
description: 'Blob plain highlighted data', description: 'Blob plain highlighted data',
null: true null: true
......
# frozen_string_literal: true # frozen_string_literal: true
class SnippetBlobPresenter < BlobPresenter class SnippetBlobPresenter < BlobPresenter
def highlighted_data def rich_data
return if blob.binary? return if blob.binary?
highlight(plain: false) if markup?
blob.rendered_markup
else
highlight(plain: false)
end
end end
def plain_highlighted_data def plain_data
return if blob.binary? return if blob.binary?
highlight(plain: true) highlight(plain: !markup?)
end end
def raw_path def raw_path
...@@ -23,6 +27,10 @@ class SnippetBlobPresenter < BlobPresenter ...@@ -23,6 +27,10 @@ class SnippetBlobPresenter < BlobPresenter
private private
def markup?
blob.rich_viewer&.partial_name == 'markup'
end
def snippet def snippet
blob.snippet blob.snippet
end end
......
---
title: Fix bug rendering BlobType markdown data
merge_request: 24960
author:
type: fixed
...@@ -6757,11 +6757,6 @@ type SnippetBlob { ...@@ -6757,11 +6757,6 @@ type SnippetBlob {
""" """
binary: Boolean! binary: Boolean!
"""
Blob highlighted data
"""
highlightedData: String
""" """
Blob mode Blob mode
""" """
...@@ -6780,13 +6775,18 @@ type SnippetBlob { ...@@ -6780,13 +6775,18 @@ type SnippetBlob {
""" """
Blob plain highlighted data Blob plain highlighted data
""" """
plainHighlightedData: String plainData: String
""" """
Blob raw content endpoint path Blob raw content endpoint path
""" """
rawPath: String! rawPath: String!
"""
Blob highlighted data
"""
richData: String
""" """
Blob content rich viewer Blob content rich viewer
""" """
......
...@@ -7556,20 +7556,6 @@ ...@@ -7556,20 +7556,6 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "highlightedData",
"description": "Blob highlighted data",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "mode", "name": "mode",
"description": "Blob mode", "description": "Blob mode",
...@@ -7613,7 +7599,7 @@ ...@@ -7613,7 +7599,7 @@
"deprecationReason": null "deprecationReason": null
}, },
{ {
"name": "plainHighlightedData", "name": "plainData",
"description": "Blob plain highlighted data", "description": "Blob plain highlighted data",
"args": [ "args": [
...@@ -7644,6 +7630,20 @@ ...@@ -7644,6 +7630,20 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "richData",
"description": "Blob highlighted data",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "richViewer", "name": "richViewer",
"description": "Blob content rich viewer", "description": "Blob content rich viewer",
......
...@@ -1067,12 +1067,12 @@ Represents the snippet blob ...@@ -1067,12 +1067,12 @@ Represents the snippet blob
| Name | Type | Description | | Name | Type | Description |
| --- | ---- | ---------- | | --- | ---- | ---------- |
| `binary` | Boolean! | Shows whether the blob is binary | | `binary` | Boolean! | Shows whether the blob is binary |
| `highlightedData` | String | Blob highlighted data |
| `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 | | `plainData` | String | Blob plain highlighted data |
| `rawPath` | String! | Blob raw content endpoint path | | `rawPath` | String! | Blob raw content endpoint path |
| `richData` | String | Blob highlighted data |
| `richViewer` | SnippetBlobViewer | Blob content rich viewer | | `richViewer` | SnippetBlobViewer | Blob content rich viewer |
| `simpleViewer` | SnippetBlobViewer! | Blob content simple viewer | | `simpleViewer` | SnippetBlobViewer! | Blob content simple viewer |
| `size` | Int! | Blob size | | `size` | Int! | Blob size |
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ 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, :plain_highlighted_data, expected_fields = [:rich_data, :plain_data,
:raw_path, :size, :binary, :name, :path, :raw_path, :size, :binary, :name, :path,
:simple_viewer, :rich_viewer, :mode] :simple_viewer, :rich_viewer, :mode]
......
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
require 'spec_helper' require 'spec_helper'
describe SnippetBlobPresenter do describe SnippetBlobPresenter do
describe '#highlighted_data' do describe '#rich_data' do
let(:snippet) { build(:personal_snippet) } let(:snippet) { build(:personal_snippet) }
subject { described_class.new(snippet.blob).highlighted_data } subject { described_class.new(snippet.blob).rich_data }
it 'returns nil when the snippet blob is binary' do it 'returns nil when the snippet blob is binary' do
allow(snippet.blob).to receive(:binary?).and_return(true) allow(snippet.blob).to receive(:binary?).and_return(true)
...@@ -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 '<span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span>' expect(subject).to eq '<p data-sourcepos="1:1-1:5" dir="auto"><em>foo</em></p>'
end end
it 'returns syntax highlighted content' do it 'returns syntax highlighted content' do
...@@ -37,10 +37,10 @@ describe SnippetBlobPresenter do ...@@ -37,10 +37,10 @@ describe SnippetBlobPresenter do
end end
end end
describe '#plain_highlighted_data' do describe '#plain_data' do
let(:snippet) { build(:personal_snippet) } let(:snippet) { build(:personal_snippet) }
subject { described_class.new(snippet.blob).plain_highlighted_data } subject { described_class.new(snippet.blob).plain_data }
it 'returns nil when the snippet blob is binary' do it 'returns nil when the snippet blob is binary' do
allow(snippet.blob).to receive(:binary?).and_return(true) allow(snippet.blob).to receive(:binary?).and_return(true)
...@@ -52,7 +52,7 @@ describe SnippetBlobPresenter do ...@@ -52,7 +52,7 @@ describe SnippetBlobPresenter do
snippet.file_name = 'test.md' snippet.file_name = 'test.md'
snippet.content = '*foo*' snippet.content = '*foo*'
expect(subject).to eq '<span id="LC1" class="line" lang="">*foo*</span>' expect(subject).to eq '<span id="LC1" class="line" lang="markdown"><span class="ge">*foo*</span></span>'
end end
it 'returns plain syntax content' do it 'returns plain syntax content' do
......
...@@ -67,7 +67,8 @@ describe 'Creating a Snippet' do ...@@ -67,7 +67,8 @@ describe 'Creating a Snippet' do
it 'returns the created Snippet' do it 'returns the created Snippet' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(content) expect(mutation_response['snippet']['blob']['richData']).to match(content)
expect(mutation_response['snippet']['blob']['plainData']).to match(content)
expect(mutation_response['snippet']['title']).to eq(title) expect(mutation_response['snippet']['title']).to eq(title)
expect(mutation_response['snippet']['description']).to eq(description) expect(mutation_response['snippet']['description']).to eq(description)
expect(mutation_response['snippet']['fileName']).to eq(file_name) expect(mutation_response['snippet']['fileName']).to eq(file_name)
...@@ -92,7 +93,8 @@ describe 'Creating a Snippet' do ...@@ -92,7 +93,8 @@ describe 'Creating a Snippet' do
it 'returns the created Snippet' do it 'returns the created Snippet' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(content) expect(mutation_response['snippet']['blob']['richData']).to match(content)
expect(mutation_response['snippet']['blob']['plainData']).to match(content)
expect(mutation_response['snippet']['title']).to eq(title) expect(mutation_response['snippet']['title']).to eq(title)
expect(mutation_response['snippet']['description']).to eq(description) expect(mutation_response['snippet']['description']).to eq(description)
expect(mutation_response['snippet']['fileName']).to eq(file_name) expect(mutation_response['snippet']['fileName']).to eq(file_name)
......
...@@ -56,7 +56,8 @@ describe 'Updating a Snippet' do ...@@ -56,7 +56,8 @@ describe 'Updating a Snippet' do
it 'returns the updated Snippet' do it 'returns the updated Snippet' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(updated_content) expect(mutation_response['snippet']['blob']['richData']).to match(updated_content)
expect(mutation_response['snippet']['blob']['plainData']).to match(updated_content)
expect(mutation_response['snippet']['title']).to eq(updated_title) expect(mutation_response['snippet']['title']).to eq(updated_title)
expect(mutation_response['snippet']['description']).to eq(updated_description) expect(mutation_response['snippet']['description']).to eq(updated_description)
expect(mutation_response['snippet']['fileName']).to eq(updated_file_name) expect(mutation_response['snippet']['fileName']).to eq(updated_file_name)
...@@ -77,7 +78,8 @@ describe 'Updating a Snippet' do ...@@ -77,7 +78,8 @@ describe 'Updating a Snippet' do
it 'returns the Snippet with its original values' do it 'returns the Snippet with its original values' do
post_graphql_mutation(mutation, current_user: current_user) post_graphql_mutation(mutation, current_user: current_user)
expect(mutation_response['snippet']['blob']['highlightedData']).to match(original_content) expect(mutation_response['snippet']['blob']['richData']).to match(original_content)
expect(mutation_response['snippet']['blob']['plainData']).to match(original_content)
expect(mutation_response['snippet']['title']).to eq(original_title) expect(mutation_response['snippet']['title']).to eq(original_title)
expect(mutation_response['snippet']['description']).to eq(original_description) expect(mutation_response['snippet']['description']).to eq(original_description)
expect(mutation_response['snippet']['fileName']).to eq(original_file_name) expect(mutation_response['snippet']['fileName']).to eq(original_file_name)
......
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