Commit 493c7a61 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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.
parents 66c4a7db 656d9548
...@@ -63,8 +63,7 @@ module GitlabMarkdownHelper ...@@ -63,8 +63,7 @@ module GitlabMarkdownHelper
# project_path_with_namespace - namespace/projectname, eg. gitlabhq/gitlabhq # project_path_with_namespace - namespace/projectname, eg. gitlabhq/gitlabhq
# ref - name of the branch or reference, eg. stable # ref - name of the branch or reference, eg. stable
# 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 # 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
# wiki - whether the markdown is from wiki or not def create_relative_links(text, project, ref, requested_path)
def create_relative_links(text, project, ref, requested_path, wiki = false)
@path_to_satellite = project.satellite.path @path_to_satellite = project.satellite.path
project_path_with_namespace = project.path_with_namespace project_path_with_namespace = project.path_with_namespace
paths = extract_paths(text) paths = extract_paths(text)
...@@ -134,12 +133,12 @@ module GitlabMarkdownHelper ...@@ -134,12 +133,12 @@ module GitlabMarkdownHelper
end end
# Checks if the path exists in the repo # Checks if the path exists in the repo
# eg. checks if doc/README.md exists, if it doesn't then it is a wiki link # eg. checks if doc/README.md exists, if not then link to blob
def path_with_ref(path, ref) def path_with_ref(path, ref)
if file_exists?(path) if file_exists?(path)
"#{local_path(path)}/#{correct_ref(ref)}" "#{local_path(path)}/#{correct_ref(ref)}"
else else
"wikis" "blob/#{correct_ref(ref)}"
end end
end end
......
...@@ -8,23 +8,38 @@ Table of Contents ...@@ -8,23 +8,38 @@ Table of Contents
**[GitLab Flavored Markdown](#gitlab-flavored-markdown-gfm)** **[GitLab Flavored Markdown](#gitlab-flavored-markdown-gfm)**
[Newlines](#newlines) [Newlines](#newlines)
[Multiple underscores in words](#multiple-underscores-in-words) [Multiple underscores in words](#multiple-underscores-in-words)
[URL autolinking](#url-autolinking) [URL autolinking](#url-autolinking)
[Code and Syntax Highlighting](#code-and-syntax-highlighting) [Code and Syntax Highlighting](#code-and-syntax-highlighting)
[Emoji](#emoji) [Emoji](#emoji)
[Special GitLab references](#special-gitlab-references) [Special GitLab references](#special-gitlab-references)
**[Standard Markdown](#standard-markdown)** **[Standard Markdown](#standard-markdown)**
[Headers](#headers) [Headers](#headers)
[Emphasis](#emphasis) [Emphasis](#emphasis)
[Lists](#lists) [Lists](#lists)
[Links](#links) [Links](#links)
[Images](#images) [Images](#images)
[Blockquotes](#blockquotes) [Blockquotes](#blockquotes)
[Inline HTML](#inline-html) [Inline HTML](#inline-html)
[Horizontal Rule](#horizontal-rule) [Horizontal Rule](#horizontal-rule)
[Line Breaks](#line-breaks) [Line Breaks](#line-breaks)
[Tables](#tables) [Tables](#tables)
**[References](#references)** **[References](#references)**
...@@ -33,7 +48,8 @@ Table of Contents ...@@ -33,7 +48,8 @@ Table of Contents
GitLab Flavored Markdown (GFM) GitLab Flavored Markdown (GFM)
============================== ==============================
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. 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.
You can use GFM in You can use GFM in
...@@ -51,16 +67,20 @@ Please see the [github-markup gem readme](https://github.com/gitlabhq/markup#mar ...@@ -51,16 +67,20 @@ Please see the [github-markup gem readme](https://github.com/gitlabhq/markup#mar
Newlines Newlines
-------- --------
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. GFM honors the markdown specification in how [paragraphs and line breaks are handled](http://daringfireball.net/projects/markdown/syntax#p).
The next paragraph contains two phrases separated by a single newline character: A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines.:
Roses are red Roses are red
Violets are blue Violets are blue
Sugar is sweet
Roses are red Roses are red
Violets are blue Violets are blue
Sugar is sweet
Multiple underscores in words Multiple underscores in words
----------------------------- -----------------------------
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. 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,13 +339,13 @@ Strikethrough uses two tildes. ~~Scratch this.~~
## Links ## Links
There are two ways to create links. There are two ways to create links, inline-style and reference-style.
[I'm an inline-style link](https://www.google.com) [I'm an inline-style link](https://www.google.com)
[I'm a reference-style link][Arbitrary case-insensitive reference text] [I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](../blob/master/LICENSE) [I'm a relative reference to a repository file](LICENSE)
[You can use numbers for reference-style link definitions][1] [You can use numbers for reference-style link definitions][1]
...@@ -341,7 +361,7 @@ There are two ways to create links. ...@@ -341,7 +361,7 @@ There are two ways to create links.
[I'm a reference-style link][Arbitrary case-insensitive reference text] [I'm a reference-style link][Arbitrary case-insensitive reference text]
[I'm a relative reference to a repository file](../blob/master/LICENSE) [I'm a relative reference to a repository file](LICENSE)
[You can use numbers for reference-style link definitions][1] [You can use numbers for reference-style link definitions][1]
...@@ -353,6 +373,15 @@ Some text to show that the reference links can follow later. ...@@ -353,6 +373,15 @@ Some text to show that the reference links can follow later.
[1]: http://slashdot.org [1]: http://slashdot.org
[link text itself]: http://www.reddit.com [link text itself]: http://www.reddit.com
**Note**
Relative links do not allow referencing project files in a wiki page or wiki page in a project file.
The reason for this is that, in GitLab, wiki is always a separate git repository. For example:
`[I'm a reference-style link][style]`
will point the link to `wikis/style` when the link is inside of a wiki markdown file.
## Images ## Images
Here's our logo (hover to see the title text): 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,15 +394,15 @@ Some text to show that the reference links can follow later.
[logo]: assets/logo-white.png [logo]: assets/logo-white.png
Here's our logo (hover to see the title text): Here's our logo:
Inline-style: Inline-style:
![alt text](/assets/logo-white.png "Logo Title Text 1") ![alt text](/assets/logo-white.png)
Reference-style: Reference-style:
![alt text][logo] ![alt text][logo]
[logo]: /assets/logo-white.png "Logo Title Text 2" [logo]: /assets/logo-white.png
## Blockquotes ## Blockquotes
......
...@@ -203,7 +203,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -203,7 +203,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end end
And 'I add various links to the wiki page' do And 'I add various links to the wiki page' do
fill_in "wiki[content]", with: "[test](test)\n[GitLab API doc](doc/api/README.md)\n[Rake tasks](doc/raketasks)\n" fill_in "wiki[content]", with: "[test](test)\n[GitLab API doc](api)\n[Rake tasks](raketasks)\n"
fill_in "wiki[message]", with: "Adding links to wiki" fill_in "wiki[message]", with: "Adding links to wiki"
click_button "Create page" click_button "Create page"
end end
...@@ -242,8 +242,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -242,8 +242,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end end
Then 'I see Gitlab API document' do Then 'I see Gitlab API document' do
current_path.should == project_blob_path(@project, "master/doc/api/README.md") current_path.should == project_wiki_path(@project, "api")
page.should have_content "Status codes" page.should have_content "Editing"
end end
And 'I click on Rake tasks link' do And 'I click on Rake tasks link' do
...@@ -251,9 +251,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -251,9 +251,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end end
Then 'I see Rake tasks directory' do Then 'I see Rake tasks directory' do
current_path.should == project_tree_path(@project, "master/doc/raketasks") current_path.should == project_wiki_path(@project, "raketasks")
page.should have_content "backup_restore.md" page.should have_content "Editing"
page.should have_content "maintenance.md"
end end
Given 'I go directory which contains README file' do Given 'I go directory which contains README file' do
......
...@@ -46,8 +46,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML ...@@ -46,8 +46,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
end end
def preprocess(full_document) def preprocess(full_document)
if @project if is_wiki?
h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?) full_document
elsif @project
h.create_relative_links(full_document, @project, @ref, @request_path)
else else
full_document full_document
end end
......
...@@ -440,12 +440,6 @@ describe GitlabMarkdownHelper do ...@@ -440,12 +440,6 @@ describe GitlabMarkdownHelper do
markdown(actual).should match(expected) markdown(actual).should match(expected)
end end
it "should handle wiki urls" do
actual = "[Link](test/link)\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/wikis/test/link\">Link</a></p>\n"
markdown(actual).should match(expected)
end
it "should handle relative urls in reference links for a file in master" do it "should handle relative urls in reference links for a file in master" do
actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n" actual = "[GitLab API doc][GitLab readme]\n [GitLab readme]: doc/api/README.md\n"
expected = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\n" expected = "<p><a href=\"/#{project.path_with_namespace}/blob/master/doc/api/README.md\">GitLab API doc</a></p>\n"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment