Yoginth 7 年之前
父节点
当前提交
998c279ad7
共有 4 个文件被更改,包括 20 次插入17 次删除
  1. 4 4
      models/repo.go
  2. 2 2
      pkg/markup/markdown.go
  3. 12 9
      pkg/markup/markup.go
  4. 2 2
      pkg/markup/markup_test.go

+ 4 - 4
models/repo.go

@@ -244,7 +244,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 = markup.ISSUE_NAME_STYLE_NUMERIC
+			repo.ExternalTrackerStyle = markup.IssueNameStyleNumeric
 		}
 	case "created_unix":
 		repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
@@ -456,10 +456,10 @@ func (repo *Repository) ComposeMetas() map[string]string {
 			"repo":   repo.Name,
 		}
 		switch repo.ExternalTrackerStyle {
-		case markup.ISSUE_NAME_STYLE_ALPHANUMERIC:
-			repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_ALPHANUMERIC
+		case markup.IssueNameStyleAlphaNumeric:
+			repo.ExternalMetas["style"] = markup.IssueNameStyleAlphaNumeric
 		default:
-			repo.ExternalMetas["style"] = markup.ISSUE_NAME_STYLE_NUMERIC
+			repo.ExternalMetas["style"] = markup.IssueNameStyleNumeric
 		}
 
 	}

+ 2 - 2
pkg/markup/markdown.go

@@ -106,7 +106,7 @@ func (r *MarkdownRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
 }
 
 // ListItem defines how list items should be processed to produce corresponding HTML elements.
-func (options *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
+func (r *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
 	// Detect procedures to draw checkboxes.
 	switch {
 	case bytes.HasPrefix(text, []byte("[ ] ")):
@@ -114,7 +114,7 @@ func (options *MarkdownRenderer) ListItem(out *bytes.Buffer, text []byte, flags
 	case bytes.HasPrefix(text, []byte("[x] ")):
 		text = append([]byte(`<input type="checkbox" disabled="" checked="" />`), text[3:]...)
 	}
-	options.Renderer.ListItem(out, text, flags)
+	r.Renderer.ListItem(out, text, flags)
 }
 
 // RawMarkdown renders content in Markdown syntax to HTML without handling special links.

+ 12 - 9
pkg/markup/markup.go

@@ -29,15 +29,18 @@ func IsIPythonNotebook(name string) bool {
 	return strings.HasSuffix(name, ".ipynb")
 }
 
+// Issue name style
 const (
-	ISSUE_NAME_STYLE_NUMERIC      = "numeric"
-	ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
+	IssueNameStyleNumeric      = "numeric"
+	IssueNameStyleAlphaNumeric = "alphanumeric"
 )
 
 var (
 	// MentionPattern matches string that mentions someone, e.g. @yoginth
-	MentionPattern   = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`)
-	CommitPattern    = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`)
+	MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`)
+	// CommitPattern matches string that commits
+	CommitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`)
+	// IssueFullPattern matches string that issue
 	IssueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`)
 	// IssueNumericPattern matches string that references to a numeric issue, e.g. #505
 	IssueNumericPattern = regexp.MustCompile(`( |^|\(|\[)#[0-9]+\b`)
@@ -46,9 +49,7 @@ var (
 	// CrossReferenceIssueNumericPattern matches string that references a numeric issue in a difference repository
 	// e.g. gitote/gitote#12345
 	CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+\b`)
-
-	// FIXME: this pattern matches pure numbers as well, right now we do a hack to check in RenderSha1CurrentPattern by converting string to a number.
-	// by converting string to a number.
+	// Sha1CurrentPattern by converting string to a number.
 	Sha1CurrentPattern = regexp.MustCompile(`\b[0-9a-f]{7,40}\b`)
 )
 
@@ -85,7 +86,7 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
 	urlPrefix = cutoutVerbosePrefix(urlPrefix)
 
 	pattern := IssueNumericPattern
-	if metas["style"] == ISSUE_NAME_STYLE_ALPHANUMERIC {
+	if metas["style"] == IssueNameStyleAlphaNumeric {
 		pattern = IssueAlphanumericPattern
 	}
 
@@ -100,7 +101,7 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
 			link = fmt.Sprintf(`<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)
 		} else {
 			// Support for external issue tracker
-			if metas["style"] == ISSUE_NAME_STYLE_ALPHANUMERIC {
+			if metas["style"] == IssueNameStyleAlphaNumeric {
 				metas["index"] = string(m)
 			} else {
 				metas["index"] = string(m[1:])
@@ -306,8 +307,10 @@ OUTER_LOOP:
 	return rawHTML
 }
 
+// Type holds type
 type Type string
 
+// Markup
 const (
 	UNRECOGNIZED     Type = "unrecognized"
 	MARKDOWN         Type = "markdown"

+ 2 - 2
pkg/markup/markup_test.go

@@ -155,7 +155,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) {
 			metas["format"] = "https://someurl.com/{user}/{repo}/{index}"
 			metas["user"] = "someuser"
 			metas["repo"] = "somerepo"
-			metas["style"] = ISSUE_NAME_STYLE_NUMERIC
+			metas["style"] = IssueNameStyleNumeric
 
 			Convey("should not render anything when there are no mentions", func() {
 				testCases := []string{
@@ -227,7 +227,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) {
 			metas["format"] = "https://someurl.com/{user}/{repo}/?b={index}"
 			metas["user"] = "someuser"
 			metas["repo"] = "somerepo"
-			metas["style"] = ISSUE_NAME_STYLE_ALPHANUMERIC
+			metas["style"] = IssueNameStyleAlphaNumeric
 			Convey("It should not render anything when there are no mentions", func() {
 				testCases := []string{
 					"",