diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-04-21 15:01:08 +0800 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-04-21 09:01:08 +0200 |
commit | 52627032bc55bd73694bea9e6e17df575b51664c (patch) | |
tree | 2324046a3936f5b5e68bf07ed7adaf083411b329 /routers | |
parent | f0db3da713eb9440923ddf376349e72b65f129ef (diff) | |
download | gitea-52627032bc55bd73694bea9e6e17df575b51664c.tar.gz gitea-52627032bc55bd73694bea9e6e17df575b51664c.zip |
Add markup package to prepare for org markup format (#1493)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/view.go | 27 | ||||
-rw-r--r-- | routers/repo/wiki.go | 3 |
2 files changed, 16 insertions, 14 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go index 51443a9452..2e4b2644cd 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -21,7 +21,7 @@ import ( "code.gitea.io/gitea/modules/highlight" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/markdown" + "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" "github.com/Unknwon/paginater" @@ -56,7 +56,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { var readmeFile *git.Blob for _, entry := range entries { - if entry.IsDir() || !markdown.IsReadmeFile(entry.Name()) { + if entry.IsDir() || !markup.IsReadmeFile(entry.Name()) { continue } @@ -87,17 +87,16 @@ func renderDirectory(ctx *context.Context, treeLink string) { if isTextFile { d, _ := ioutil.ReadAll(dataRc) buf = append(buf, d...) - switch { - case markdown.IsMarkdownFile(readmeFile.Name()): + newbuf := markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()) + if newbuf != nil { ctx.Data["IsMarkdown"] = true - buf = markdown.Render(buf, treeLink, ctx.Repo.Repository.ComposeMetas()) - default: + } else { // FIXME This is the only way to show non-markdown files // instead of a broken "View Raw" link ctx.Data["IsMarkdown"] = true - buf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1) + newbuf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1) } - ctx.Data["FileContent"] = string(buf) + ctx.Data["FileContent"] = string(newbuf) } } @@ -182,13 +181,15 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st d, _ := ioutil.ReadAll(dataRc) buf = append(buf, d...) - isMarkdown := markdown.IsMarkdownFile(blob.Name()) - ctx.Data["IsMarkdown"] = isMarkdown + tp := markup.Type(blob.Name()) + isSupportedMarkup := tp != "" + // FIXME: currently set IsMarkdown for compitable + ctx.Data["IsMarkdown"] = isSupportedMarkup - readmeExist := isMarkdown || markdown.IsReadmeFile(blob.Name()) + readmeExist := isSupportedMarkup || markup.IsReadmeFile(blob.Name()) ctx.Data["ReadmeExist"] = readmeExist - if readmeExist && isMarkdown { - ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) + if readmeExist && isSupportedMarkup { + ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) } else { // Building code view blocks with line number on server side. var fileContent string diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index c1c05d305a..2dcf37cc86 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/markdown" + "code.gitea.io/gitea/modules/markup" ) const ( @@ -322,7 +323,7 @@ func Wiki(ctx *context.Context) { } ename := entry.Name() - if !markdown.IsMarkdownFile(ename) { + if markup.Type(ename) != markdown.MarkupName { ext := strings.ToUpper(filepath.Ext(ename)) ctx.Data["FormatWarning"] = fmt.Sprintf("%s rendering is not supported at the moment. Rendered as Markdown.", ext) } |