summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-09-17 01:17:57 +0800
committerLauris BH <lauris@nix.lv>2017-09-16 20:17:57 +0300
commit52e11b24bf5e395d83ea58c1b0fd6922efe16add (patch)
treef00c9da35c1f2afc3446b8607217e4d4315959ec /routers
parent911ca0215377b34559f2304a22dce863e219b255 (diff)
downloadgitea-52e11b24bf5e395d83ea58c1b0fd6922efe16add.tar.gz
gitea-52e11b24bf5e395d83ea58c1b0fd6922efe16add.zip
Restructure markup & markdown to prepare for multiple markup languageā€¦ (#2411)
* restructure markup & markdown to prepare for multiple markup languages support * adjust some functions between markdown and markup * fix tests * improve the comments
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/misc/markdown.go3
-rw-r--r--routers/api/v1/misc/markdown_test.go18
-rw-r--r--routers/init.go6
-rw-r--r--routers/repo/view.go5
4 files changed, 15 insertions, 17 deletions
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
index 933488301b..a2e65ecb0a 100644
--- a/routers/api/v1/misc/markdown.go
+++ b/routers/api/v1/misc/markdown.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/markdown"
+ "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
)
@@ -39,7 +40,7 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
switch form.Mode {
case "gfm":
md := []byte(form.Text)
- context := markdown.URLJoin(setting.AppURL, form.Context)
+ context := markup.URLJoin(setting.AppURL, form.Context)
if form.Wiki {
ctx.Write([]byte(markdown.RenderWiki(md, context, nil)))
} else {
diff --git a/routers/api/v1/misc/markdown_test.go b/routers/api/v1/misc/markdown_test.go
index d6e6193478..8c3051ea8e 100644
--- a/routers/api/v1/misc/markdown_test.go
+++ b/routers/api/v1/misc/markdown_test.go
@@ -1,23 +1,21 @@
package misc
import (
+ "io/ioutil"
"net/http"
"net/http/httptest"
- "testing"
-
- macaron "gopkg.in/macaron.v1"
-
"net/url"
-
- "io/ioutil"
"strings"
+ "testing"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/markdown"
+ "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/sdk/gitea"
+
"github.com/go-macaron/inject"
"github.com/stretchr/testify/assert"
+ macaron "gopkg.in/macaron.v1"
)
const AppURL = "http://localhost:3000/"
@@ -55,7 +53,7 @@ func TestAPI_RenderGFM(t *testing.T) {
Context: Repo,
Wiki: true,
}
- requrl, _ := url.Parse(markdown.URLJoin(AppURL, "api", "v1", "markdown"))
+ requrl, _ := url.Parse(markup.URLJoin(AppURL, "api", "v1", "markdown"))
req := &http.Request{
Method: "POST",
URL: requrl,
@@ -149,7 +147,7 @@ func TestAPI_RenderSimple(t *testing.T) {
Text: "",
Context: Repo,
}
- requrl, _ := url.Parse(markdown.URLJoin(AppURL, "api", "v1", "markdown"))
+ requrl, _ := url.Parse(markup.URLJoin(AppURL, "api", "v1", "markdown"))
req := &http.Request{
Method: "POST",
URL: requrl,
@@ -168,7 +166,7 @@ func TestAPI_RenderSimple(t *testing.T) {
func TestAPI_RenderRaw(t *testing.T) {
setting.AppURL = AppURL
- requrl, _ := url.Parse(markdown.URLJoin(AppURL, "api", "v1", "markdown"))
+ requrl, _ := url.Parse(markup.URLJoin(AppURL, "api", "v1", "markdown"))
req := &http.Request{
Method: "POST",
URL: requrl,
diff --git a/routers/init.go b/routers/init.go
index bd46abdf94..5113ec4cef 100644
--- a/routers/init.go
+++ b/routers/init.go
@@ -16,7 +16,7 @@ import (
"code.gitea.io/gitea/modules/indexer"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/mailer"
- "code.gitea.io/gitea/modules/markdown"
+ "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/ssh"
macaron "gopkg.in/macaron.v1"
@@ -50,8 +50,8 @@ func GlobalInit() {
if setting.InstallLock {
highlight.NewContext()
- markdown.InitMarkdown()
- markdown.NewSanitizer()
+ markup.Init()
+
if err := models.NewEngine(migrations.Migrate); err != nil {
log.Fatal(4, "Failed to initialize ORM engine: %v", err)
}
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 3a9e0e1d3b..991d2c0400 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -61,13 +61,12 @@ func renderDirectory(ctx *context.Context, treeLink string) {
continue
}
- tp, ok := markup.ReadmeFileType(entry.Name())
- if !ok {
+ if !markup.IsReadmeFile(entry.Name()) {
continue
}
readmeFile = entry.Blob()
- if tp != "" {
+ if markup.Type(entry.Name()) != "" {
break
}
}