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
5733bdb7
Commit
5733bdb7
authored
May 29, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix link_to_gfm with only a reference having the incorrect link
Closes #1721
parent
51888f74
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
3 deletions
+22
-3
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+16
-3
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+6
-0
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
5733bdb7
require
'nokogiri'
module
GitlabMarkdownHelper
module
GitlabMarkdownHelper
include
Gitlab
::
Markdown
include
Gitlab
::
Markdown
...
@@ -21,11 +23,22 @@ module GitlabMarkdownHelper
...
@@ -21,11 +23,22 @@ module GitlabMarkdownHelper
gfm_body
=
gfm
(
escaped_body
,
{},
html_options
)
gfm_body
=
gfm
(
escaped_body
,
{},
html_options
)
gfm_body
.
gsub!
(
%r{<a.*?>.*?</a>}m
)
do
|
match
|
fragment
=
Nokogiri
::
XML
::
DocumentFragment
.
parse
(
gfm_body
)
"</a>
#{
match
}#{
link_to
(
""
,
url
,
html_options
)[
0
..-
5
]
}
"
# "</a>".length +1
if
fragment
.
children
.
size
==
1
&&
fragment
.
children
[
0
].
name
==
'a'
# Fragment has only one node, and it's a link generated by `gfm`.
# Replace it with our requested link.
text
=
fragment
.
children
[
0
].
text
fragment
.
children
[
0
].
replace
(
link_to
(
text
,
url
,
html_options
))
else
# Traverse the fragment's first generation of children looking for pure
# text, wrapping anything found in the requested link
fragment
.
children
.
each
do
|
node
|
next
unless
node
.
text?
node
.
replace
(
link_to
(
node
.
text
,
url
,
html_options
))
end
end
end
link_to
(
gfm_body
.
html_safe
,
url
,
html_options
)
fragment
.
to_html
.
html_safe
end
end
def
markdown
(
text
,
options
=
{})
def
markdown
(
text
,
options
=
{})
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
5733bdb7
...
@@ -94,6 +94,12 @@ describe GitlabMarkdownHelper do
...
@@ -94,6 +94,12 @@ describe GitlabMarkdownHelper do
expect
(
link_to_gfm
(
actual
,
commit_path
)).
expect
(
link_to_gfm
(
actual
,
commit_path
)).
to
match
(
'<h1>test</h1>'
)
to
match
(
'<h1>test</h1>'
)
end
end
it
'ignores reference links when they are the entire body'
do
text
=
issues
[
0
].
to_reference
act
=
link_to_gfm
(
text
,
'/foo'
)
expect
(
act
).
to
eq
%Q(<a href="/foo">
#{
issues
[
0
].
to_reference
}
</a>)
end
end
end
describe
'#render_wiki_content'
do
describe
'#render_wiki_content'
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