mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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
This commit is contained in:
@@ -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.
|
||||
@@ -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)
|
||||
}
|
||||
|
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
@@ -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"
|
||||
@@ -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 {
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/markdown"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
@@ -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:
|
||||
|
@@ -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"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
@@ -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"
|
||||
@@ -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) {
|
||||
|
Reference in New Issue
Block a user