From 0602a44b276b009c1f7eb65c589ec284ef4131cf Mon Sep 17 00:00:00 2001 From: Andrew Boyarshin Date: Fri, 24 Feb 2017 21:59:56 +0700 Subject: 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 --- routers/api/v1/misc/markdown.go | 8 +++++++- routers/api/v1/misc/markdown_test.go | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'routers/api/v1/misc') 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) { `, // 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

Here are some links to the most important topics. You can find the full list of pages at the sidebar.

Configuration -images/icon-bug.png

+images/icon-bug.png

`, // Guard wiki sidebar: special syntax `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, -- cgit v1.2.3