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
Kazuhiko Shiozaki
gitlab-ce
Commits
15bee7e0
Commit
15bee7e0
authored
Feb 18, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Markdown relative links to files with anchors.
parent
0da0d800
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+5
-4
spec/helpers/gitlab_markdown_helper_spec.rb
spec/helpers/gitlab_markdown_helper_spec.rb
+13
-1
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
15bee7e0
...
@@ -110,7 +110,7 @@ module GitlabMarkdownHelper
...
@@ -110,7 +110,7 @@ module GitlabMarkdownHelper
end
end
def
link_to_ignore?
(
link
)
def
link_to_ignore?
(
link
)
if
link
=~
/\#\w+/
if
link
=~
/\
A\
#\w+/
# ignore anchors like <a href="#my-header">
# ignore anchors like <a href="#my-header">
true
true
else
else
...
@@ -122,10 +122,11 @@ module GitlabMarkdownHelper
...
@@ -122,10 +122,11 @@ module GitlabMarkdownHelper
[
"http://"
,
"https://"
,
"ftp://"
,
"mailto:"
]
[
"http://"
,
"https://"
,
"ftp://"
,
"mailto:"
]
end
end
def
rebuild_path
(
path
)
def
rebuild_path
(
file_path
)
path
.
gsub!
(
/(#.*)/
,
""
)
file_path
=
file_path
.
dup
file_path
.
gsub!
(
/(#.*)/
,
""
)
id
=
$1
||
""
id
=
$1
||
""
file_path
=
relative_file_path
(
path
)
file_path
=
relative_file_path
(
file_
path
)
file_path
=
sanitize_slashes
(
file_path
)
file_path
=
sanitize_slashes
(
file_path
)
[
[
...
...
spec/helpers/gitlab_markdown_helper_spec.rb
View file @
15bee7e0
...
@@ -584,7 +584,7 @@ describe GitlabMarkdownHelper do
...
@@ -584,7 +584,7 @@ describe GitlabMarkdownHelper do
it
"should leave code blocks untouched"
do
it
"should leave code blocks untouched"
do
allow
(
helper
).
to
receive
(
:user_color_scheme_class
).
and_return
(
:white
)
allow
(
helper
).
to
receive
(
:user_color_scheme_class
).
and_return
(
:white
)
target_html
=
"<pre class=
\"
code highlight white plaintext
\"
><code>some code from $
40
\n
here too
\n
</code></pre>
\n
"
target_html
=
"<pre class=
\"
code highlight white plaintext
\"
><code>some code from $
#{
snippet
.
id
}
\n
here too
\n
</code></pre>
\n
"
expect
(
helper
.
markdown
(
"
\n
some code from $
#{
snippet
.
id
}
\n
here too
\n
"
)).
expect
(
helper
.
markdown
(
"
\n
some code from $
#{
snippet
.
id
}
\n
here too
\n
"
)).
to
eq
(
target_html
)
to
eq
(
target_html
)
...
@@ -638,6 +638,18 @@ describe GitlabMarkdownHelper do
...
@@ -638,6 +638,18 @@ describe GitlabMarkdownHelper do
expect
(
markdown
(
actual
)).
to
match
(
expected
)
expect
(
markdown
(
actual
)).
to
match
(
expected
)
end
end
it
"should handle relative urls for a file in master with an anchor"
do
actual
=
"[GitLab API doc](doc/api/README.md#section)
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/blob/
#{
@ref
}
/doc/api/README.md#section
\"
>GitLab API doc</a></p>
\n
"
expect
(
markdown
(
actual
)).
to
match
(
expected
)
end
it
"should not handle relative urls for the current file with an anchor"
do
actual
=
"[GitLab API doc](#section)
\n
"
expected
=
"<p><a href=
\"
#section
\"
>GitLab API doc</a></p>
\n
"
expect
(
markdown
(
actual
)).
to
match
(
expected
)
end
it
"should handle relative urls for a directory in master"
do
it
"should handle relative urls for a directory in master"
do
actual
=
"[GitLab API doc](doc/api)
\n
"
actual
=
"[GitLab API doc](doc/api)
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/tree/
#{
@ref
}
/doc/api
\"
>GitLab API doc</a></p>
\n
"
expected
=
"<p><a href=
\"
/
#{
project
.
path_with_namespace
}
/tree/
#{
@ref
}
/doc/api
\"
>GitLab API doc</a></p>
\n
"
...
...
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