Commit 493c7a614782381a5267939d5b5cf7bdb61daf3a

Authored by Dmitriy Zaporozhets
2 parents 66c4a7db 656d9548

Merge branch 'links_within_same_repo' into 'master'

Relative links within one system

When using relative links in md in repository file it will only link within the repository.
When using relative links in md in wiki page, it will only link to wiki pages.
app/helpers/gitlab_markdown_helper.rb
... ... @@ -63,8 +63,7 @@ module GitlabMarkdownHelper
63 63 # project_path_with_namespace - namespace/projectname, eg. gitlabhq/gitlabhq
64 64 # ref - name of the branch or reference, eg. stable
65 65 # requested_path - path of request, eg. doc/api/README.md, used in special case when path is pointing to the .md file were the original request is coming from
66   - # wiki - whether the markdown is from wiki or not
67   - def create_relative_links(text, project, ref, requested_path, wiki = false)
  66 + def create_relative_links(text, project, ref, requested_path)
68 67 @path_to_satellite = project.satellite.path
69 68 project_path_with_namespace = project.path_with_namespace
70 69 paths = extract_paths(text)
... ... @@ -134,12 +133,12 @@ module GitlabMarkdownHelper
134 133 end
135 134  
136 135 # Checks if the path exists in the repo
137   - # eg. checks if doc/README.md exists, if it doesn't then it is a wiki link
  136 + # eg. checks if doc/README.md exists, if not then link to blob
138 137 def path_with_ref(path, ref)
139 138 if file_exists?(path)
140 139 "#{local_path(path)}/#{correct_ref(ref)}"
141 140 else
142   - "wikis"
  141 + "blob/#{correct_ref(ref)}"
