summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authormrsdizzie <info@mrsdizzie.com>2019-04-12 01:53:34 -0400
committerLauris BH <lauris@nix.lv>2019-04-12 08:53:34 +0300
commit3ff0a126e12109b6c3aceaa229dd1bf229b6ad4b (patch)
treed3201fa81e7b6dc01d238ec7b833456e47463d6c /routers/api/v1
parent3186ef554cdbf54e1a3328ffcb35ea18105d7cb1 (diff)
downloadgitea-3ff0a126e12109b6c3aceaa229dd1bf229b6ad4b.tar.gz
gitea-3ff0a126e12109b6c3aceaa229dd1bf229b6ad4b.zip
Improve issue autolinks (#6273)
* Improve issue autolinks Update autolinks to match what github does here: Issue in same repo: #1 Issue in different repo: org/repo#1 Fixes #6264 * Use setting.AppURL when parsing URL Using setting.AppURL here is a more reliable way of parsing the current URL and what other functions in this file seem to use. * Make ComposeMetas always return a valid context * Add per repository markdown renderers for better context * Update for use of context metas Now that we include the user and repo name inside context metas, update various code and tests for this new logic
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/api.go2
-rw-r--r--routers/api/v1/misc/markdown.go22
2 files changed, 21 insertions, 3 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 02c74e5056..4194d98db8 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -584,6 +584,8 @@ func RegisterRoutes(m *macaron.Macaron) {
Patch(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.EditLabelOption{}), repo.EditLabel).
Delete(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), repo.DeleteLabel)
})
+ m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
+ m.Post("/markdown/raw", misc.MarkdownRaw)
m.Group("/milestones", func() {
m.Combo("").Get(repo.ListMilestones).
Post(reqToken(), reqRepoWriter(models.UnitTypeIssues, models.UnitTypePullRequests), bind(api.CreateMilestoneOption{}), repo.CreateMilestone)
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
index 633dff98eb..9ae7a6c58c 100644
--- a/routers/api/v1/misc/markdown.go
+++ b/routers/api/v1/misc/markdown.go
@@ -5,12 +5,16 @@
package misc
import (
+ "strings"
+
api "code.gitea.io/sdk/gitea"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
+
+ "mvdan.cc/xurls/v2"
)
// Markdown render markdown document to HTML
@@ -45,11 +49,23 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
switch form.Mode {
case "gfm":
md := []byte(form.Text)
- context := util.URLJoin(setting.AppURL, form.Context)
+ urlPrefix := form.Context
+ var meta map[string]string
+ if !strings.HasPrefix(setting.AppSubURL+"/", urlPrefix) {
+ // check if urlPrefix is already set to a URL
+ linkRegex, _ := xurls.StrictMatchingScheme("https?://")
+ m := linkRegex.FindStringIndex(urlPrefix)
+ if m == nil {
+ urlPrefix = util.URLJoin(setting.AppURL, form.Context)
+ }
+ }
+ if ctx.Repo != nil && ctx.Repo.Repository != nil {
+ meta = ctx.Repo.Repository.ComposeMetas()
+ }
if form.Wiki {
- ctx.Write([]byte(markdown.RenderWiki(md, context, nil)))
+ ctx.Write([]byte(markdown.RenderWiki(md, urlPrefix, meta)))
} else {
- ctx.Write(markdown.Render(md, context, nil))
+ ctx.Write(markdown.Render(md, urlPrefix, meta))
}
default:
ctx.Write(markdown.RenderRaw([]byte(form.Text), "", false))