Browse Source

modules: rename markdown -> markup

To further support more markup languages (e.g. Org-mode, AsciiDoc,
reStructuredText), the name 'markdown' is inappropriate.

This is the first step towards more markup language support.
pull/4017/merge
Unknwon 8 years ago
parent
commit
c1c269d9ef
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 4
      models/comment.go
  2. 4
      models/issue_mail.go
  3. 10
      models/repo.go
  4. 2
      models/repo_test.go
  5. 4
      modules/mailer/mail.go
  6. 2
      modules/markup/markdown.go
  7. 4
      modules/markup/markdown_test.go
  8. 6
      modules/template/template.go
  9. 8
      routers/api/v1/misc/markdown.go
  10. 4
      routers/install.go
  11. 12
      routers/repo/issue.go
  12. 6
      routers/repo/release.go
  13. 14
      routers/repo/view.go
  14. 4
      routers/repo/wiki.go

4
models/comment.go

@ -16,7 +16,7 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/models/errors" "github.com/gogits/gogs/models/errors"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
) )
// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference. // CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
@ -168,7 +168,7 @@ func (c *Comment) EventTag() string {
// mailParticipants sends new comment emails to repository watchers // mailParticipants sends new comment emails to repository watchers
// and mentioned people. // and mentioned people.
func (cmt *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (err error) { func (cmt *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
mentions := markdown.FindAllMentions(cmt.Content) mentions := markup.FindAllMentions(cmt.Content)
if err = updateIssueMentions(e, cmt.IssueID, mentions); err != nil { if err = updateIssueMentions(e, cmt.IssueID, mentions); err != nil {
return fmt.Errorf("UpdateIssueMentions [%d]: %v", cmt.IssueID, err) return fmt.Errorf("UpdateIssueMentions [%d]: %v", cmt.IssueID, err)
} }

4
models/issue_mail.go

@ -11,7 +11,7 @@ import (
log "gopkg.in/clog.v1" log "gopkg.in/clog.v1"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -162,7 +162,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
// MailParticipants sends new issue thread created emails to repository watchers // MailParticipants sends new issue thread created emails to repository watchers
// and mentioned people. // and mentioned people.
func (issue *Issue) MailParticipants() (err error) { func (issue *Issue) MailParticipants() (err error) {
mentions := markdown.FindAllMentions(issue.Content) mentions := markup.FindAllMentions(issue.Content)
if err = updateIssueMentions(x, issue.ID, mentions); err != nil { if err = updateIssueMentions(x, issue.ID, mentions); err != nil {
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
} }

10
models/repo.go

@ -28,7 +28,7 @@ import (
"github.com/gogits/gogs/models/errors" "github.com/gogits/gogs/models/errors"
"github.com/gogits/gogs/modules/bindata" "github.com/gogits/gogs/modules/bindata"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/process" "github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/sync" "github.com/gogits/gogs/modules/sync"
@ -219,7 +219,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
case "external_tracker_style": case "external_tracker_style":
if len(repo.ExternalTrackerStyle) == 0 { if len(repo.ExternalTrackerStyle) == 0 {
repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC
} }
case "created_unix": case "created_unix":
repo.Created = time.Unix(repo.CreatedUnix, 0).Local() repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
@ -356,10 +356,10 @@ func (repo *Repository) ComposeMetas() map[string]string {
"repo": repo.Name, "repo": repo.Name,
} }
switch repo.ExternalTrackerStyle { switch repo.ExternalTrackerStyle {
case markdown.ISSUE_NAME_STYLE_ALPHANUMERIC: case markup.ISSUE_NAME_STYLE_ALPHANUMERIC:
repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_ALPHANUMERIC repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
default: default:
repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_NUMERIC repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_NUMERIC
} }
} }

2
models/repo_test.go

@ -5,7 +5,7 @@ import (
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"testing" "testing"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
) )
func TestRepo(t *testing.T) { func TestRepo(t *testing.T) {

4
modules/mailer/mail.go

@ -13,7 +13,7 @@ import (
"gopkg.in/macaron.v1" "gopkg.in/macaron.v1"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -174,7 +174,7 @@ func composeTplData(subject, body, link string) map[string]interface{} {
func composeIssueMessage(issue Issue, repo Repository, doer User, tplName base.TplName, tos []string, info string) *Message { func composeIssueMessage(issue Issue, repo Repository, doer User, tplName base.TplName, tos []string, info string) *Message {
subject := issue.MailSubject() subject := issue.MailSubject()
body := string(markdown.RenderSpecialLink([]byte(issue.Content()), repo.HTMLURL(), repo.ComposeMetas())) body := string(markup.RenderSpecialLink([]byte(issue.Content()), repo.HTMLURL(), repo.ComposeMetas()))
data := composeTplData(subject, body, issue.HTMLURL()) data := composeTplData(subject, body, issue.HTMLURL())
data["Doer"] = doer data["Doer"] = doer
content, err := mailRender.HTMLString(string(tplName), data) content, err := mailRender.HTMLString(string(tplName), data)

2
modules/markdown/markdown.go → modules/markup/markdown.go

@ -2,7 +2,7 @@
// Use of this source code is governed by a MIT-style // Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package markdown package markup
import ( import (
"bytes" "bytes"

4
modules/markdown/markdown_test.go → modules/markup/markdown_test.go

@ -1,7 +1,7 @@
package markdown_test package markup_test
import ( import (
. "github.com/gogits/gogs/modules/markdown" . "github.com/gogits/gogs/modules/markup"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"testing" "testing"

6
modules/template/template.go

@ -23,7 +23,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -125,7 +125,7 @@ func Safe(raw string) template.HTML {
} }
func Str2html(raw string) template.HTML { func Str2html(raw string) template.HTML {
return template.HTML(markdown.Sanitizer.Sanitize(raw)) return template.HTML(markup.Sanitizer.Sanitize(raw))
} }
func List(l *list.List) chan interface{} { func List(l *list.List) chan interface{} {
@ -201,7 +201,7 @@ func ReplaceLeft(s, old, new string) string {
// RenderCommitMessage renders commit message with XSS-safe and special links. // RenderCommitMessage renders commit message with XSS-safe and special links.
func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]string) template.HTML { func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]string) template.HTML {
cleanMsg := template.HTMLEscapeString(msg) cleanMsg := template.HTMLEscapeString(msg)
fullMessage := string(markdown.RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix, metas)) fullMessage := string(markup.RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix, metas))
msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n")
numLines := len(msgLines) numLines := len(msgLines)
if numLines == 0 { if numLines == 0 {

8
routers/api/v1/misc/markdown.go

@ -8,7 +8,7 @@ import (
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
) )
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document // https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
@ -25,9 +25,9 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
switch form.Mode { switch form.Mode {
case "gfm": case "gfm":
ctx.Write(markdown.Render([]byte(form.Text), form.Context, nil)) ctx.Write(markup.Render([]byte(form.Text), form.Context, nil))
default: default:
ctx.Write(markdown.RenderRaw([]byte(form.Text), "")) ctx.Write(markup.RenderRaw([]byte(form.Text), ""))
} }
} }
@ -38,5 +38,5 @@ func MarkdownRaw(ctx *context.APIContext) {
ctx.Error(422, "", err) ctx.Error(422, "", err)
return return
} }
ctx.Write(markdown.RenderRaw(body, "")) ctx.Write(markup.RenderRaw(body, ""))
} }

4
routers/install.go

@ -26,7 +26,7 @@ import (
"github.com/gogits/gogs/modules/cron" "github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/form" "github.com/gogits/gogs/modules/form"
"github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/ssh" "github.com/gogits/gogs/modules/ssh"
"github.com/gogits/gogs/modules/template/highlight" "github.com/gogits/gogs/modules/template/highlight"
@ -62,7 +62,7 @@ func GlobalInit() {
if setting.InstallLock { if setting.InstallLock {
highlight.NewContext() highlight.NewContext()
markdown.BuildSanitizer() markup.BuildSanitizer()
if err := models.NewEngine(); err != nil { if err := models.NewEngine(); err != nil {
log.Fatal(2, "Fail to initialize ORM engine: %v", err) log.Fatal(2, "Fail to initialize ORM engine: %v", err)
} }

12
routers/repo/issue.go

@ -22,7 +22,7 @@ import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/form" "github.com/gogits/gogs/modules/form"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -541,7 +541,7 @@ func viewIssue(ctx *context.Context, isPullList bool) {
ctx.Data["PageIsIssueList"] = true ctx.Data["PageIsIssueList"] = true
} }
issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink, issue.RenderedContent = string(markup.Render([]byte(issue.Content), ctx.Repo.RepoLink,
ctx.Repo.Repository.ComposeMetas())) ctx.Repo.Repository.ComposeMetas()))
repo := ctx.Repo.Repository repo := ctx.Repo.Repository
@ -608,7 +608,7 @@ func viewIssue(ctx *context.Context, isPullList bool) {
participants[0] = issue.Poster participants[0] = issue.Poster
for _, comment = range issue.Comments { for _, comment = range issue.Comments {
if comment.Type == models.COMMENT_TYPE_COMMENT { if comment.Type == models.COMMENT_TYPE_COMMENT {
comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink, comment.RenderedContent = string(markup.Render([]byte(comment.Content), ctx.Repo.RepoLink,
ctx.Repo.Repository.ComposeMetas())) ctx.Repo.Repository.ComposeMetas()))
// Check tag. // Check tag.
@ -728,7 +728,7 @@ func UpdateIssueContent(ctx *context.Context) {
} }
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), "content": string(markup.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
}) })
} }
@ -939,7 +939,7 @@ func UpdateCommentContent(ctx *context.Context) {
} }
ctx.JSON(200, map[string]interface{}{ ctx.JSON(200, map[string]interface{}{
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), "content": string(markup.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
}) })
} }
@ -1092,7 +1092,7 @@ func Milestones(ctx *context.Context) {
if m.NumOpenIssues+m.NumClosedIssues > 0 { if m.NumOpenIssues+m.NumClosedIssues > 0 {
m.Completeness = m.NumClosedIssues * 100 / (m.NumOpenIssues + m.NumClosedIssues) m.Completeness = m.NumClosedIssues * 100 / (m.NumOpenIssues + m.NumClosedIssues)
} }
m.RenderedContent = string(markdown.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())) m.RenderedContent = string(markup.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
} }
ctx.Data["Milestones"] = miles ctx.Data["Milestones"] = miles

