summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-03-17 14:06:08 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-03-17 14:06:08 +0000
commit493c7a614782381a5267939d5b5cf7bdb61daf3a (patch)
treef53dc332ff34eaf51537be6aa02ae0a44e7f513e
parent66c4a7dba1f9ff2018811dc04ebc1b2e7eb269a3 (diff)
parent656d9548bcfa315751fc01b3afb0ec14104e15a8 (diff)
downloadgitlab-ce-493c7a614782381a5267939d5b5cf7bdb61daf3a.tar.gz
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.
-rw-r--r--app/helpers/gitlab_markdown_helper.rb7
-rw-r--r--doc/markdown/markdown.md47
-rw-r--r--features/steps/project/markdown_render.rb11
-rw-r--r--lib/redcarpet/render/gitlab_html.rb6
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb6
5 files changed, 50 insertions, 27 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 7f72ab54838..69425bc171d 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -63,8 +63,7 @@ module GitlabMarkdownHelper
# project_path_with_namespace - namespace/projectname, eg. gitlabhq/gitlabhq
# 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
- # wiki - whether the markdown is from wiki or not
- def create_relative_links(text, project, ref, requested_path, wiki = false)
+ def create_relative_links(text, project, ref, requested_path)
@path_to_satellite = project.satellite.path
project_path_with_namespace = project.path_with_namespace
paths = extract_paths(text)
@@ -134,12 +133,12 @@ module GitlabMarkdownHelper
end
# 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)
if file_exists?(path)
"#{local_path(path)}/#{correct_ref(ref)}"
else
- "wikis"
+ "blob/#{correct_ref(ref)}"
end
end
diff --git a/doc/markdown/markdown.md b/doc/markdown/markdown.md
index f49f09756ab..e7ebc613431 100644
--- a/doc/markdown/markdown.md
+++ b/doc/markdown/markdown.md
@@ -8,23 +8,38 @@ Table of Contents
**[GitLab Flavored Markdown](#gitlab-flavored-markdown-gfm)**
[Newlines](#newlines)
+
[Multiple underscores in words](#multiple-underscores-in-words)
+
[URL autolinking](#url-autolinking)
+
[Code and Syntax Highlighting](#code-and-syntax-highlighting)
+
[Emoji](#emoji)
+
[Special GitLab references](#special-gitlab-references)
+
**[Standard Markdown](#standard-markdown)**
[Headers](#headers)
+
[Emphasis](#emphasis)
+
[Lists](#lists)
+
[Links](#links)
+
[Images](#images)
+
[Blockquotes](#blockquotes)
+
[Inline HTML](#inline-html)
+
[Horizontal Rule](#horizontal-rule)
+
[Line Breaks](#line-breaks)
+
[Tables](#tables)
**[References](#references)**
@@ -33,7 +48,8 @@ Table of Contents
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
@@ -51,16 +67,20 @@ Please see the [github-markup gem readme](https://github.com/gitlabhq/markup#mar
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
Violets are blue
+ Sugar is sweet
+
Roses are red
Violets are blue
+Sugar is sweet
+
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.~~
## 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 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]
@@ -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 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]
@@ -353,6 +373,15 @@ Some text to show that the reference links can follow later.
[1]: http://slashdot.org
[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
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.
[logo]: assets/logo-white.png
-Here's our logo (hover to see the title text):
+Here's our logo:
Inline-style:
-![alt text](/assets/logo-white.png "Logo Title Text 1")
+![alt text](/assets/logo-white.png)
Reference-style:
![alt text][logo]
-[logo]: /assets/logo-white.png "Logo Title Text 2"
+[logo]: /assets/logo-white.png
## Blockquotes
diff --git a/features/steps/project/markdown_render.rb b/features/steps/project/markdown_render.rb
index 8fbf2753aa7..c94de283069 100644
--- a/features/steps/project/markdown_render.rb
+++ b/features/steps/project/markdown_render.rb
@@ -203,7 +203,7 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
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"
click_button "Create page"
end
@@ -242,8 +242,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I see Gitlab API document' do
- current_path.should == project_blob_path(@project, "master/doc/api/README.md")
- page.should have_content "Status codes"
+ current_path.should == project_wiki_path(@project, "api")
+ page.should have_content "Editing"
end
And 'I click on Rake tasks link' do
@@ -251,9 +251,8 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
end
Then 'I see Rake tasks directory' do
- current_path.should == project_tree_path(@project, "master/doc/raketasks")
- page.should have_content "backup_restore.md"
- page.should have_content "maintenance.md"
+ current_path.should == project_wiki_path(@project, "raketasks")
+ page.should have_content "Editing"
end
Given 'I go directory which contains README file' do
diff --git a/lib/redcarpet/render/gitlab_html.rb b/lib/redcarpet/render/gitlab_html.rb
index 2e18b0592b5..86d8b69b0ef 100644
--- a/lib/redcarpet/render/gitlab_html.rb
+++ b/lib/redcarpet/render/gitlab_html.rb
@@ -46,8 +46,10 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
end
def preprocess(full_document)
- if @project
- h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?)
+ if is_wiki?
+ full_document
+ elsif @project
+ h.create_relative_links(full_document, @project, @ref, @request_path)
else
full_document
end
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index 7e98b7944f1..5bd16d1c16c 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -440,12 +440,6 @@ describe GitlabMarkdownHelper do
markdown(actual).should match(expected)
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
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"