diff options
author | Andrew Boyarshin <andrew.boyarshin@gmail.com> | 2017-02-24 21:59:56 +0700 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-24 22:59:56 +0800 |
commit | 0602a44b276b009c1f7eb65c589ec284ef4131cf (patch) | |
tree | 8177d22a525e6bd7dcc535b58f1813c19ec9efac /routers/api/v1/misc | |
parent | 12e71e570619aa6f0e0289caa0b000158260065b (diff) | |
download | gitea-0602a44b276b009c1f7eb65c589ec284ef4131cf.tar.gz gitea-0602a44b276b009c1f7eb65c589ec284ef4131cf.zip |
Fix URL handling in the whole markdown module, improve test coverage (#1027)
Amended with string to bool change in API SDK.
Signed-off-by: Andrew Boyarshin <andrew.boyarshin@gmail.com>
Diffstat (limited to 'routers/api/v1/misc')
-rw-r--r-- | routers/api/v1/misc/markdown.go | 8 | ||||
-rw-r--r-- | routers/api/v1/misc/markdown_test.go | 5 |
2 files changed, 10 insertions, 3 deletions
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go index 947924dbed..188594e83e 100644 --- a/routers/api/v1/misc/markdown.go +++ b/routers/api/v1/misc/markdown.go @@ -27,7 +27,13 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) { switch form.Mode { case "gfm": - ctx.Write(markdown.Render([]byte(form.Text), markdown.URLJoin(setting.AppURL, form.Context), nil)) + md := []byte(form.Text) + context := markdown.URLJoin(setting.AppURL, form.Context) + if form.Wiki { + ctx.Write([]byte(markdown.RenderWiki(md, context, nil))) + } else { + ctx.Write(markdown.Render(md, context, nil)) + } default: ctx.Write(markdown.RenderRaw([]byte(form.Text), "", false)) } diff --git a/routers/api/v1/misc/markdown_test.go b/routers/api/v1/misc/markdown_test.go index 398e652d21..ae7a445e86 100644 --- a/routers/api/v1/misc/markdown_test.go +++ b/routers/api/v1/misc/markdown_test.go @@ -53,6 +53,7 @@ func TestAPI_RenderGFM(t *testing.T) { Mode: "gfm", Text: "", Context: Repo, + Wiki: true, } requrl, _ := url.Parse(markdown.URLJoin(AppURL, "api", "v1", "markdown")) req := &http.Request{ @@ -74,7 +75,7 @@ func TestAPI_RenderGFM(t *testing.T) { <ul> <li><a href="` + AppSubURL + `wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li> <li><a href="` + AppSubURL + `wiki/Tips" rel="nofollow">Tips</a></li> -<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>)<a href="` + AppSubURL + `issues/786" rel="nofollow">#786</a></li> +<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>)<a href="https://github.com/ocornut/imgui/issues/786" rel="nofollow">#786</a></li> </ul> `, // wine-staging wiki home extract: special wiki syntax, images @@ -97,7 +98,7 @@ Here are some links to the most important topics. You can find the full list of <p>Here are some links to the most important topics. You can find the full list of pages at the sidebar.</p> <p><a href="` + AppSubURL + `wiki/Configuration" rel="nofollow">Configuration</a> -<a href="` + AppSubURL + `wiki/raw/images%2Ficon-bug.png" rel="nofollow"><img src="` + AppSubURL + `wiki/raw/images%2Ficon-bug.png" alt="images/icon-bug.png" title="icon-bug.png"/></a></p> +<a href="` + AppSubURL + `wiki/raw/images/icon-bug.png" rel="nofollow"><img src="` + AppSubURL + `wiki/raw/images/icon-bug.png" alt="images/icon-bug.png" title="icon-bug.png"/></a></p> `, // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, |