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
Léo-Paul Géneau
gitlab-ce
Commits
fe78984f
Commit
fe78984f
authored
Jun 02, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actually ignore references in code blocks etc.
parent
5a1aa49b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
49 deletions
+51
-49
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+12
-15
lib/gitlab/reference_extractor.rb
lib/gitlab/reference_extractor.rb
+17
-34
lib/redcarpet/render/gitlab_html.rb
lib/redcarpet/render/gitlab_html.rb
+2
-0
spec/lib/gitlab/reference_extractor_spec.rb
spec/lib/gitlab/reference_extractor_spec.rb
+20
-0
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
fe78984f
...
...
@@ -41,20 +41,7 @@ module GitlabMarkdownHelper
fragment
.
to_html
.
html_safe
end
def
markdown
(
text
,
options
=
{})
unless
@markdown
&&
options
==
@options
@options
=
options
options
.
merge!
(
# Handled further down the line by Gitlab::Markdown::SanitizationFilter
escape_html:
false
)
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
rend
=
Redcarpet
::
Render
::
GitlabHTML
.
new
(
self
,
user_color_scheme_class
,
options
)
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
@markdown
=
Redcarpet
::
Markdown
.
new
(
rend
,
MARKDOWN_OPTIONS
=
{
no_intra_emphasis:
true
,
tables:
true
,
fenced_code_blocks:
true
,
...
...
@@ -63,7 +50,17 @@ module GitlabMarkdownHelper
space_after_headers:
true
,
superscript:
true
,
footnotes:
true
)
}.
freeze
def
markdown
(
text
,
options
=
{})
unless
@markdown
&&
options
==
@options
@options
=
options
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
rend
=
Redcarpet
::
Render
::
GitlabHTML
.
new
(
self
,
user_color_scheme_class
,
options
)
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
@markdown
=
Redcarpet
::
Markdown
.
new
(
rend
,
MARKDOWN_OPTIONS
)
end
@markdown
.
render
(
text
).
html_safe
...
...
lib/gitlab/reference_extractor.rb
View file @
fe78984f
module
Gitlab
# Extract possible GFM references from an arbitrary String for further processing.
class
ReferenceExtractor
attr_accessor
:project
,
:current_user
,
:references
attr_accessor
:project
,
:current_user
def
initialize
(
project
,
current_user
=
nil
)
@project
=
project
...
...
@@ -9,48 +9,31 @@ module Gitlab
end
def
analyze
(
text
)
@_text
=
text
.
dup
references
.
clear
@text
=
markdown
.
render
(
text
.
dup
)
end
def
users
result
=
pipeline_result
(
:user
)
result
.
uniq
%i(user label issue merge_request snippet commit commit_range)
.
each
do
|
type
|
define_method
(
"
#{
type
}
s"
)
do
references
[
type
]
end
def
labels
result
=
pipeline_result
(
:label
)
result
.
uniq
end
def
issues
# TODO (rspeicher): What about external issues?
result
=
pipeline_result
(
:issue
)
result
.
uniq
end
private
def
merge_requests
result
=
pipeline_result
(
:merge_request
)
result
.
uniq
def
markdown
@markdown
||=
Redcarpet
::
Markdown
.
new
(
Redcarpet
::
Render
::
HTML
,
GitlabMarkdownHelper
::
MARKDOWN_OPTIONS
)
end
def
snippet
s
result
=
pipeline_result
(
:snippet
)
result
.
uniq
end
def
reference
s
@references
||=
Hash
.
new
do
|
references
,
type
|
type
=
type
.
to_sym
return
references
[
type
]
if
references
.
has_key?
(
type
)
def
commits
result
=
pipeline_result
(
:commit
)
result
.
uniq
references
[
type
]
=
pipeline_result
(
type
).
uniq
end
def
commit_ranges
result
=
pipeline_result
(
:commit_range
)
result
.
uniq
end
private
# Instantiate and call HTML::Pipeline with a single reference filter type,
# returning the result
#
...
...
@@ -69,7 +52,7 @@ module Gitlab
}
pipeline
=
HTML
::
Pipeline
.
new
([
filter
],
context
)
result
=
pipeline
.
call
(
@
_
text
)
result
=
pipeline
.
call
(
@text
)
result
[
:references
][
filter_type
]
end
...
...
lib/redcarpet/render/gitlab_html.rb
View file @
fe78984f
...
...
@@ -10,6 +10,8 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
@options
=
options
.
dup
@options
.
reverse_merge!
(
# Handled further down the line by Gitlab::Markdown::SanitizationFilter
escape_html:
false
project:
@template
.
instance_variable_get
(
"@project"
)
)
...
...
spec/lib/gitlab/reference_extractor_spec.rb
View file @
fe78984f
...
...
@@ -16,6 +16,26 @@ describe Gitlab::ReferenceExtractor do
expect
(
subject
.
users
).
to
eq
([
@u_foo
,
@u_bar
,
@u_offteam
])
end
it
'ignores user mentions inside specific elements'
do
@u_foo
=
create
(
:user
,
username:
'foo'
)
@u_bar
=
create
(
:user
,
username:
'bar'
)
@u_offteam
=
create
(
:user
,
username:
'offteam'
)
project
.
team
<<
[
@u_foo
,
:reporter
]
project
.
team
<<
[
@u_bar
,
:guest
]
subject
.
analyze
(
%Q{
Inline code: `@foo`
Code block:
```
@bar
```
}
)
expect
(
subject
.
users
).
to
eq
([])
end
it
'accesses valid issue objects'
do
@i0
=
create
(
:issue
,
project:
project
)
@i1
=
create
(
:issue
,
project:
project
)
...
...
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