Commit c61512d4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'header-anchors' of github.com:cirosantilli/gitlab-elearn into...

Merge branch 'header-anchors' of github.com:cirosantilli/gitlab-elearn into cirosantilli-header-anchors
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

Conflicts:
	CHANGELOG
parents 6e47fbf5 61748c99
...@@ -14,6 +14,7 @@ v 6.6.0 ...@@ -14,6 +14,7 @@ v 6.6.0
- Fix block/remove UI for admin::users#show page - Fix block/remove UI for admin::users#show page
- Show users' group membership on users' activity page - Show users' group membership on users' activity page
- User pages are visible without login if user is authorized to a public project - 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 v 6.5.1
- Fix branch selectbox when create merge request from fork - Fix branch selectbox when create merge request from fork
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
} }
&.wiki { &.wiki {
padding: 20px;
font-size: 14px; font-size: 14px;
line-height: 1.6; line-height: 1.6;
......
...@@ -23,11 +23,12 @@ ...@@ -23,11 +23,12 @@
line-height: 28px; line-height: 28px;
margin: 0; margin: 0;
color: #444; color: #444;
border-bottom: 1px solid #eee;
} }
.context { .context {
border: none; border: none;
border-top: 1px solid #eee; border-bottom: 1px solid #eee;
} }
.description { .description {
...@@ -35,7 +36,7 @@ ...@@ -35,7 +36,7 @@
} }
.title, .context, .description { .title, .context, .description {
padding: 15px; padding: 15px 15px 15px 30px;
.clearfix { .clearfix {
margin: 0; margin: 0;
......
...@@ -90,6 +90,27 @@ a:focus { ...@@ -90,6 +90,27 @@ a:focus {
font-size: 14px; font-size: 14px;
line-height: 1.6; 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 { ul {
padding: 0; padding: 0;
margin: 0 0 9px 25px !important; margin: 0 0 9px 25px !important;
......
...@@ -114,6 +114,10 @@ ...@@ -114,6 +114,10 @@
font-size: 1.2em; 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 { blockquote p {
color: #888; color: #888;
font-size: 14px; font-size: 14px;
......
...@@ -28,14 +28,16 @@ module GitlabMarkdownHelper ...@@ -28,14 +28,16 @@ module GitlabMarkdownHelper
link_to(gfm_body.html_safe, url, html_options) link_to(gfm_body.html_safe, url, html_options)
end end
def markdown(text) def markdown(text, options={})
unless @markdown unless (@markdown and options == @options)
gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self, @options = options
# see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch- gitlab_renderer = Redcarpet::Render::GitlabHTML.new(self, {
filter_html: true, # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-
with_toc_data: true, filter_html: true,
hard_wrap: true, with_toc_data: true,
safe_links_only: true) hard_wrap: true,
safe_links_only: true
}.merge(options))
@markdown = Redcarpet::Markdown.new(gitlab_renderer, @markdown = Redcarpet::Markdown.new(gitlab_renderer,
# see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
no_intra_emphasis: true, no_intra_emphasis: true,
...@@ -47,7 +49,6 @@ module GitlabMarkdownHelper ...@@ -47,7 +49,6 @@ module GitlabMarkdownHelper
space_after_headers: true, space_after_headers: true,
superscript: true) superscript: true)
end end
@markdown.render(text).html_safe @markdown.render(text).html_safe
end end
......
...@@ -8,4 +8,5 @@ ...@@ -8,4 +8,5 @@
= link_to title, path = link_to title, path
.col-md-9 .col-md-9
= yield .wiki
= yield
...@@ -46,10 +46,9 @@ ...@@ -46,10 +46,9 @@
= render partial: 'issue_context', locals: { issue: @issue } = render partial: 'issue_context', locals: { issue: @issue }
- if @issue.description.present? - if @issue.description.present?
.description .wiki
.wiki = preserve do
= preserve do = markdown @issue.description
= markdown @issue.description
- content_for :note_actions do - content_for :note_actions do
- if can?(current_user, :modify_issue, @issue) - if can?(current_user, :modify_issue, @issue)
......
...@@ -15,10 +15,9 @@ ...@@ -15,10 +15,9 @@
- if @merge_request.description.present? - if @merge_request.description.present?
.description .wiki
.wiki = preserve do
= preserve do = markdown @merge_request.description
= markdown @merge_request.description
- if @merge_request.closed? - if @merge_request.closed?
.description.alert-danger .description.alert-danger
......
...@@ -42,13 +42,11 @@ ...@@ -42,13 +42,11 @@
.progress.progress-info .progress.progress-info
.progress-bar{style: "width: #{@milestone.percent_complete}%;"} .progress-bar{style: "width: #{@milestone.percent_complete}%;"}
- if @milestone.description.present? - if @milestone.description.present?
.description .wiki
= preserve do = preserve do
= markdown @milestone.description = markdown @milestone.description
%ul.nav.nav-tabs.append-bottom-10 %ul.nav.nav-tabs.append-bottom-10
%li.active %li.active
= link_to '#tab-issues', 'data-toggle' => 'tab' do = link_to '#tab-issues', 'data-toggle' => 'tab' do
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
.note-body .note-body
.note-text .note-text
= preserve do = preserve do
= markdown(note.note) = markdown(note.note, {no_header_anchors: true})
.note-edit-form .note-edit-form
= form_for note, url: project_note_path(@project, note), method: :put, remote: true, authenticity_token: true do |f| = form_for note, url: project_note_path(@project, note), method: :put, remote: true, authenticity_token: true do |f|
......
---------------------------------------------- ----------------------------------------------
Table of Contents Table of Contents
================= =================
---------------------------------------------- ----------------------------------------------
[GitLab Flavored Markdown](#toc_3) **[GitLab Flavored Markdown](#gitlab-flavored-markdown-gfm)**
-------------------------------
[Newlines](#toc_4) [Newlines](#newlines)
[Multiple underscores in words](#toc_5) [Multiple underscores in words](#multiple-underscores-in-words)
[URL autolinking](#toc_6) [URL autolinking](#url-autolinking)
[Code and Syntax Highlighting](#toc_7) [Code and Syntax Highlighting](#code-and-syntax-highlighting)
[Emoji](#toc_8) [Emoji](#emoji)
[Special GitLab references](#toc_9) [Special GitLab references](#special-gitlab-references)
**[Standard Markdown](#standard-markdown)**
[Standard Markdown](#toc_10) [Headers](#headers)
------------------------------ [Emphasis](#emphasis)
[Headers](#toc_11) [Lists](#lists)
[Emphasis](#toc_20) [Links](#links)
[Lists](#toc_21) [Images](#images)
[Links](#toc_22) [Blockquotes](#blockquotes)
[Images](#toc_23) [Inline HTML](#inline-html)
[Blockquotes](#toc_24) [Horizontal Rule](#horizontal-rule)
[Inline HTML](#toc_25) [Line Breaks](#line-breaks)
[Horizontal Rule](#toc_26) [Tables](#tables)
[Line Breaks](#toc_27)
[Tables](#toc_28) **[References](#references)**
[References](#toc_29)
---------------------
---------------------------------------------- ----------------------------------------------
<a name="gfm" /> 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.
...@@ -49,7 +45,6 @@ You can use GFM in ...@@ -49,7 +45,6 @@ You can use GFM in
* milestones * milestones
* wiki pages * wiki pages
<a name="newlines" />
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. 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: ...@@ -61,8 +56,7 @@ The next paragraph contains two phrases separated by a single newline character:
Roses are red Roses are red
Violets are blue Violets are blue
<a name="underscores" />
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.
...@@ -73,7 +67,6 @@ It is not reasonable to italicize just _part_ of a word, especially when you're ...@@ -73,7 +67,6 @@ It is not reasonable to italicize just _part_ of a word, especially when you're
perform_complicated_task perform_complicated_task
do_this_and_do_that_and_another_thing do_this_and_do_that_and_another_thing
<a name="autolink" />
URL autolinking URL autolinking
--------------- ---------------
GFM will autolink standard URLs you copy and paste into your text. 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 ...@@ -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 http://www.google.com
<a name="code"/>
## Code and Syntax Highlighting ## Code and Syntax Highlighting
Blocks of code are either fenced by lines with three back-ticks <code>```</code>, or are indented with four spaces. Only the fenced code blocks support syntax highlighting. Blocks of code are either fenced by lines with three back-ticks <code>```</code>, or are indented with four spaces. Only the fenced code blocks support syntax highlighting.
```no-highlight ```no-highlight
Inline `code` has `back-ticks around` it. Inline `code` has `back-ticks around` it.
``` ```
...@@ -101,14 +92,14 @@ Example: ...@@ -101,14 +92,14 @@ Example:
var s = "JavaScript syntax highlighting"; var s = "JavaScript syntax highlighting";
alert(s); alert(s);
``` ```
```python ```python
def function(): def function():
#indenting works just fine in the fenced code block #indenting works just fine in the fenced code block
s = "Python syntax highlighting" s = "Python syntax highlighting"
print s print s
``` ```
```ruby ```ruby
require 'redcarpet' require 'redcarpet'
markdown = Redcarpet.new("Hello World!") markdown = Redcarpet.new("Hello World!")
...@@ -116,7 +107,7 @@ Example: ...@@ -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." s = "There is no highlighting for this."
But let's throw in a <b>tag</b>. But let's throw in a <b>tag</b>.
``` ```
...@@ -147,7 +138,6 @@ s = "There is no highlighting for this." ...@@ -147,7 +138,6 @@ s = "There is no highlighting for this."
But let's throw in a <b>tag</b>. But let's throw in a <b>tag</b>.
``` ```
<a name="emoji"/>
Emoji Emoji
----- -----
...@@ -159,7 +149,7 @@ 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. 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: 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 ...@@ -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. 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:
<a name="special"/>
Special GitLab References Special GitLab References
----- -----
...@@ -179,7 +168,6 @@ GFM recognized special 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. 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 turn that reference into a link so you can navigate between them easily.
GFM will recognize the following: GFM will recognize the following:
* @foo : for team members * @foo : for team members
...@@ -189,13 +177,10 @@ GFM will recognize the following: ...@@ -189,13 +177,10 @@ GFM will recognize the following:
* 1234567 : for commits * 1234567 : for commits
* \[file\](path/to/file) : for file references * \[file\](path/to/file) : for file references
<a name="standard"/>
---------------------------------- ----------------------------------
# Standard Markdown # Standard Markdown
---------------------------------- ----------------------------------
<a name="headers"/>
## Headers ## Headers
```no-highlight ```no-highlight
...@@ -230,7 +215,54 @@ Alt-H1 ...@@ -230,7 +215,54 @@ Alt-H1
Alt-H2 Alt-H2
------ ------
<a name="emphasis"/> ### 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) ![alt text](url)..
```
which renders as:
###### ..Ab_c-d. e [anchor](url) ![alt text](url)..
will first be converted by step 1) into a string like:
```
..Ab_c-d. e &lt;a href="url">anchor&lt;/a> &lt;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 `![alt](url)` are completely ignored
## Emphasis ## Emphasis
```no-highlight ```no-highlight
...@@ -251,18 +283,16 @@ Combined emphasis with **asterisks and _underscores_**. ...@@ -251,18 +283,16 @@ Combined emphasis with **asterisks and _underscores_**.
Strikethrough uses two tildes. ~~Scratch this.~~ Strikethrough uses two tildes. ~~Scratch this.~~
<a name="lists"/>
## Lists ## Lists
```no-highlight ```no-highlight
1. First ordered list item 1. First ordered list item
2. Another item 2. Another item
* Unordered sub-list. * Unordered sub-list.
1. Actual numbers don't matter, just that it's a number 1. Actual numbers don't matter, just that it's a number
1. Ordered sub-list 1. Ordered sub-list
4. And another item. 4. And another item.
Some text that should be aligned with the above item. Some text that should be aligned with the above item.
* Unordered list can use asterisks * Unordered list can use asterisks
...@@ -272,18 +302,17 @@ Strikethrough uses two tildes. ~~Scratch this.~~ ...@@ -272,18 +302,17 @@ Strikethrough uses two tildes. ~~Scratch this.~~
1. First ordered list item 1. First ordered list item
2. Another item 2. Another item
* Unordered sub-list. * Unordered sub-list.
1. Actual numbers don't matter, just that it's a number 1. Actual numbers don't matter, just that it's a number
1. Ordered sub-list 1. Ordered sub-list
4. And another item. 4. And another item.
Some text that should be aligned with the above item. Some text that should be aligned with the above item.
* Unordered list can use asterisks * Unordered list can use asterisks
- Or minuses - Or minuses
+ Or pluses + Or pluses
<a name="links"/>
## Links ## Links
There are two ways to create links. There are two ways to create links.
...@@ -320,30 +349,28 @@ Some text to show that the reference links can follow later. ...@@ -320,30 +349,28 @@ 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
<a name="images"/>
## Images ## Images
Here's our logo (hover to see the title text): Here's our logo (hover to see the title text):
Inline-style: Inline-style:
![alt text](assets/logo-white.png) ![alt text](assets/logo-white.png)
Reference-style: Reference-style:
![alt text1][logo] ![alt text1][logo]
[logo]: assets/logo-white.png [logo]: assets/logo-white.png
Here's our logo (hover to see the title text): Here's our logo (hover to see the title text):
Inline-style: Inline-style:
![alt text](/assets/logo-white.png "Logo Title Text 1") ![alt text](/assets/logo-white.png "Logo Title Text 1")
Reference-style: Reference-style:
![alt text][logo] ![alt text][logo]
[logo]: /assets/logo-white.png "Logo Title Text 2" [logo]: /assets/logo-white.png "Logo Title Text 2"
<a name="blockquotes"/>
## Blockquotes ## Blockquotes
```no-highlight ```no-highlight
...@@ -352,7 +379,7 @@ Reference-style: ...@@ -352,7 +379,7 @@ Reference-style:
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.
``` ```
> Blockquotes are very handy in email to emulate reply text. > Blockquotes are very handy in email to emulate reply text.
...@@ -360,12 +387,11 @@ Quote break. ...@@ -360,12 +387,11 @@ Quote break.
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.
<a name="html"/>
## Inline HTML ## 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 ```no-highlight
<dl> <dl>
...@@ -385,7 +411,6 @@ You can also use raw HTML in your Markdown, and it'll mostly work pretty well. ...@@ -385,7 +411,6 @@ You can also use raw HTML in your Markdown, and it'll mostly work pretty well.
<dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd> <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
</dl> </dl>
<a name="hr"/>
## Horizontal Rule ## Horizontal Rule
``` ```
...@@ -418,10 +443,9 @@ ___ ...@@ -418,10 +443,9 @@ ___
Underscores Underscores
<a name="lines"/>
## Line Breaks ## Line Breaks
My basic recommendation for learning how line breaks work is to experiment and discover -- hit &lt;Enter&gt; once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend. My basic recommendation for learning how line breaks work is to experiment and discover -- hit &lt;Enter&gt; once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.
Here are some things to try out: Here are some things to try out:
...@@ -438,11 +462,9 @@ Here's a line for us to start with. ...@@ -438,11 +462,9 @@ Here's a line for us to start with.
This line is separated from the one above by two newlines, so it will be a *separate paragraph*. This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
This line is also begins a separate paragraph, but... This line is also begins a separate paragraph, but...
This line is only separated by a single newline, so it's a separate line in the *same paragraph*. This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
<a name="tables"/>
## Tables ## Tables
Tables aren't part of the core Markdown spec, but they are part of GFM and Markdown Here supports them. Tables aren't part of the core Markdown spec, but they are part of GFM and Markdown Here supports them.
...@@ -461,10 +483,8 @@ Code above produces next output: ...@@ -461,10 +483,8 @@ Code above produces next output:
| cell 1 | cell 2 | | cell 1 | cell 2 |
| cell 3 | cell 4 | | cell 3 | cell 4 |
------------ ------------
<a name="references"/>
## References ## References
* This document leveraged heavily from the [Markdown-Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet). * This document leveraged heavily from the [Markdown-Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
......
Feature: Help
Background:
Given I sign in as a user
And I visit the "Rake Tasks" help page
Scenario: The markdown should be rendered correctly
Then I should see "Rake Tasks" page markdown rendered
And Header "Rebuild project satellites" should have correct ids and links
...@@ -55,3 +55,15 @@ Feature: Project Issues ...@@ -55,3 +55,15 @@ Feature: Project Issues
And I fill in issue search with ".3" And I fill in issue search with ".3"
Then I should see "Release 0.3" in issues Then I should see "Release 0.3" in issues
And I should not see "Release 0.4" in issues And I should not see "Release 0.4" in issues
# Markdown
Scenario: Headers inside the description should have ids generated for them.
Given I visit issue page "Release 0.4"
Then Header "Description header" should have correct id and link
@javascript
Scenario: Headers inside comments should not have ids generated for them.
Given I visit issue page "Release 0.4"
And I leave a comment with a header containing "Comment with a header"
Then The comment with the header should not have an ID
...@@ -22,3 +22,9 @@ Feature: Project Milestones ...@@ -22,3 +22,9 @@ Feature: Project Milestones
Given the milestone has open and closed issues Given the milestone has open and closed issues
And I click link "v2.2" And I click link "v2.2"
Then I should see 3 issues Then I should see 3 issues
# Markdown
Scenario: Headers inside the description should have ids generated for them.
Given I click link "v2.2"
Then Header "Description header" should have correct id and link
...@@ -77,3 +77,15 @@ Feature: Project Merge Requests ...@@ -77,3 +77,15 @@ Feature: Project Merge Requests
Then I modify merge commit message Then I modify merge commit message
And I accept this merge request And I accept this merge request
Then I should see merged request Then I should see merged request
# Markdown
Scenario: Headers inside the description should have ids generated for them.
When I visit merge request page "Bug NS-04"
Then Header "Description header" should have correct id and link
@javascript
Scenario: Headers inside comments should not have ids generated for them.
Given I visit merge request page "Bug NS-04"
And I leave a comment with a header containing "Comment with a header"
Then The comment with the header should not have an ID
...@@ -4,6 +4,15 @@ Feature: Project markdown render ...@@ -4,6 +4,15 @@ Feature: Project markdown render
And I own project "Delta" And I own project "Delta"
Given I visit project source page Given I visit project source page
# -------------------------------------------
# README
# -------------------------------------------
Scenario: Tree view should have correct links in README
Given I go directory which contains README file
And I click on a relative link in README
Then I should see the correct markdown
Scenario: I browse files from master branch Scenario: I browse files from master branch
Then I should see files from repository in master Then I should see files from repository in master
And I should see rendered README which contains correct links And I should see rendered README which contains correct links
...@@ -28,6 +37,14 @@ Feature: Project markdown render ...@@ -28,6 +37,14 @@ Feature: Project markdown render
And I click on Maintenance in README And I click on Maintenance in README
Then I should see correct maintenance file rendered Then I should see correct maintenance file rendered
Scenario: README headers should have header links
Then I should see rendered README which contains correct links
And Header "Application details" should have correct id and link
# -------------------------------------------
# File content
# -------------------------------------------
Scenario: I navigate to doc directory to view documentation in master Scenario: I navigate to doc directory to view documentation in master
And I navigate to the doc/api/README And I navigate to the doc/api/README
And I see correct file rendered And I see correct file rendered
...@@ -40,6 +57,14 @@ Feature: Project markdown render ...@@ -40,6 +57,14 @@ Feature: Project markdown render
And I click on raketasks in doc/api/README And I click on raketasks in doc/api/README
Then I should see correct directory rendered Then I should see correct directory rendered
Scenario: I navigate to doc directory to view user doc in master
And I navigate to the doc/api/README
And Header "GitLab API" should have correct id and link
# -------------------------------------------
# Markdown branch README
# -------------------------------------------
Scenario: I browse files from markdown branch Scenario: I browse files from markdown branch
When I visit markdown branch When I visit markdown branch
Then I should see files from repository in markdown branch Then I should see files from repository in markdown branch
...@@ -68,6 +93,10 @@ Feature: Project markdown render ...@@ -68,6 +93,10 @@ Feature: Project markdown render
And I click on raketasks in doc/api/README And I click on raketasks in doc/api/README
Then I should see correct directory rendered for markdown branch Then I should see correct directory rendered for markdown branch
# -------------------------------------------
# Wiki
# -------------------------------------------
Scenario: I create a wiki page with different links Scenario: I create a wiki page with different links
Given I go to wiki page Given I go to wiki page
And I add various links to the wiki page And I add various links to the wiki page
...@@ -81,12 +110,7 @@ Feature: Project markdown render ...@@ -81,12 +110,7 @@ Feature: Project markdown render
And I click on Rake tasks link And I click on Rake tasks link
Then I see Rake tasks directory Then I see Rake tasks directory
Scenario: I visit the help page with markdown Scenario: Wiki headers should have should have ids generated for them.
Given I visit to the help page Given I go to wiki page
And I select a page with markdown And I add a header to the wiki page
Then I should see a help page with markdown Then Wiki header should have correct id and link
Scenario: Tree view should have correct links in README
Given I go directory which contains README file
And I click on a relative link in README
Then I should see the correct markdown
class Spinach::Features::Help < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedMarkdown
step 'I visit the help page' do
visit help_path
end
step 'I visit the "Rake Tasks" help page' do
visit help_raketasks_path
end
step 'I should see "Rake Tasks" page markdown rendered' do
page.should have_content "GitLab provides some specific rake tasks to enable special features or perform maintenance tasks"
end
step 'Header "Rebuild project satellites" should have correct ids and links' do
header_should_have_correct_id_and_link(3, 'Rebuild project satellites', 'rebuild-project-satellites')
end
end
...@@ -3,6 +3,7 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -3,6 +3,7 @@ class ProjectIssues < Spinach::FeatureSteps
include SharedProject include SharedProject
include SharedNote include SharedNote
include SharedPaths include SharedPaths
include SharedMarkdown
Given 'I should see "Release 0.4" in issues' do Given 'I should see "Release 0.4" in issues' do
page.should have_content "Release 0.4" page.should have_content "Release 0.4"
...@@ -121,7 +122,9 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -121,7 +122,9 @@ class ProjectIssues < Spinach::FeatureSteps
create(:issue, create(:issue,
title: "Release 0.4", title: "Release 0.4",
project: project, project: project,
author: project.users.first) author: project.users.first,
description: "# Description header"
)
end end
And 'project "Shop" have "Tweet control" open issue' do And 'project "Shop" have "Tweet control" open issue' do
......
class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
include SharedAuthentication include SharedAuthentication
include SharedPaths include SharedPaths
include SharedMarkdown
And 'I own project "Delta"' do And 'I own project "Delta"' do
@project = Project.find_by(name: "Delta") @project = Project.find_by(name: "Delta")
...@@ -44,7 +45,6 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -44,7 +45,6 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
page.should have_content "maintenance.md" page.should have_content "maintenance.md"
end end
And 'I click on GitLab API doc directory in README' do And 'I click on GitLab API doc directory in README' do
click_link "GitLab API doc directory" click_link "GitLab API doc directory"
end end
...@@ -140,6 +140,16 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -140,6 +140,16 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
page.should have_content "test GitLab API doc Rake tasks" page.should have_content "test GitLab API doc Rake tasks"
end end
step 'I add a header to the wiki page' do
fill_in "wiki[content]", with: "# Wiki header\n"
fill_in "wiki[message]", with: "Add header to wiki"
click_button "Create page"
end
step 'Wiki header should have correct id and link' do
header_should_have_correct_id_and_link(1, 'Wiki header', 'wiki-header')
end
And 'I click on test link' do And 'I click on test link' do
click_link "test" click_link "test"
end end
...@@ -173,18 +183,6 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -173,18 +183,6 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
page.should have_content "maintenance.md" page.should have_content "maintenance.md"
end end
Given 'I visit to the help page' do
visit help_path
end
And 'I select a page with markdown' do
click_link "Rake Tasks"
end
Then 'I should see a help page with markdown' do
page.should have_content "GitLab provides some specific rake tasks to enable special features or perform maintenance tasks"
end
Given 'I go directory which contains README file' do Given 'I go directory which contains README file' do
visit project_tree_path(@project, "master/doc/api") visit project_tree_path(@project, "master/doc/api")
current_path.should == project_tree_path(@project, "master/doc/api") current_path.should == project_tree_path(@project, "master/doc/api")
...@@ -198,4 +196,12 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps ...@@ -198,4 +196,12 @@ class Spinach::Features::ProjectMarkdownRender < Spinach::FeatureSteps
current_path.should == project_blob_path(@project, "master/doc/api/users.md") current_path.should == project_blob_path(@project, "master/doc/api/users.md")
page.should have_content "List users" page.should have_content "List users"
end end
step 'Header "Application details" should have correct id and link' do
header_should_have_correct_id_and_link(2, 'Application details', 'application-details')
end
step 'Header "GitLab API" should have correct id and link' do
header_should_have_correct_id_and_link(1, 'GitLab API', 'gitlab-api')
end
end end
...@@ -3,6 +3,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps ...@@ -3,6 +3,7 @@ class ProjectMergeRequests < Spinach::FeatureSteps
include SharedProject include SharedProject
include SharedNote include SharedNote
include SharedPaths include SharedPaths
include SharedMarkdown
step 'I click link "New Merge Request"' do step 'I click link "New Merge Request"' do
click_link "New Merge Request" click_link "New Merge Request"
...@@ -83,7 +84,9 @@ class ProjectMergeRequests < Spinach::FeatureSteps ...@@ -83,7 +84,9 @@ class ProjectMergeRequests < Spinach::FeatureSteps
target_project: project, target_project: project,
source_branch: 'stable', source_branch: 'stable',
target_branch: 'master', target_branch: 'master',
author: project.users.first) author: project.users.first,
description: "# Description header"
)
end end
step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
......
...@@ -2,6 +2,7 @@ class ProjectMilestones < Spinach::FeatureSteps ...@@ -2,6 +2,7 @@ class ProjectMilestones < Spinach::FeatureSteps
include SharedAuthentication include SharedAuthentication
include SharedProject include SharedProject
include SharedPaths include SharedPaths
include SharedMarkdown
Then 'I should see milestone "v2.2"' do Then 'I should see milestone "v2.2"' do
milestone = @project.milestones.find_by(title: "v2.2") milestone = @project.milestones.find_by(title: "v2.2")
...@@ -32,8 +33,11 @@ class ProjectMilestones < Spinach::FeatureSteps ...@@ -32,8 +33,11 @@ class ProjectMilestones < Spinach::FeatureSteps
And 'project "Shop" has milestone "v2.2"' do And 'project "Shop" has milestone "v2.2"' do
project = Project.find_by(name: "Shop") project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v2.2", project: project) milestone = create(:milestone,
title: "v2.2",
project: project,
description: "# Description header"
)
3.times { create(:issue, project: project, milestone: milestone) } 3.times { create(:issue, project: project, milestone: milestone) }
end end
......
module SharedMarkdown
include Spinach::DSL
def header_should_have_correct_id_and_link(level, text, id, parent = ".wiki")
page.find(:css, "#{parent} h#{level}##{id}").text.should == text
page.find(:css, "#{parent} h#{level}##{id} > :last-child")[:href].should =~ /##{id}$/
end
step 'Header "Description header" should have correct id and link' do
header_should_have_correct_id_and_link(1, 'Description header', 'description-header')
end
end
...@@ -102,4 +102,21 @@ module SharedNote ...@@ -102,4 +102,21 @@ module SharedNote
page.should have_content("XML attached") page.should have_content("XML attached")
end end
end end
# Markdown
step 'I leave a comment with a header containing "Comment with a header"' do
within(".js-main-target-form") do
fill_in "note[note]", with: "# Comment with a header"
click_button "Add Comment"
sleep 0.05
end
end
step 'The comment with the header should not have an ID' do
within(".note-text") do
page.should have_content("Comment with a header")
page.should_not have_css("#comment-with-a-header")
end
end
end end
...@@ -8,6 +8,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML ...@@ -8,6 +8,7 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
@project = @template.instance_variable_get("@project") @project = @template.instance_variable_get("@project")
@ref = @template.instance_variable_get("@ref") @ref = @template.instance_variable_get("@ref")
@request_path = @template.instance_variable_get("@path") @request_path = @template.instance_variable_get("@path")
@options = options.dup
super options super options
end end
...@@ -34,6 +35,16 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML ...@@ -34,6 +35,16 @@ class Redcarpet::Render::GitlabHTML < Redcarpet::Render::HTML
h.link_to_gfm(content, link, title: title) h.link_to_gfm(content, link, title: title)
end end
def header(text, level)
if @options[:no_header_anchors]
"<h#{level}>#{text}</h#{level}>"
else
id = ActionController::Base.helpers.strip_tags(h.gfm(text)).downcase() \
.gsub(/[^a-z0-9_-]/, '-').gsub(/-+/, '-').gsub(/^-/, '').gsub(/-$/, '')
"<h#{level} id=\"#{id}\">#{text}<a href=\"\##{id}\"></a></h#{level}>"
end
end
def preprocess(full_document) def preprocess(full_document)
if @project if @project
h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?) h.create_relative_links(full_document, @project, @ref, @request_path, is_wiki?)
......
...@@ -348,8 +348,21 @@ describe GitlabMarkdownHelper do ...@@ -348,8 +348,21 @@ describe GitlabMarkdownHelper do
it "should handle references in headers" do it "should handle references in headers" do
actual = "\n# Working around ##{issue.iid}\n## Apply !#{merge_request.iid}" actual = "\n# Working around ##{issue.iid}\n## Apply !#{merge_request.iid}"
markdown(actual).should match(%r{<h1[^<]*>Working around <a.+>##{issue.iid}</a></h1>}) markdown(actual, {no_header_anchors:true}).should match(%r{<h1[^<]*>Working around <a.+>##{issue.iid}</a></h1>})
markdown(actual).should match(%r{<h2[^<]*>Apply <a.+>!#{merge_request.iid}</a></h2>}) markdown(actual, {no_header_anchors:true}).should match(%r{<h2[^<]*>Apply <a.+>!#{merge_request.iid}</a></h2>})
end
it "should add ids and links to headers" do
# Test every rule except nested tags.
text = '..Ab_c-d. e..'
id = 'ab_c-d-e'
markdown("# #{text}").should match(%r{<h1 id="#{id}">#{text}<a href="[^"]*##{id}"></a></h1>})
markdown("# #{text}", {no_header_anchors:true}).should == "<h1>#{text}</h1>"
id = 'link-text'
markdown("# [link text](url) ![img alt](url)").should match(
%r{<h1 id="#{id}"><a href="[^"]*url">link text</a> <img[^>]*><a href="[^"]*##{id}"></a></h1>}
)
end end
it "should handle references in lists" do it "should handle references in lists" do
......
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