Skip to content

Blob and tree gfm links to anchors work.

Matthias Käppler requested to merge github/fork/booktree/link-with-id into master

Created by: cirosantilli

Fixes #6046 (closed) bug

Intended Behavior

When on a tree directory such as path/name/tree/branch/dir, in the rendered README.md:

[0]() | path/name/tree/branch/dir | current behavior. [1](#id) | path/name/tree/branch/dir#id | new. Before opened wiki. [2](file.md#id) | path/name/blob/branch/dir/file.md#id | new

When on a markdown blob such as path/name/blob/branch/dir/file.md:

[0]() | path/name/blob/branch/dir/file.md | current [1](#id) | path/name/blob/branch/dir/file.md#id | new [2](file2.md#id) | path/name/blob/branch/dir/file2.md#id | new

This differs slightly from GitHub behavior, in which [empty]() always points to a non existent URL.

I feel that this behavior makes more sense, because if "#a" points to the current file, then "" should too.

The following is the diff for the tests under spec/seed_project.tar.gz. Only the markdown branch was modified with a new commit added. Rationale is explianed on the comments under features/steps/project/project_markdown_render.rb and spec/factories.rb#project.

diff --git a/README.md b/README.md
index 7577fc5..96c09cf 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,11 @@
+This branch is meant to be used with for markdown tests.
+
+Do not rely on its commit message or SHA being constant.
+
# Welcome to GitLab [![build status](https://secure.travis-ci.org/gitlabhq/gitlabhq.png)](https://secure.travis-ci.org/gitlabhq/gitlabhq)

GitLab is a free project and repository management application

-
## Application details

* rails 3.1
@@ -53,3 +56,15 @@ Email

Want to help - send a pull request.
We'll accept good pull requests.
+
+# Links with IDs
+
+[empty]()
+
+[#id](#id)
+
+[/#id](/#id)
+
+[README.md#id](README.md#id)
+
+[d/README.md#id](db/README.md#id)
diff --git a/d/README.md b/d/README.md
new file mode 100644
index 0000000..78addd3
--- /dev/null
+++ b/d/README.md
@@ -0,0 +1,9 @@
+[empty]()
+
+[#id](#id)
+
+[/#id](/#id)
+
+[README.md#id](README.md#id)
+
+[d/README.md#id](db/README.md#id)

Merge request reports

Loading