mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 04:56:02 +01:00
Merge pull request #2249 from gitbucket/fix-markdown-link
Fix Markdown links in README at the file list view
This commit is contained in:
@@ -176,6 +176,10 @@ object Markdown {
|
|||||||
} else if (!enableWikiLink) {
|
} else if (!enableWikiLink) {
|
||||||
if (context.currentPath.contains("/blob/")) {
|
if (context.currentPath.contains("/blob/")) {
|
||||||
urlWithRawParam
|
urlWithRawParam
|
||||||
|
} else if (context.currentPath.contains("/tree/")) {
|
||||||
|
val paths = context.currentPath.split("/")
|
||||||
|
val path = if (paths.length > 3) paths.drop(4).mkString("/") else branch
|
||||||
|
repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + path + "/" + urlWithRawParam
|
||||||
} else {
|
} else {
|
||||||
repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + urlWithRawParam
|
repository.httpUrl.replaceFirst("/git/", "/").stripSuffix(".git") + "/blob/" + branch + "/" + urlWithRawParam
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package gitbucket.core.view
|
package gitbucket.core.view
|
||||||
|
|
||||||
|
import gitbucket.core.controller.Context
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import org.scalatest.FunSpec
|
import org.scalatest.FunSpec
|
||||||
|
import org.scalatest.mockito.MockitoSugar
|
||||||
|
import org.mockito.Mockito._
|
||||||
|
|
||||||
class MarkdownSpec extends FunSpec {
|
class MarkdownSpec extends FunSpec with MockitoSugar {
|
||||||
|
|
||||||
import Markdown._
|
import Markdown._
|
||||||
|
|
||||||
@@ -89,4 +93,69 @@ tasks
|
|||||||
assert(after == " -[ ] aaaa")
|
assert(after == " -[ ] aaaa")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
describe("toHtml") {
|
||||||
|
it("should fix url at the repository root") {
|
||||||
|
val repository = mock[RepositoryInfo]
|
||||||
|
val context = mock[Context]
|
||||||
|
when(context.currentPath).thenReturn("/user/repo")
|
||||||
|
when(repository.httpUrl(context)).thenReturn("http://localhost:8080/git/user/repo.git")
|
||||||
|
|
||||||
|
val html = Markdown.toHtml(
|
||||||
|
markdown = "[ChangeLog](CHANGELOG.md)",
|
||||||
|
repository = repository,
|
||||||
|
branch = "master",
|
||||||
|
enableWikiLink = false,
|
||||||
|
enableRefsLink = true,
|
||||||
|
enableAnchor = true,
|
||||||
|
enableLineBreaks = true
|
||||||
|
)(context)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
html == """<p><a href="http://localhost:8080/user/repo/blob/master/CHANGELOG.md">ChangeLog</a></p>"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should fix sub directory url at the file list") {
|
||||||
|
val repository = mock[RepositoryInfo]
|
||||||
|
val context = mock[Context]
|
||||||
|
when(context.currentPath).thenReturn("/user/repo/tree/master/sub/dir")
|
||||||
|
when(repository.httpUrl(context)).thenReturn("http://localhost:8080/git/user/repo.git")
|
||||||
|
|
||||||
|
val html = Markdown.toHtml(
|
||||||
|
markdown = "[ChangeLog](CHANGELOG.md)",
|
||||||
|
repository = repository,
|
||||||
|
branch = "master",
|
||||||
|
enableWikiLink = false,
|
||||||
|
enableRefsLink = true,
|
||||||
|
enableAnchor = true,
|
||||||
|
enableLineBreaks = true
|
||||||
|
)(context)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
html == """<p><a href="http://localhost:8080/user/repo/blob/master/sub/dir/CHANGELOG.md">ChangeLog</a></p>"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should fix sub directory url at the blob view") {
|
||||||
|
val repository = mock[RepositoryInfo]
|
||||||
|
val context = mock[Context]
|
||||||
|
when(context.currentPath).thenReturn("/user/repo/blob/master/sub/dir/README.md")
|
||||||
|
when(repository.httpUrl(context)).thenReturn("http://localhost:8080/git/user/repo.git")
|
||||||
|
|
||||||
|
val html = Markdown.toHtml(
|
||||||
|
markdown = "[ChangeLog](CHANGELOG.md)",
|
||||||
|
repository = repository,
|
||||||
|
branch = "master",
|
||||||
|
enableWikiLink = false,
|
||||||
|
enableRefsLink = true,
|
||||||
|
enableAnchor = true,
|
||||||
|
enableLineBreaks = true
|
||||||
|
)(context)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
html == """<p><a href="CHANGELOG.md">ChangeLog</a></p>"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user