6
routers/repo/release.go

@ -14,7 +14,7 @@ import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/form" "github.com/gogits/gogs/modules/form"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
@ -83,7 +83,7 @@ func Releases(ctx *context.Context) {
return return
} }
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) r.Note = markup.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
results[i] = r results[i] = r
break break
} }
@ -132,7 +132,7 @@ func Releases(ctx *context.Context) {
return return
} }
r.Note = markdown.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()) r.Note = markup.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
} }
if len(drafts) > 0 { if len(drafts) > 0 {

14
routers/repo/view.go

@ -20,7 +20,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/template" "github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/modules/template/highlight" "github.com/gogits/gogs/modules/template/highlight"
@ -55,7 +55,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
var readmeFile *git.Blob var readmeFile *git.Blob
for _, entry := range entries { for _, entry := range entries {
if entry.IsDir() || !markdown.IsReadmeFile(entry.Name()) { if entry.IsDir() || !markup.IsReadmeFile(entry.Name()) {
continue continue
} }
@ -86,9 +86,9 @@ func renderDirectory(ctx *context.Context, treeLink string) {
d, _ := ioutil.ReadAll(dataRc) d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...) buf = append(buf, d...)
switch { switch {
case markdown.IsMarkdownFile(readmeFile.Name()): case markup.IsMarkdownFile(readmeFile.Name()):
ctx.Data["IsMarkdown"] = true ctx.Data["IsMarkdown"] = true
buf = markdown.Render(buf, treeLink, ctx.Repo.Repository.ComposeMetas()) buf = markup.Render(buf, treeLink, ctx.Repo.Repository.ComposeMetas())
default: default:
buf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1) buf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
} }
@ -153,14 +153,14 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
d, _ := ioutil.ReadAll(dataRc) d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...) buf = append(buf, d...)
isMarkdown := markdown.IsMarkdownFile(blob.Name()) isMarkdown := markup.IsMarkdownFile(blob.Name())
ctx.Data["IsMarkdown"] = isMarkdown ctx.Data["IsMarkdown"] = isMarkdown
ctx.Data["ReadmeExist"] = isMarkdown && markdown.IsReadmeFile(blob.Name()) ctx.Data["ReadmeExist"] = isMarkdown && markup.IsReadmeFile(blob.Name())
ctx.Data["IsIPythonNotebook"] = strings.HasSuffix(blob.Name(), ".ipynb") ctx.Data["IsIPythonNotebook"] = strings.HasSuffix(blob.Name(), ".ipynb")
if isMarkdown { if isMarkdown {
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) ctx.Data["FileContent"] = string(markup.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
} else { } else {
// Building code view blocks with line number on server side. // Building code view blocks with line number on server side.
var fileContent string var fileContent string

4
routers/repo/wiki.go

@ -15,7 +15,7 @@ import (
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/form" "github.com/gogits/gogs/modules/form"
"github.com/gogits/gogs/modules/markdown" "github.com/gogits/gogs/modules/markup"
) )
const ( const (
@ -107,7 +107,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
return nil, "" return nil, ""
} }
if isViewPage { if isViewPage {
ctx.Data["content"] = string(markdown.Render(data, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())) ctx.Data["content"] = string(markup.Render(data, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
} else { } else {
ctx.Data["content"] = string(data) ctx.Data["content"] = string(data)
} }

Loading…
Cancel
Save