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
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'
require
'html/pipeline/gitlab'
module
Gitlab
module
Gitlab
# Custom parser for GitLab-flavored Markdown
# Custom parser for GitLab-flavored Markdown
...
@@ -61,19 +60,24 @@ module Gitlab
...
@@ -61,19 +60,24 @@ module Gitlab
reference_only_path:
true
reference_only_path:
true
)
)
markdown_context
=
{
pipeline
=
HTML
::
Pipeline
.
new
(
filters
)
context
=
{
# SanitizationFilter
whitelist:
sanitization_whitelist
,
# EmojiFilter
asset_root:
Gitlab
.
config
.
gitlab
.
url
,
asset_root:
Gitlab
.
config
.
gitlab
.
url
,
asset_host:
Gitlab
::
Application
.
config
.
asset_host
,
asset_host:
Gitlab
::
Application
.
config
.
asset_host
,
whitelist:
sanitization_whitelist
,
reference_class:
html_options
[
:class
],
# ReferenceFilter
only_path:
options
[
:reference_only_path
],
current_user:
current_user
,
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
=
pipeline
.
call
(
text
,
context
)
result
=
markdown_pipeline
.
call
(
text
,
markdown_context
)
save_options
=
0
save_options
=
0
if
options
[
:xhtml
]
if
options
[
:xhtml
]
...
@@ -91,7 +95,7 @@ module Gitlab
...
@@ -91,7 +95,7 @@ module Gitlab
private
private
#
Custom filters for html-pipeline:
#
Filters used in our pipeline
#
#
# SanitizationFilter should come first so that all generated reference HTML
# SanitizationFilter should come first so that all generated reference HTML
# goes through untouched.
# goes through untouched.
...
@@ -101,6 +105,8 @@ module Gitlab
...
@@ -101,6 +105,8 @@ module Gitlab
[
[
HTML
::
Pipeline
::
SanitizationFilter
,
HTML
::
Pipeline
::
SanitizationFilter
,
Gitlab
::
Markdown
::
EmojiFilter
,
Gitlab
::
Markdown
::
UserReferenceFilter
,
Gitlab
::
Markdown
::
UserReferenceFilter
,
Gitlab
::
Markdown
::
IssueReferenceFilter
,
Gitlab
::
Markdown
::
IssueReferenceFilter
,
Gitlab
::
Markdown
::
ExternalIssueReferenceFilter
,
Gitlab
::
Markdown
::
ExternalIssueReferenceFilter
,
...
@@ -109,8 +115,6 @@ module Gitlab
...
@@ -109,8 +115,6 @@ module Gitlab
Gitlab
::
Markdown
::
CommitRangeReferenceFilter
,
Gitlab
::
Markdown
::
CommitRangeReferenceFilter
,
Gitlab
::
Markdown
::
CommitReferenceFilter
,
Gitlab
::
Markdown
::
CommitReferenceFilter
,
Gitlab
::
Markdown
::
LabelReferenceFilter
,
Gitlab
::
Markdown
::
LabelReferenceFilter
,
HTML
::
Pipeline
::
Gitlab
::
GitlabEmojiFilter
]
]
end
end
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
fca62467
...
@@ -10,15 +10,12 @@ describe GitlabMarkdownHelper do
...
@@ -10,15 +10,12 @@ describe GitlabMarkdownHelper do
end
end
let!
(
:project
)
{
create
(
:project
)
}
let!
(
:project
)
{
create
(
:project
)
}
let
(
:empty_project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
,
username:
'gfm'
)
}
let
(
:user
)
{
create
(
:user
,
username:
'gfm'
)
}
let
(
:commit
)
{
project
.
repository
.
commit
}
let
(
:commit
)
{
project
.
repository
.
commit
}
let
(
:earlier_commit
){
project
.
repository
.
commit
(
"HEAD~2"
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
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.
# Helper expects a current_user method.
let
(
:current_user
)
{
user
}
let
(
:current_user
)
{
user
}
...
@@ -60,53 +57,6 @@ describe GitlabMarkdownHelper do
...
@@ -60,53 +57,6 @@ describe GitlabMarkdownHelper do
end
end
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
context
'parse_tasks: true'
do
before
(
:all
)
do
before
(
:all
)
do
@source_text_asterisk
=
<<-
EOT
.
strip_heredoc
@source_text_asterisk
=
<<-
EOT
.
strip_heredoc
...
@@ -339,28 +289,6 @@ describe GitlabMarkdownHelper do
...
@@ -339,28 +289,6 @@ describe GitlabMarkdownHelper do
expect
(
markdown
(
"#
#{
issue
.
iid
}
"
)).
to
include
(
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
))
expect
(
markdown
(
"#
#{
issue
.
iid
}
"
)).
to
include
(
namespace_project_issue_path
(
project
.
namespace
,
project
,
issue
))
end
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 -----------------------------------------------------------
# RELATIVE URLS -----------------------------------------------------------
# TODO (rspeicher): These belong in a relative link filter spec
# TODO (rspeicher): These belong in a relative link filter spec
...
@@ -448,8 +376,8 @@ describe GitlabMarkdownHelper do
...
@@ -448,8 +376,8 @@ describe GitlabMarkdownHelper do
# TODO (rspeicher): This should be a context of relative link specs, not its own thing
# TODO (rspeicher): This should be a context of relative link specs, not its own thing
describe
'markdown for empty repository'
do
describe
'markdown for empty repository'
do
before
do
before
do
@project
=
empty_project
@project
=
create
(
:empty_project
)
@repository
=
empty_
project
.
repository
@repository
=
@
project
.
repository
end
end
it
"should not touch relative urls"
do
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