diff options
author | Joe Chen <jc@unknwon.io> | 2022-01-13 11:27:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 11:27:16 +0800 |
commit | 9ae80a6173132c54fb0fb9f094b3e472a10e1f3f (patch) | |
tree | 4ba9fd4de2fbba3a986a772e337ce71be9845636 /internal/markup | |
parent | c8476b1c2e5dc8e430713722daa0bc4ba5e07103 (diff) |
chore: rename few consts to camel case (#6725)
Diffstat (limited to 'internal/markup')
-rw-r--r-- | internal/markup/markdown.go | 6 | ||||
-rw-r--r-- | internal/markup/markup.go | 36 | ||||
-rw-r--r-- | internal/markup/markup_test.go | 4 | ||||
-rw-r--r-- | internal/markup/orgmode.go | 2 |
4 files changed, 24 insertions, 24 deletions
diff --git a/internal/markup/markdown.go b/internal/markup/markdown.go index 0d4cdd2a..ab0b9cd2 100644 --- a/internal/markup/markdown.go +++ b/internal/markup/markdown.go @@ -105,7 +105,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("[ ] ")): @@ -113,7 +113,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. @@ -162,5 +162,5 @@ func RawMarkdown(body []byte, urlPrefix string) []byte { // Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links. func Markdown(input interface{}, urlPrefix string, metas map[string]string) []byte { - return Render(MARKDOWN, input, urlPrefix, metas) + return Render(TypeMarkdown, input, urlPrefix, metas) } diff --git a/internal/markup/markup.go b/internal/markup/markup.go index ae19ddeb..d4784ff6 100644 --- a/internal/markup/markup.go +++ b/internal/markup/markup.go @@ -29,8 +29,8 @@ func IsIPythonNotebook(name string) bool { } const ( - ISSUE_NAME_STYLE_NUMERIC = "numeric" - ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric" + IssueNameStyleNumeric = "numeric" + IssueNameStyleAlphanumeric = "alphanumeric" ) var ( @@ -90,7 +90,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 } @@ -105,7 +105,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:]) @@ -243,7 +243,7 @@ func postProcessHTML(rawHTML []byte, urlPrefix string, metas map[string]string) buf := bytes.NewBuffer(nil) tokenizer := html.NewTokenizer(bytes.NewReader(rawHTML)) -OUTER_LOOP: +outerLoop: for html.ErrorToken != tokenizer.Next() { token := tokenizer.Token() switch token.Type { @@ -255,7 +255,7 @@ OUTER_LOOP: if tagName == "img" { wrapImgWithLink(urlPrefix, buf, token) - continue OUTER_LOOP + continue outerLoop } buf.WriteString(token.String()) @@ -268,7 +268,7 @@ OUTER_LOOP: // Copy the token to the output verbatim buf.WriteString(token.String()) - // Stack number doesn't increate for tags without end tags. + // Stack number doesn't increase for tags without end tags. if token.Type == html.StartTagToken && !com.IsSliceContainsStr(noEndTags, token.Data) { stackNum++ } @@ -281,7 +281,7 @@ OUTER_LOOP: } } } - continue OUTER_LOOP + continue outerLoop } if !com.IsSliceContainsStr(noEndTags, tagName) { @@ -315,23 +315,23 @@ OUTER_LOOP: type Type string const ( - UNRECOGNIZED Type = "unrecognized" - MARKDOWN Type = "markdown" - ORG_MODE Type = "orgmode" - IPYTHON_NOTEBOOK Type = "ipynb" + TypeUnrecognized Type = "unrecognized" + TypeMarkdown Type = "markdown" + TypeOrgMode Type = "orgmode" + TypeIPythonNotebook Type = "ipynb" ) // Detect returns best guess of a markup type based on file name. func Detect(filename string) Type { switch { case IsMarkdownFile(filename): - return MARKDOWN + return TypeMarkdown case IsOrgModeFile(filename): - return ORG_MODE + return TypeOrgMode case IsIPythonNotebook(filename): - return IPYTHON_NOTEBOOK + return TypeIPythonNotebook default: - return UNRECOGNIZED + return TypeUnrecognized } } @@ -350,9 +350,9 @@ func Render(typ Type, input interface{}, urlPrefix string, metas map[string]stri urlPrefix = strings.TrimRight(strings.Replace(urlPrefix, " ", "%20", -1), "/") var rawHTML []byte switch typ { - case MARKDOWN: + case TypeMarkdown: rawHTML = RawMarkdown(rawBytes, urlPrefix) - case ORG_MODE: + case TypeOrgMode: rawHTML = RawOrgMode(rawBytes, urlPrefix) default: return rawBytes // Do nothing if syntax type is not recognized diff --git a/internal/markup/markup_test.go b/internal/markup/markup_test.go index df6213e6..0c1370cb 100644 --- a/internal/markup/markup_test.go +++ b/internal/markup/markup_test.go @@ -110,7 +110,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) { "format": "https://someurl.com/{user}/{repo}/{index}", "user": "someuser", "repo": "somerepo", - "style": ISSUE_NAME_STYLE_NUMERIC, + "style": IssueNameStyleNumeric, } tests := []struct { @@ -156,7 +156,7 @@ func Test_RenderIssueIndexPattern(t *testing.T) { "format": "https://someurl.com/{user}/{repo}/?b={index}", "user": "someuser", "repo": "somerepo", - "style": ISSUE_NAME_STYLE_ALPHANUMERIC, + "style": IssueNameStyleAlphanumeric, } tests := []struct { diff --git a/internal/markup/orgmode.go b/internal/markup/orgmode.go index 6fe1240a..467e455e 100644 --- a/internal/markup/orgmode.go +++ b/internal/markup/orgmode.go @@ -36,5 +36,5 @@ func RawOrgMode(body []byte, urlPrefix string) (result []byte) { // OrgMode takes a string or []byte and renders to HTML in Org-mode syntax with special links. func OrgMode(input interface{}, urlPrefix string, metas map[string]string) []byte { - return Render(ORG_MODE, input, urlPrefix, metas) + return Render(TypeOrgMode, input, urlPrefix, metas) } |