Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fc5bdb4a
Commit
fc5bdb4a
authored
Jul 10, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
0e5016cc
ef348618
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
5 deletions
+80
-5
app/helpers/markup_helper.rb
app/helpers/markup_helper.rb
+8
-4
spec/helpers/markup_helper_spec.rb
spec/helpers/markup_helper_spec.rb
+72
-1
No files found.
app/helpers/markup_helper.rb
View file @
fc5bdb4a
...
...
@@ -3,7 +3,7 @@
require
'nokogiri'
module
MarkupHelper
include
ActionView
::
Helpers
::
T
ag
Helper
include
ActionView
::
Helpers
::
T
ext
Helper
include
::
Gitlab
::
ActionViewOutput
::
Context
def
plain?
(
filename
)
...
...
@@ -154,9 +154,7 @@ module MarkupHelper
elsif
asciidoc?
(
file_name
)
asciidoc_unsafe
(
text
,
context
)
elsif
plain?
(
file_name
)
content_tag
:pre
,
class:
'plain-readme'
do
text
end
plain_unsafe
(
text
)
else
other_markup_unsafe
(
file_name
,
text
,
context
)
end
...
...
@@ -271,6 +269,12 @@ module MarkupHelper
Gitlab
::
Asciidoc
.
render
(
text
,
context
)
end
def
plain_unsafe
(
text
)
content_tag
:pre
,
class:
'plain-readme'
do
text
end
end
def
other_markup_unsafe
(
file_name
,
text
,
context
=
{})
Gitlab
::
OtherMarkup
.
render
(
file_name
,
text
,
context
)
end
...
...
spec/helpers/markup_helper_spec.rb
View file @
fc5bdb4a
...
...
@@ -268,7 +268,7 @@ describe MarkupHelper do
end
end
describe
'markup'
do
describe
'
#
markup'
do
let
(
:content
)
{
'Noël'
}
it
'preserves encoding'
do
...
...
@@ -302,6 +302,77 @@ describe MarkupHelper do
end
end
describe
'#markup_unsafe'
do
subject
{
helper
.
markup_unsafe
(
file_name
,
text
,
context
)
}
let
(
:file_name
)
{
'foo.bar'
}
let
(
:text
)
{
'Noël'
}
let
(
:project_base
)
{
build
(
:project
,
:repository
)
}
let
(
:context
)
{
{
project:
project_base
}
}
context
'when text is missing'
do
let
(
:text
)
{
nil
}
it
'returns an empty string'
do
is_expected
.
to
eq
(
''
)
end
end
context
'when file is a markdown file'
do
let
(
:file_name
)
{
'foo.md'
}
it
'returns html (rendered by Banzai)'
do
expected_html
=
'<p data-sourcepos="1:1-1:5" dir="auto">Noël</p>'
expect
(
Banzai
).
to
receive
(
:render
).
with
(
text
,
context
)
{
expected_html
}
is_expected
.
to
eq
(
expected_html
)
end
context
'when renderer returns an error'
do
before
do
allow
(
Banzai
).
to
receive
(
:render
).
and_raise
(
"An error"
)
end
it
'returns html (rendered by ActionView:TextHelper)'
do
is_expected
.
to
eq
(
'<p>Noël</p>'
)
end
end
end
context
'when file is asciidoc file'
do
let
(
:file_name
)
{
'foo.adoc'
}
it
'returns html (rendered by Gitlab::Asciidoc)'
do
expected_html
=
"<div>
\n
<p>Noël</p>
\n
</div>"
expect
(
Gitlab
::
Asciidoc
).
to
receive
(
:render
).
with
(
text
,
context
)
{
expected_html
}
is_expected
.
to
eq
(
expected_html
)
end
end
context
'when file is a regular text file'
do
let
(
:file_name
)
{
'foo.txt'
}
it
'returns html (rendered by ActionView::TagHelper)'
do
is_expected
.
to
eq
(
'<pre class="plain-readme">Noël</pre>'
)
end
end
context
'when file has an unknown type'
do
let
(
:file_name
)
{
'foo'
}
it
'returns html (rendered by Gitlab::OtherMarkup)'
do
expected_html
=
'Noël'
expect
(
Gitlab
::
OtherMarkup
).
to
receive
(
:render
).
with
(
file_name
,
text
,
context
)
{
expected_html
}
is_expected
.
to
eq
(
expected_html
)
end
end
end
describe
'#first_line_in_markdown'
do
shared_examples_for
'common markdown examples'
do
let
(
:project_base
)
{
build
(
:project
,
:repository
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment