Skip to content

Commit

Permalink
Restructure markup & markdown to prepare for multiple markup language… (
Browse files Browse the repository at this point in the history
go-gitea#2411)

* restructure markup & markdown to prepare for multiple markup languages support

* adjust some functions between markdown and markup

* fix tests

* improve the comments
  • Loading branch information
lunny authored and lafriks committed Sep 16, 2017
1 parent 911ca02 commit 52e11b2
Show file tree
Hide file tree
Showing 19 changed files with 1,189 additions and 1,092 deletions.
4 changes: 2 additions & 2 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
api "code.gitea.io/sdk/gitea"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/markup"
)

// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
Expand Down Expand Up @@ -272,7 +272,7 @@ func (c *Comment) LoadAssignees() error {
// MailParticipants sends new comment emails to repository watchers
// and mentioned people.
func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
mentions := markdown.FindAllMentions(c.Content)
mentions := markup.FindAllMentions(c.Content)
if err = UpdateIssueMentions(e, c.IssueID, mentions); err != nil {
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
}
Expand Down
4 changes: 2 additions & 2 deletions models/issue_mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/Unknwon/com"

"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func (issue *Issue) MailParticipants() (err error) {
}

func (issue *Issue) mailParticipants(e Engine) (err error) {
mentions := markdown.FindAllMentions(issue.Content)
mentions := markup.FindAllMentions(issue.Content)
if err = UpdateIssueMentions(e, issue.ID, mentions); err != nil {
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
}
Expand Down
3 changes: 2 additions & 1 deletion models/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"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"
"gopkg.in/gomail.v2"
"gopkg.in/macaron.v1"
Expand Down Expand Up @@ -150,7 +151,7 @@ func composeTplData(subject, body, link string) map[string]interface{} {

func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message {
subject := issue.mailSubject()
body := string(markdown.RenderString(issue.Content, issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))
body := string(markup.RenderByType(markdown.MarkupName, []byte(issue.Content), issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))

data := make(map[string]interface{}, 10)
if comment != nil {
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v16.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"time"

"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/markup"

"github.com/go-xorm/xorm"
)
Expand Down Expand Up @@ -101,7 +101,7 @@ func addUnitsToTables(x *xorm.Engine) error {
config["ExternalTrackerURL"] = repo.ExternalTrackerURL
config["ExternalTrackerFormat"] = repo.ExternalTrackerFormat
if len(repo.ExternalTrackerStyle) == 0 {
repo.ExternalTrackerStyle = markdown.IssueNameStyleNumeric
repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
}
config["ExternalTrackerStyle"] = repo.ExternalTrackerStyle
case V16UnitTypeExternalWiki:
Expand Down
10 changes: 5 additions & 5 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"code.gitea.io/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -480,10 +480,10 @@ func (repo *Repository) ComposeMetas() map[string]string {
"repo": repo.Name,
}
switch unit.ExternalTrackerConfig().ExternalTrackerStyle {
case markdown.IssueNameStyleAlphanumeric:
repo.ExternalMetas["style"] = markdown.IssueNameStyleAlphanumeric
case markup.IssueNameStyleAlphanumeric:
repo.ExternalMetas["style"] = markup.IssueNameStyleAlphanumeric
default:
repo.ExternalMetas["style"] = markdown.IssueNameStyleNumeric
repo.ExternalMetas["style"] = markup.IssueNameStyleNumeric
}

}
Expand Down Expand Up @@ -708,7 +708,7 @@ func (repo *Repository) DescriptionHTML() template.HTML {
sanitize := func(s string) string {
return fmt.Sprintf(`<a href="%[1]s" target="_blank" rel="noopener">%[1]s</a>`, s)
}
return template.HTML(descPattern.ReplaceAllStringFunc(markdown.Sanitize(repo.Description), sanitize))
return template.HTML(descPattern.ReplaceAllStringFunc(markup.Sanitize(repo.Description), sanitize))
}

// LocalCopyPath returns the local repository copy path
Expand Down
12 changes: 6 additions & 6 deletions models/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path"
"testing"

"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"

"github.com/Unknwon/com"
Expand Down Expand Up @@ -39,13 +39,13 @@ func TestRepo(t *testing.T) {
assert.Equal(t, "https://someurl.com/{user}/{repo}/{issue}", metas["format"])
}

testSuccess(markdown.IssueNameStyleNumeric)
testSuccess(markup.IssueNameStyleNumeric)

externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleAlphanumeric
testSuccess(markdown.IssueNameStyleAlphanumeric)
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleAlphanumeric
testSuccess(markup.IssueNameStyleAlphanumeric)

externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markdown.IssueNameStyleNumeric
testSuccess(markdown.IssueNameStyleNumeric)
externalTracker.ExternalTrackerConfig().ExternalTrackerStyle = markup.IssueNameStyleNumeric
testSuccess(markup.IssueNameStyleNumeric)
}

func TestGetRepositoryCount(t *testing.T) {
Expand Down
Loading

0 comments on commit 52e11b2

Please sign in to comment.