From c1c269d9ef50595475cf4c6728d9b20a6417c490 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 31 Mar 2017 15:29:43 -0400 Subject: [PATCH] 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. --- models/comment.go | 4 ++-- models/issue_mail.go | 4 ++-- models/repo.go | 10 +++++----- models/repo_test.go | 2 +- modules/mailer/mail.go | 4 ++-- modules/{markdown => markup}/markdown.go | 2 +- modules/{markdown => markup}/markdown_test.go | 4 ++-- modules/template/template.go | 6 +++--- routers/api/v1/misc/markdown.go | 8 ++++---- routers/install.go | 4 ++-- routers/repo/issue.go | 12 ++++++------ routers/repo/release.go | 6 +++--- routers/repo/view.go | 14 +++++++------- routers/repo/wiki.go | 4 ++-- 14 files changed, 42 insertions(+), 42 deletions(-) rename modules/{markdown => markup}/markdown.go (99%) rename modules/{markdown => markup}/markdown_test.go (99%) diff --git a/models/comment.go b/models/comment.go index 2b5ac923e..7a46f6f86 100644 --- a/models/comment.go +++ b/models/comment.go @@ -16,7 +16,7 @@ import ( api "github.com/gogits/go-gogs-client" "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. @@ -168,7 +168,7 @@ func (c *Comment) EventTag() string { // mailParticipants sends new comment emails to repository watchers // and mentioned people. 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 { return fmt.Errorf("UpdateIssueMentions [%d]: %v", cmt.IssueID, err) } diff --git a/models/issue_mail.go b/models/issue_mail.go index be653b89d..d04472618 100644 --- a/models/issue_mail.go +++ b/models/issue_mail.go @@ -11,7 +11,7 @@ import ( log "gopkg.in/clog.v1" "github.com/gogits/gogs/modules/mailer" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" "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 // and mentioned people. 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 { return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) } diff --git a/models/repo.go b/models/repo.go index a597f82ed..b12ed58e2 100644 --- a/models/repo.go +++ b/models/repo.go @@ -28,7 +28,7 @@ import ( "github.com/gogits/gogs/models/errors" "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/setting" "github.com/gogits/gogs/modules/sync" @@ -219,7 +219,7 @@ func (repo *Repository) AfterSet(colName string, _ xorm.Cell) { repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones case "external_tracker_style": if len(repo.ExternalTrackerStyle) == 0 { - repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC + repo.ExternalTrackerStyle = markup.ISSUE_NAME_STYLE_NUMERIC } case "created_unix": repo.Created = time.Unix(repo.CreatedUnix, 0).Local() @@ -356,10 +356,10 @@ func (repo *Repository) ComposeMetas() map[string]string { "repo": repo.Name, } switch repo.ExternalTrackerStyle { - case markdown.ISSUE_NAME_STYLE_ALPHANUMERIC: - repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_ALPHANUMERIC + case markup.ISSUE_NAME_STYLE_ALPHANUMERIC: + repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_ALPHANUMERIC default: - repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_NUMERIC + repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_NUMERIC } } diff --git a/models/repo_test.go b/models/repo_test.go index 69d90b938..653a0962d 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -5,7 +5,7 @@ import ( . "github.com/smartystreets/goconvey/convey" "testing" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" ) func TestRepo(t *testing.T) { diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index b65073a1d..955432944 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -13,7 +13,7 @@ import ( "gopkg.in/macaron.v1" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" "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 { 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["Doer"] = doer content, err := mailRender.HTMLString(string(tplName), data) diff --git a/modules/markdown/markdown.go b/modules/markup/markdown.go similarity index 99% rename from modules/markdown/markdown.go rename to modules/markup/markdown.go index 6101670cf..fa91553ab 100644 --- a/modules/markdown/markdown.go +++ b/modules/markup/markdown.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -package markdown +package markup import ( "bytes" diff --git a/modules/markdown/markdown_test.go b/modules/markup/markdown_test.go similarity index 99% rename from modules/markdown/markdown_test.go rename to modules/markup/markdown_test.go index d4071ba35..2d06a149f 100644 --- a/modules/markdown/markdown_test.go +++ b/modules/markup/markdown_test.go @@ -1,7 +1,7 @@ -package markdown_test +package markup_test import ( - . "github.com/gogits/gogs/modules/markdown" + . "github.com/gogits/gogs/modules/markup" . "github.com/smartystreets/goconvey/convey" "testing" diff --git a/modules/template/template.go b/modules/template/template.go index acdfab8d8..0bd5fa3f1 100644 --- a/modules/template/template.go +++ b/modules/template/template.go @@ -23,7 +23,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" "github.com/gogits/gogs/modules/setting" ) @@ -125,7 +125,7 @@ func Safe(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{} { @@ -201,7 +201,7 @@ func ReplaceLeft(s, old, new string) string { // RenderCommitMessage renders commit message with XSS-safe and special links. func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]string) template.HTML { 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") numLines := len(msgLines) if numLines == 0 { diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go index 64895db07..58ff93f50 100644 --- a/routers/api/v1/misc/markdown.go +++ b/routers/api/v1/misc/markdown.go @@ -8,7 +8,7 @@ import ( api "github.com/gogits/go-gogs-client" "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 @@ -25,9 +25,9 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) { switch form.Mode { case "gfm": - ctx.Write(markdown.Render([]byte(form.Text), form.Context, nil)) + ctx.Write(markup.Render([]byte(form.Text), form.Context, nil)) 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) return } - ctx.Write(markdown.RenderRaw(body, "")) + ctx.Write(markup.RenderRaw(body, "")) } diff --git a/routers/install.go b/routers/install.go index 0a8569341..2e6bee100 100644 --- a/routers/install.go +++ b/routers/install.go @@ -26,7 +26,7 @@ import ( "github.com/gogits/gogs/modules/cron" "github.com/gogits/gogs/modules/form" "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/ssh" "github.com/gogits/gogs/modules/template/highlight" @@ -62,7 +62,7 @@ func GlobalInit() { if setting.InstallLock { highlight.NewContext() - markdown.BuildSanitizer() + markup.BuildSanitizer() if err := models.NewEngine(); err != nil { log.Fatal(2, "Fail to initialize ORM engine: %v", err) } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 4ab8bc9bd..917bcad5e 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -22,7 +22,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/form" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" "github.com/gogits/gogs/modules/setting" ) @@ -541,7 +541,7 @@ func viewIssue(ctx *context.Context, isPullList bool) { 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())) repo := ctx.Repo.Repository @@ -608,7 +608,7 @@ func viewIssue(ctx *context.Context, isPullList bool) { participants[0] = issue.Poster for _, comment = range issue.Comments { 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())) // Check tag. @@ -728,7 +728,7 @@ func UpdateIssueContent(ctx *context.Context) { } 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{}{ - "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 { 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 diff --git a/routers/repo/release.go b/routers/repo/release.go index 5c6ba4eaf..b25add772 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -14,7 +14,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/form" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" "github.com/gogits/gogs/modules/setting" ) @@ -83,7 +83,7 @@ func Releases(ctx *context.Context) { 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 break } @@ -132,7 +132,7 @@ func Releases(ctx *context.Context) { 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 { diff --git a/routers/repo/view.go b/routers/repo/view.go index 8b68d188c..a97c67056 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -20,7 +20,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "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/template" "github.com/gogits/gogs/modules/template/highlight" @@ -55,7 +55,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 } @@ -86,9 +86,9 @@ func renderDirectory(ctx *context.Context, treeLink string) { d, _ := ioutil.ReadAll(dataRc) buf = append(buf, d...) switch { - case markdown.IsMarkdownFile(readmeFile.Name()): + case markup.IsMarkdownFile(readmeFile.Name()): ctx.Data["IsMarkdown"] = true - buf = markdown.Render(buf, treeLink, ctx.Repo.Repository.ComposeMetas()) + buf = markup.Render(buf, treeLink, ctx.Repo.Repository.ComposeMetas()) default: buf = bytes.Replace(buf, []byte("\n"), []byte(`
`), -1) } @@ -153,14 +153,14 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st d, _ := ioutil.ReadAll(dataRc) buf = append(buf, d...) - isMarkdown := markdown.IsMarkdownFile(blob.Name()) + isMarkdown := markup.IsMarkdownFile(blob.Name()) 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") 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 { // 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 df8d78a3a..e0c5fdc59 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -15,7 +15,7 @@ import ( "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/context" "github.com/gogits/gogs/modules/form" - "github.com/gogits/gogs/modules/markdown" + "github.com/gogits/gogs/modules/markup" ) const ( @@ -107,7 +107,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str return nil, "" } 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 { ctx.Data["content"] = string(data) }