diff --git a/CHANGELOG b/CHANGELOG
index c11d6af2c4..9933f2f77d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -14,6 +14,7 @@ v 6.6.0
- Fix block/remove UI for admin::users#show page
- Show users' group membership on users' activity page
- User pages are visible without login if user is authorized to a public project
+ - Markdown rendered headers have id derived from their name and link to their id
v 6.5.1
- Fix branch selectbox when create merge request from fork
diff --git a/app/assets/images/icon-link.png b/app/assets/images/icon-link.png
new file mode 100644
index 0000000000..32ade0fe9a
Binary files /dev/null and b/app/assets/images/icon-link.png differ
diff --git a/app/assets/stylesheets/generic/files.scss b/app/assets/stylesheets/generic/files.scss
index 20877507c9..85111a4591 100644
--- a/app/assets/stylesheets/generic/files.scss
+++ b/app/assets/stylesheets/generic/files.scss
@@ -50,7 +50,6 @@
}
&.wiki {
- padding: 20px;
font-size: 14px;
line-height: 1.6;
diff --git a/app/assets/stylesheets/generic/issue_box.scss b/app/assets/stylesheets/generic/issue_box.scss
index afe9c5f818..c3a39f0251 100644
--- a/app/assets/stylesheets/generic/issue_box.scss
+++ b/app/assets/stylesheets/generic/issue_box.scss
@@ -23,11 +23,12 @@
line-height: 28px;
margin: 0;
color: #444;
+ border-bottom: 1px solid #eee;
}
.context {
border: none;
- border-top: 1px solid #eee;
+ border-bottom: 1px solid #eee;
}
.description {
@@ -35,7 +36,7 @@
}
.title, .context, .description {
- padding: 15px;
+ padding: 15px 15px 15px 30px;
.clearfix {
margin: 0;
diff --git a/app/assets/stylesheets/generic/typography.scss b/app/assets/stylesheets/generic/typography.scss
index 419a63d4d3..1a07fde53f 100644
--- a/app/assets/stylesheets/generic/typography.scss
+++ b/app/assets/stylesheets/generic/typography.scss
@@ -90,6 +90,27 @@ a:focus {
font-size: 14px;
line-height: 1.6;
+
+ /* Link to current header. */
+ h1, h2, h3, h4, h5, h6 {
+ position: relative;
+ &:hover > :last-child {
+ $size: 16px;
+ position: absolute;
+ right: 100%;
+ top: 50%;
+ margin-top: -$size/2;
+ margin-right: 0px;
+ padding-right: 20px;
+ display: inline-block;
+ width: $size;
+ height: $size;
+ background-image: url("icon-link.png");
+ background-size: contain;
+ background-repeat: no-repeat;
+ }
+ }
+
ul {
padding: 0;
margin: 0 0 9px 25px !important;
diff --git a/app/assets/stylesheets/main/mixins.scss b/app/assets/stylesheets/main/mixins.scss
index 4afe61d756..a7a5ed73ab 100644
--- a/app/assets/stylesheets/main/mixins.scss
+++ b/app/assets/stylesheets/main/mixins.scss
@@ -114,6 +114,10 @@
font-size: 1.2em;
}
+ // Larger 30px left margin is required for the header link icon.
+ // Use on all markdown including those without header links for uniformity.
+ margin: 20px 20px 20px 30px;
+
blockquote p {
color: #888;
font-size: 14px;
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index 315f1b805b..b25662e3ba 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -28,14 +28,16 @@ module GitlabMarkdownHelper
link_to(gfm_body.html_safe, url, html_options)
end
- def markdown(text)
- unless @markdown
- gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self,
- # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-
- filter_html: true,
- with_toc_data: true,
- hard_wrap: true,
- safe_links_only: true)
+ def markdown(text, options={})
+ unless (@markdown and options == @options)
+ @options = options
+ gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self, {
+ # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-
+ filter_html: true,
+ with_toc_data: true,
+ hard_wrap: true,
+ safe_links_only: true
+ }.merge(options))
@markdown = Redcarpet::Markdown.new(gitlab_renderer,
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
no_intra_emphasis: true,
@@ -47,7 +49,6 @@ module GitlabMarkdownHelper
space_after_headers: true,
superscript: true)
end
-
@markdown.render(text).html_safe
end
diff --git a/app/views/help/_layout.html.haml b/app/views/help/_layout.html.haml
index a413616bad..201d63ca24 100644
--- a/app/views/help/_layout.html.haml
+++ b/app/views/help/_layout.html.haml
@@ -8,4 +8,5 @@
= link_to title, path
.col-md-9
- = yield
+ .wiki
+ = yield
diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml
index cd4a158e42..5033dfefe2 100644
--- a/app/views/projects/issues/show.html.haml
+++ b/app/views/projects/issues/show.html.haml
@@ -46,10 +46,9 @@
= render partial: 'issue_context', locals: { issue: @issue }
- if @issue.description.present?
- .description
- .wiki
- = preserve do
- = markdown @issue.description
+ .wiki
+ = preserve do
+ = markdown @issue.description
- content_for :note_actions do
- if can?(current_user, :modify_issue, @issue)
diff --git a/app/views/projects/merge_requests/show/_mr_box.html.haml b/app/views/projects/merge_requests/show/_mr_box.html.haml
index b4f648ab19..9b95c09218 100644
--- a/app/views/projects/merge_requests/show/_mr_box.html.haml
+++ b/app/views/projects/merge_requests/show/_mr_box.html.haml
@@ -15,10 +15,9 @@
- if @merge_request.description.present?
- .description
- .wiki
- = preserve do
- = markdown @merge_request.description
+ .wiki
+ = preserve do
+ = markdown @merge_request.description
- if @merge_request.closed?
.description.alert-danger
diff --git a/app/views/projects/milestones/show.html.haml b/app/views/projects/milestones/show.html.haml
index e7c3785c05..283b4dfeac 100644
--- a/app/views/projects/milestones/show.html.haml
+++ b/app/views/projects/milestones/show.html.haml
@@ -42,13 +42,11 @@
.progress.progress-info
.progress-bar{style: "width: #{@milestone.percent_complete}%;"}
-
- if @milestone.description.present?
- .description
+ .wiki
= preserve do
= markdown @milestone.description
-
%ul.nav.nav-tabs.append-bottom-10
%li.active
= link_to '#tab-issues', 'data-toggle' => 'tab' do
diff --git a/app/views/projects/notes/_note.html.haml b/app/views/projects/notes/_note.html.haml
index fd2a3f4367..217e36e38d 100644
--- a/app/views/projects/notes/_note.html.haml
+++ b/app/views/projects/notes/_note.html.haml
@@ -31,7 +31,7 @@
.note-body
.note-text
= preserve do
- = markdown(note.note)
+ = markdown(note.note, {no_header_anchors: true})
.note-edit-form
= form_for note, url: project_note_path(@project, note), method: :put, remote: true, authenticity_token: true do |f|
diff --git a/doc/markdown/markdown.md b/doc/markdown/markdown.md
index bfb93a4701..008e37d11f 100644
--- a/doc/markdown/markdown.md
+++ b/doc/markdown/markdown.md
@@ -1,41 +1,37 @@
----------------------------------------------
-Table of Contents
+Table of Contents
=================
----------------------------------------------
-[GitLab Flavored Markdown](#toc_3)
--------------------------------
-[Newlines](#toc_4)
-[Multiple underscores in words](#toc_5)
-[URL autolinking](#toc_6)
-[Code and Syntax Highlighting](#toc_7)
-[Emoji](#toc_8)
-[Special GitLab references](#toc_9)
+**[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)**
-[Standard Markdown](#toc_10)
-------------------------------
-[Headers](#toc_11)
-[Emphasis](#toc_20)
-[Lists](#toc_21)
-[Links](#toc_22)
-[Images](#toc_23)
-[Blockquotes](#toc_24)
-[Inline HTML](#toc_25)
-[Horizontal Rule](#toc_26)
-[Line Breaks](#toc_27)
-[Tables](#toc_28)
+[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](#toc_29)
----------------------
+**[References](#references)**
----------------------------------------------
-
-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.
@@ -49,7 +45,6 @@ You can use GFM in
* milestones
* wiki pages
-
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.
@@ -61,8 +56,7 @@ The next paragraph contains two phrases separated by a single newline character:
Roses are red
Violets are blue
-
-
+
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.
@@ -73,7 +67,6 @@ It is not reasonable to italicize just _part_ of a word, especially when you're
perform_complicated_task
do_this_and_do_that_and_another_thing
-
URL autolinking
---------------
GFM will autolink standard URLs you copy and paste into your text.
@@ -83,12 +76,10 @@ So if you want to link to a URL (instead of a textural link), you can simply put
http://www.google.com
-
## Code and Syntax Highlighting
Blocks of code are either fenced by lines with three back-ticks ```, or are indented with four spaces. Only the fenced code blocks support syntax highlighting.
-
```no-highlight
Inline `code` has `back-ticks around` it.
```
@@ -101,14 +92,14 @@ Example:
var s = "JavaScript syntax highlighting";
alert(s);
```
-
+
```python
def function():
#indenting works just fine in the fenced code block
s = "Python syntax highlighting"
print s
```
-
+
```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
@@ -116,7 +107,7 @@ Example:
```
```
- No language indicated, so no syntax highlighting.
+ No language indicated, so no syntax highlighting.
s = "There is no highlighting for this."
But let's throw in a tag.
```
@@ -147,7 +138,6 @@ s = "There is no highlighting for this."
But let's throw in a tag.
```
-
Emoji
-----
@@ -159,7 +149,7 @@ Emoji
If you are :new: to this, don't be :fearful:. You can easily join the emoji :circus_tent:. All you need to do is to :book: up on the supported codes.
- Consult the [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/) for a list of all supported emoji codes. :thumbsup:
+ Consult the [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/) for a list of all supported emoji codes. :thumbsup:
Sometimes you want to be :cool: and add some :sparkles: to your :speech_balloon:. Well we have a :gift: for you:
@@ -169,9 +159,8 @@ You can use it to point out a :bug: or warn about :monkey:patches. And if someon
If you are :new: to this, don't be :fearful:. You can easily join the emoji :circus_tent:. All you need to do is to :book: up on the supported codes.
-Consult the [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/) for a list of all supported emoji codes. :thumbsup:
+Consult the [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/) for a list of all supported emoji codes. :thumbsup:
-
Special GitLab References
-----
@@ -179,7 +168,6 @@ GFM recognized special references.
You can easily reference e.g. a team member, an issue, or a commit within a project.
GFM will turn that reference into a link so you can navigate between them easily.
-
GFM will recognize the following:
* @foo : for team members
@@ -189,13 +177,10 @@ GFM will recognize the following:
* 1234567 : for commits
* \[file\](path/to/file) : for file references
-
-
----------------------------------
# Standard Markdown
----------------------------------
-
## Headers
```no-highlight
@@ -230,7 +215,54 @@ Alt-H1
Alt-H2
------
-
+### Header IDs and links
+
+All markdown rendered headers automatically get IDs, except for comments.
+
+On hover a link to those IDs becomes visible to make it easier to copy the link to the header to give it to someone else.
+
+The IDs are generated from the content of the header according to the following rules:
+
+1) remove the heading hashes `#` and process the rest of the line as it would be processed if it were not a header
+2) from the result, remove all HTML tags, but keep their inner content
+3) convert all characters to lowercase
+4) convert all characters except `[a-z0-9_-]` into hyphens `-`
+5) transform multiple adjacent hyphens into a single hyphen
+6) remove trailing and heading hyphens
+
+For example:
+
+```
+###### ..Ab_c-d. e [anchor](url) ..
+```
+
+which renders as:
+
+###### ..Ab_c-d. e [anchor](url) ..
+
+will first be converted by step 1) into a string like:
+
+```
+..Ab_c-d. e <a href="url">anchor</a> <img src="url" alt="alt text"/>..
+```
+
+After removing the tags in step 2) we get:
+
+```
+..Ab_c-d. e anchor ..
+```
+
+And applying all the other steps gives the id:
+
+```
+ab_c-d-e-anchor
+```
+
+Note in particular how:
+
+- for markdown anchors `[text](url)`, only the `text` is used
+- markdown images `` are completely ignored
+
## Emphasis
```no-highlight
@@ -251,18 +283,16 @@ Combined emphasis with **asterisks and _underscores_**.
Strikethrough uses two tildes. ~~Scratch this.~~
-
-
## Lists
```no-highlight
1. First ordered list item
2. Another item
- * Unordered sub-list.
+ * Unordered sub-list.
1. Actual numbers don't matter, just that it's a number
1. Ordered sub-list
-4. And another item.
-
+4. And another item.
+
Some text that should be aligned with the above item.
* Unordered list can use asterisks
@@ -272,18 +302,17 @@ Strikethrough uses two tildes. ~~Scratch this.~~
1. First ordered list item
2. Another item
- * Unordered sub-list.
+ * Unordered sub-list.
1. Actual numbers don't matter, just that it's a number
1. Ordered sub-list
-4. And another item.
-
+4. And another item.
+
Some text that should be aligned with the above item.
* Unordered list can use asterisks
- Or minuses
+ Or pluses
-
## Links
There are two ways to create links.
@@ -320,30 +349,28 @@ Some text to show that the reference links can follow later.
[1]: http://slashdot.org
[link text itself]: http://www.reddit.com
-
## Images
Here's our logo (hover to see the title text):
- Inline-style:
+ Inline-style:

- Reference-style:
+ Reference-style:
![alt text1][logo]
[logo]: assets/logo-white.png
Here's our logo (hover to see the title text):
-Inline-style:
+Inline-style:

-Reference-style:
+Reference-style:
![alt text][logo]
[logo]: /assets/logo-white.png "Logo Title Text 2"
-
## Blockquotes
```no-highlight
@@ -352,7 +379,7 @@ Reference-style:
Quote break.
-> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
+> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
```
> Blockquotes are very handy in email to emulate reply text.
@@ -360,12 +387,11 @@ Quote break.
Quote break.
-> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
+> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.
-
## Inline HTML
-You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
+You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
```no-highlight