143 142 end
144 143 end
145 144  
... ...
doc/markdown/markdown.md
... ... @@ -8,23 +8,38 @@ Table of Contents
8 8 **[GitLab Flavored Markdown](#gitlab-flavored-markdown-gfm)**
9 9  
10 10 [Newlines](#newlines)
  11 +
11 12 [Multiple underscores in words](#multiple-underscores-in-words)
  13 +
12 14 [URL autolinking](#url-autolinking)
  15 +
13 16 [Code and Syntax Highlighting](#code-and-syntax-highlighting)
  17 +
14 18 [Emoji](#emoji)
  19 +
15 20 [Special GitLab references](#special-gitlab-references)
16 21  
  22 +
17 23 **[Standard Markdown](#standard-markdown)**
18 24  
19 25 [Headers](#headers)
  26 +
20 27 [Emphasis](#emphasis)
  28 +
21 29 [Lists](#lists)
  30 +
22 31 [Links](#links)
  32 +
23 33 [Images](#images)
  34 +
24 35 [Blockquotes](#blockquotes)
  36 +
25 37 [Inline HTML](#inline-html)
  38 +
26 39 [Horizontal Rule](#horizontal-rule)
  40 +
27 41 [Line Breaks](#line-breaks)
  42 +
28 43 [Tables](#tables)
29 44  
30 45 **[References](#references)**
... ... @@ -33,7 +48,8 @@ Table of Contents
33 48  
34 49 GitLab Flavored Markdown (GFM)
35 50 ==============================
36   -For GitLab we developed something we call "GitLab Flavored Markdown" (GFM). It extends the standard Markdown in a few significant ways to add some useful functionality.
  51 +For GitLab we developed something we call "GitLab Flavored Markdown" (GFM).
  52 +It extends the standard Markdown in a few significant ways to add some useful functionality.
37 53  
38 54 You can use GFM in
39 55  
... ... @@ -51,16 +67,20 @@ Please see the [github-markup gem readme](https://github.com/gitlabhq/markup#mar
51 67  
52 68 Newlines
53 69 --------
54   -The biggest difference that GFM introduces is in the handling of linebreaks. With traditional Markdown you can hard wrap paragraphs of text and they will be combined into a single paragraph. We find this to be the cause of a huge number of unintentional formatting errors. GFM treats newlines in paragraph-like content as real line breaks, which is probably what you intended.
  70 +GFM honors the markdown specification in how [paragraphs and line breaks are handled](http://daringfireball.net/projects/markdown/syntax#p).
55 71  
56   -The next paragraph contains two phrases separated by a single newline character:
  72 +A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines.:
57 73  
58 74 Roses are red
59 75 Violets are blue
60 76  
  77 + Sugar is sweet
  78 +
61 79 Roses are red
62 80 Violets are blue
63 81  
  82 +Sugar is sweet
  83 +
64 84 Multiple underscores in words
65 85 -----------------------------
66 86 It is not reasonable to italicize just _part_ of a word, especially when you're dealing with code and names that often appear with multiple underscores. Therefore, GFM ignores multiple underscores in words.
... ... @@ -319,13 +339,13 @@ Strikethrough uses two tildes. ~~Scratch this.~~
319 339  
320 340 ## Links
321 341  
322   -There are two ways to create links.
  342 +There are two ways to create links, inline-style and reference-style.
323 343  
324 344 [I'm an inline-style link](https://www.google.com)
325 345  
326 346 [I'm a reference-style link][Arbitrary case-insensitive reference text]
327 347  
328   - [I'm a relative reference to a repository file](../blob/master/LICENSE)
  348 + [I'm a relative reference to a repository file](LICENSE)
329 349  
330 350 [You can use numbers for reference-style link definitions][1]
331 351  
... ... @@ -341,7 +361,7 @@ There are two ways to create links.
341 361  
342 362 [I'm a reference-style link][Arbitrary case-insensitive reference text]
343 363  
344   -[I'm a relative reference to a repository file](../blob/master/LICENSE)
  364 +[I'm a relative reference to a repository file](LICENSE)
345 365  
346 366 [You can use numbers for reference-style link definitions][1]
347 367  
... ... @@ -353,6 +373,15 @@ Some text to show that the reference links can follow later.
353 373 [1]: http://slashdot.org
354 374 [link text itself]: http://www.reddit.com
355 375  
  376 +**Note**
  377 +
  378 +Relative links do not allow referencing project files in a wiki page or wiki page in a project file.
  379 +The reason for this is that, in GitLab, wiki is always a separate git repository. For example:
  380 +
  381 +`[I'm a reference-style link][style]`
  382 +
  383 +will point the link to `wikis/style` when the link is inside of a wiki markdown file.
  384 +
356 385 ## Images
357 386  
358 387 Here's our logo (hover to see the title text):
... ... @@ -365,15 +394,15 @@ Some text to show that the reference links can follow later.
365 394  
366 395 [logo]: assets/logo-white.png
367 396  
368   -Here's our logo (hover to see the title text):
  397 +Here's our logo:
369 398  
370 399 Inline-style:
371   -![alt text](/assets/logo-white.png "Logo Title Text 1")
  400 +![alt text](/assets/logo-white.png)
372 401  
373 402 Reference-style:
374 403 ![alt text][logo]
375 404  
376   -[logo]: /assets/logo-white.png "Logo Title Text 2"
  405 +[logo]: /assets/logo-white.png
377 406  
378 407 ## Blockquotes
379 408  
... ...
features/steps/project/markdown_render.rb
... ... @@ -203,7 +203,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
203 203 end
204 204  
205 205 And 'I add various links to the wiki page' do
206   - fill_in "wiki[content]", with: "[test](test)\n[GitLab API doc](doc/api/README.md)\n[Rake tasks](doc/raketasks)\n"
  206 + fill_in "wiki[content]", with: "[test](test)\n[GitLab API doc](api)\n[Rake tasks](raketasks)\n"
207 207 fill_in "wiki[message]", with: "Adding links to wiki"
208 208 click_button "Create page"
209 209 end
... ... @@ -242,8 +242,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
242 242 end
243 243  
244 244 Then 'I see Gitlab API document' do
245   - current_path.should == project_blob_path(@project, "master/doc/api/README.md")
246   - page.should have_content "Status codes"
  245 + current_path.should == project_wiki_path(@project, "api")
  246 + page.should have_content "Editing"
247 247 end
248 248  
249 249 And 'I click on Rake tasks link' do
... ... @@ -251,9 +251,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
251 251 end
252 252  
253 253 Then 'I see Rake tasks directory' do
254   - current_path.should == project_tree_path(@project, "master/doc/raketasks")
255   - page.should have_content "backup_restore.md"
256   - page.should have_content "maintenance.md"
  254 + current_path.should == project_wiki_path(@project, "raketasks")
  255 + page.should have_content "Editing"
257 256 end
258 257  
259 258 Given 'I go directory which contains README file' do
... ...
lib/redcarpet/render/gitlab_html.rb
... ... @@ -46,8 +46,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
46 46 end
47 47  
48 48 def preprocess(full_document)
49   - if @project
50   - h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?)
  49 + if is_wiki?
  50 + full_document
  51 + elsif @project
  52 + h.create_relative_links(full_document, @project, @ref, @request_path)
51 53 else
52 54 full_document
53 55 end
... ...
spec/helpers/gitlab_markdown_helper_spec.rb
... ... @@ -440,12 +440,6 @@ describe GitlabMarkdownHelper do
440 440 markdown(actual).should match(expected)
441 441 end
442 442  
443   - it "should handle wiki urls" do
444   - actual = "[Link](test/link)\n"
445   - expected = "<p><a href=\"/#{project.path_with_namespace}/wikis/test/link\">Link</a></p>\n"
446   - markdown(actual).should match(expected)
447   - end
448   -
449 443 it "should handle relative urls in reference links for a file in master" do
450 444 actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n"
451 445 expected = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\n"
... ...