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
iv
gitlab-ce
Commits
70f828cd
Commit
70f828cd
authored
Oct 09, 2013
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split.
parent
1eabd9df
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
app/helpers/gitlab_markdown_helper.rb
app/helpers/gitlab_markdown_helper.rb
+30
-7
No files found.
app/helpers/gitlab_markdown_helper.rb
View file @
70f828cd
...
...
@@ -60,16 +60,39 @@ module GitlabMarkdownHelper
end
def
create_relative_links
(
text
,
project_path_with_namespace
,
ref
,
wiki
=
false
)
links
=
text
.
split
(
"
\n
"
).
map
{
|
a
|
a
.
scan
(
/\]\(([^(]+)\)/
)
}.
reject
{
|
b
|
b
.
empty?
}.
flatten
.
reject
{
|
c
|
c
.
include?
(
"http"
||
"www"
)}
links
=
extract_paths
(
text
)
links
.
each
do
|
string
|
new_link
=
[
project_path_with_namespace
,
wiki
?
"wikis"
:
"blob"
,
ref
,
string
].
compact
.
join
(
"/"
)
new_link
=
new_link
(
project_path_with_namespace
,
string
,
ref
)
text
.
gsub!
(
"](
#{
string
}
)"
,
"](/
#{
new_link
}
)"
)
end
text
end
def
extract_paths
(
text
)
text
.
split
(
"
\n
"
).
map
{
|
a
|
a
.
scan
(
/\]\(([^(]+)\)/
)
}.
reject
{
|
b
|
b
.
empty?
}.
flatten
.
reject
{
|
c
|
c
.
include?
(
"http"
||
"www"
)}
end
def
new_link
(
path_with_namespace
,
string
,
ref
)
[
path_with_namespace
,
path
(
string
,
ref
),
string
].
compact
.
join
(
"/"
)
end
def
path
(
string
,
ref
)
if
File
.
exists?
(
Rails
.
root
.
join
(
string
))
"
#{
local_path
(
string
)
}
/
#{
correct_ref
(
ref
)
}
"
else
"wikis"
end
end
def
local_path
(
string
)
File
.
directory?
(
Rails
.
root
.
join
(
string
))
?
"tree"
:
"blob"
end
def
correct_ref
(
ref
)
ref
?
ref
:
'master'
end
end
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