Skip to content

Golint fixed for modules/markdown #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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 = markdown.IssueNameStyleNumeric
}
case "created_unix":
repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
Expand Down Expand Up @@ -310,10 +310,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 markdown.IssueNameStyleAlphanumeric:
repo.ExternalMetas["style"] = markdown.IssueNameStyleAlphanumeric
default:
repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_NUMERIC
repo.ExternalMetas["style"] = markdown.IssueNameStyleNumeric
}

}
Expand Down
12 changes: 6 additions & 6 deletions models/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRepo(t *testing.T) {
Convey("It should be nil even if other settings are present", func() {
repo.EnableExternalTracker = false
repo.ExternalTrackerFormat = "http://someurl.com/{user}/{repo}/{issue}"
repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC
repo.ExternalTrackerStyle = markdown.IssueNameStyleNumeric
So(repo.ComposeMetas(), ShouldEqual, map[string]string(nil))
})
})
Expand All @@ -33,17 +33,17 @@ func TestRepo(t *testing.T) {
repo.EnableExternalTracker = true
Convey("It should default to numeric issue style", func() {
metas := repo.ComposeMetas()
So(metas["style"], ShouldEqual, markdown.ISSUE_NAME_STYLE_NUMERIC)
So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
})
Convey("It should pass through numeric issue style setting", func() {
repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC
repo.ExternalTrackerStyle = markdown.IssueNameStyleNumeric
metas := repo.ComposeMetas()
So(metas["style"], ShouldEqual, markdown.ISSUE_NAME_STYLE_NUMERIC)
So(metas["style"], ShouldEqual, markdown.IssueNameStyleNumeric)
})
Convey("It should pass through alphanumeric issue style setting", func() {
repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_ALPHANUMERIC
repo.ExternalTrackerStyle = markdown.IssueNameStyleAlphanumeric
metas := repo.ComposeMetas()
So(metas["style"], ShouldEqual, markdown.ISSUE_NAME_STYLE_ALPHANUMERIC)
So(metas["style"], ShouldEqual, markdown.IssueNameStyleAlphanumeric)
})
Convey("It should contain the user name", func() {
metas := repo.ComposeMetas()
Expand Down
20 changes: 11 additions & 9 deletions modules/markdown/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"code.gitea.io/gitea/modules/setting"
)

// Issue name styles
const (
ISSUE_NAME_STYLE_NUMERIC = "numeric"
ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
IssueNameStyleNumeric = "numeric"
IssueNameStyleAlphanumeric = "alphanumeric"
)

// Sanitizer markdown sanitizer
var Sanitizer = bluemonday.UGCPolicy()

// BuildSanitizer initializes sanitizer with allowed attributes based on settings.
Expand Down Expand Up @@ -163,15 +165,15 @@ func (r *Renderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
}

// ListItem defines how list items should be processed to produce corresponding HTML elements.
func (options *Renderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
func (r *Renderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
// Detect procedures to draw checkboxes.
switch {
case bytes.HasPrefix(text, []byte("[ ] ")):
text = append([]byte(`<input type="checkbox" disabled="" />`), text[3:]...)
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)
}

// Note: this section is for purpose of increase performance and
Expand Down Expand Up @@ -235,7 +237,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
}

Expand All @@ -249,7 +251,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:])
Expand Down Expand Up @@ -322,10 +324,10 @@ var noEndTags = []string{"img", "input", "br", "hr"}

// PostProcess treats different types of HTML differently,
// and only renders special links for plain text blocks.
func PostProcess(rawHtml []byte, urlPrefix string, metas map[string]string) []byte {
func PostProcess(rawHTML []byte, urlPrefix string, metas map[string]string) []byte {
startTags := make([]string, 0, 5)
var buf bytes.Buffer
tokenizer := html.NewTokenizer(bytes.NewReader(rawHtml))
tokenizer := html.NewTokenizer(bytes.NewReader(rawHTML))

OUTER_LOOP:
for html.ErrorToken != tokenizer.Next() {
Expand Down Expand Up @@ -387,7 +389,7 @@ OUTER_LOOP:

// If we are not at the end of the input, then some other parsing error has occurred,
// so return the input verbatim.
return rawHtml
return rawHTML
}

// Render renders Markdown to HTML with special links.
Expand Down
4 changes: 2 additions & 2 deletions modules/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestMarkdown(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{
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestMarkdown(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{
"",
Expand Down