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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
fca62467
Commit
fca62467
authored
Apr 16, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Gitlab::Markdown to use the
🆕
EmojiFilter
✨
Removes emoji-centric tests from GFM specs
💥
parent
4ced630f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
86 deletions
+18
-86
lib/gitlab/markdown.rb
lib/gitlab/markdown.rb
+16
-12
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+2
-74
No files found.
lib/gitlab/markdown.rb
View file @
fca62467
require
'html/pipeline'
require
'html/pipeline/gitlab'
module
Gitlab
# Custom parser for GitLab-flavored Markdown
...
...
@@ -61,19 +60,24 @@ module Gitlab
reference_only_path:
true
)
markdown_context
=
{
pipeline
=
HTML
::
Pipeline
.
new
(
filters
)
context
=
{
# SanitizationFilter
whitelist:
sanitization_whitelist
,
# EmojiFilter
asset_root:
Gitlab
.
config
.
gitlab
.
url
,
asset_host:
Gitlab
::
Application
.
config
.
asset_host
,
whitelist:
sanitization_whitelist
,
reference_class:
html_options
[
:class
],
only_path:
options
[
:reference_only_path
],
# ReferenceFilter
current_user:
current_user
,
project:
project
only_path:
options
[
:reference_only_path
],
project:
project
,
reference_class:
html_options
[
:class
]
}
markdown_pipeline
=
HTML
::
Pipeline
::
Gitlab
.
new
(
filters
).
pipeline
result
=
markdown_pipeline
.
call
(
text
,
markdown_context
)
result
=
pipeline
.
call
(
text
,
context
)
save_options
=
0
if
options
[
:xhtml
]
...
...
@@ -91,7 +95,7 @@ module Gitlab
private
#
Custom filters for html-pipeline:
#
Filters used in our pipeline
#
# SanitizationFilter should come first so that all generated reference HTML
# goes through untouched.
...
...
@@ -101,6 +105,8 @@ module Gitlab
[
HTML
::
Pipeline
::
SanitizationFilter
,
Gitlab
::
Markdown
::
EmojiFilter
,
Gitlab
::
Markdown
::
UserReferenceFilter
,
Gitlab
::
Markdown
::
IssueReferenceFilter
,
Gitlab
::
Markdown
::
ExternalIssueReferenceFilter
,
...
...
@@ -109,8 +115,6 @@ module Gitlab
Gitlab
::
Markdown
::
CommitRangeReferenceFilter
,
Gitlab
::
Markdown
::
CommitReferenceFilter
,
Gitlab
::
Markdown
::
LabelReferenceFilter
,
HTML
::
Pipeline
::
Gitlab
::
GitlabEmojiFilter
]
end
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
fca62467
...
...
@@ -10,15 +10,12 @@ describe GitlabMarkdownHelper do
end
let!
(
:project
)
{
create
(
:project
)
}
let
(
:empty_project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
,
username:
'gfm'
)
}
let
(
:commit
)
{
project
.
repository
.
commit
}
let
(
:earlier_commit
){
project
.
repository
.
commit
(
"HEAD~2"
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
project:
project
)
}
let
(
:member
)
{
project
.
project_members
.
where
(
user_id:
user
).
first
}
# Helper expects a current_user method.
let
(
:current_user
)
{
user
}
...
...
@@ -60,53 +57,6 @@ describe GitlabMarkdownHelper do
end
end
# TODO (rspeicher): These tests belong in the emoji filter spec
describe
"emoji"
do
it
"matches at the start of a string"
do
expect
(
gfm
(
":+1:"
)).
to
match
(
/<img/
)
end
it
"matches at the end of a string"
do
expect
(
gfm
(
"This gets a :-1:"
)).
to
match
(
/<img/
)
end
it
"matches with adjacent text"
do
expect
(
gfm
(
"+1 (:+1:)"
)).
to
match
(
/<img/
)
end
it
"has a title attribute"
do
expect
(
gfm
(
":-1:"
)).
to
match
(
/title=":-1:"/
)
end
it
"has an alt attribute"
do
expect
(
gfm
(
":-1:"
)).
to
match
(
/alt=":-1:"/
)
end
it
"has an emoji class"
do
expect
(
gfm
(
":+1:"
)).
to
match
(
'class="emoji"'
)
end
it
"sets height and width"
do
actual
=
gfm
(
":+1:"
)
expect
(
actual
).
to
match
(
/width="20"/
)
expect
(
actual
).
to
match
(
/height="20"/
)
end
it
"keeps whitespace intact"
do
expect
(
gfm
(
'This deserves a :+1: big time.'
)).
to
match
(
/deserves a <img.+> big time/
)
end
it
"ignores invalid emoji"
do
expect
(
gfm
(
":invalid-emoji:"
)).
not_to
match
(
/<img/
)
end
it
"should work independent of reference links (i.e. without @project being set)"
do
@project
=
nil
expect
(
gfm
(
":+1:"
)).
to
match
(
/<img/
)
end
end
context
'parse_tasks: true'
do
before
(
:all
)
do
@source_text_asterisk
=
<<-
EOT
.
strip_heredoc
...
...
@@ -339,28 +289,6 @@ describe GitlabMarkdownHelper do
expect
(
markdown
(
"#
#{
issue
.
iid
}
"
)).
to
include
(
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
))
end
# EMOJI -------------------------------------------------------------------
it
"should generate absolute urls for emoji"
do
# TODO (rspeicher): Why isn't this with the emoji tests?
expect
(
markdown
(
':smile:'
)).
to
(
include
(
%(src="#{Gitlab.config.gitlab.url}/assets/emoji/#{Emoji.emoji_filename('smile')}.png)
)
)
end
it
"should generate absolute urls for emoji if relative url is present"
do
# TODO (rspeicher): Why isn't this with the emoji tests?
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:url
).
and_return
(
'http://localhost/gitlab/root'
)
expect
(
markdown
(
":smile:"
)).
to
include
(
"src=
\"
http://localhost/gitlab/root/assets/emoji/
#{
Emoji
.
emoji_filename
(
'smile'
)
}
.png"
)
end
it
"should generate absolute urls for emoji if asset_host is present"
do
# TODO (rspeicher): Why isn't this with the emoji tests?
allow
(
Gitlab
::
Application
.
config
).
to
receive
(
:asset_host
).
and_return
(
"https://cdn.example.com"
)
ActionView
::
Base
.
any_instance
.
stub_chain
(
:config
,
:asset_host
).
and_return
(
"https://cdn.example.com"
)
expect
(
markdown
(
":smile:"
)).
to
include
(
"src=
\"
https://cdn.example.com/assets/emoji/
#{
Emoji
.
emoji_filename
(
'smile'
)
}
.png"
)
end
# RELATIVE URLS -----------------------------------------------------------
# TODO (rspeicher): These belong in a relative link filter spec
...
...
@@ -448,8 +376,8 @@ describe GitlabMarkdownHelper do
# TODO (rspeicher): This should be a context of relative link specs, not its own thing
describe
'markdown for empty repository'
do
before
do
@project
=
empty_project
@repository
=
empty_
project
.
repository
@project
=
create
(
:empty_project
)
@repository
=
@
project
.
repository
end
it
"should not touch relative urls"
do
...
...
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