|
|
@ -22,11 +22,13 @@ import (
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Issue name styles
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
ISSUE_NAME_STYLE_NUMERIC = "numeric"
|
|
|
|
IssueNameStyleNumeric = "numeric"
|
|
|
|
ISSUE_NAME_STYLE_ALPHANUMERIC = "alphanumeric"
|
|
|
|
IssueNameStyleAlphanumeric = "alphanumeric"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sanitizer markdown sanitizer
|
|
|
|
var Sanitizer = bluemonday.UGCPolicy()
|
|
|
|
var Sanitizer = bluemonday.UGCPolicy()
|
|
|
|
|
|
|
|
|
|
|
|
// BuildSanitizer initializes sanitizer with allowed attributes based on settings.
|
|
|
|
// BuildSanitizer initializes sanitizer with allowed attributes based on settings.
|
|
|
@ -163,7 +165,7 @@ func (r *Renderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ListItem defines how list items should be processed to produce corresponding HTML elements.
|
|
|
|
// 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.
|
|
|
|
// Detect procedures to draw checkboxes.
|
|
|
|
switch {
|
|
|
|
switch {
|
|
|
|
case bytes.HasPrefix(text, []byte("[ ] ")):
|
|
|
|
case bytes.HasPrefix(text, []byte("[ ] ")):
|
|
|
@ -171,7 +173,7 @@ func (options *Renderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
|
|
|
|
case bytes.HasPrefix(text, []byte("[x] ")):
|
|
|
|
case bytes.HasPrefix(text, []byte("[x] ")):
|
|
|
|
text = append([]byte(`<input type="checkbox" disabled="" checked="" />`), text[3:]...)
|
|
|
|
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
|
|
|
|
// Note: this section is for purpose of increase performance and
|
|
|
@ -235,7 +237,7 @@ func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string
|
|
|
|
urlPrefix = cutoutVerbosePrefix(urlPrefix)
|
|
|
|
urlPrefix = cutoutVerbosePrefix(urlPrefix)
|
|
|
|
|
|
|
|
|
|
|
|
pattern := IssueNumericPattern
|
|
|
|
pattern := IssueNumericPattern
|
|
|
|
if metas["style"] == ISSUE_NAME_STYLE_ALPHANUMERIC {
|
|
|
|
if metas["style"] == IssueNameStyleAlphanumeric {
|
|
|
|
pattern = IssueAlphanumericPattern
|
|
|
|
pattern = IssueAlphanumericPattern
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -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)
|
|
|
|
link = fmt.Sprintf(`<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Support for external issue tracker
|
|
|
|
// Support for external issue tracker
|
|
|
|
if metas["style"] == ISSUE_NAME_STYLE_ALPHANUMERIC {
|
|
|
|
if metas["style"] == IssueNameStyleAlphanumeric {
|
|
|
|
metas["index"] = string(m)
|
|
|
|
metas["index"] = string(m)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
metas["index"] = string(m[1:])
|
|
|
|
metas["index"] = string(m[1:])
|
|
|
@ -322,10 +324,10 @@ var noEndTags = []string{"img", "input", "br", "hr"}
|
|
|
|
|
|
|
|
|
|
|
|
// PostProcess treats different types of HTML differently,
|
|
|
|
// PostProcess treats different types of HTML differently,
|
|
|
|
// and only renders special links for plain text blocks.
|
|
|
|
// 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)
|
|
|
|
startTags := make([]string, 0, 5)
|
|
|
|
var buf bytes.Buffer
|
|
|
|
var buf bytes.Buffer
|
|
|
|
tokenizer := html.NewTokenizer(bytes.NewReader(rawHtml))
|
|
|
|
tokenizer := html.NewTokenizer(bytes.NewReader(rawHTML))
|
|
|
|
|
|
|
|
|
|
|
|
OUTER_LOOP:
|
|
|
|
OUTER_LOOP:
|
|
|
|
for html.ErrorToken != tokenizer.Next() {
|
|
|
|
for html.ErrorToken != tokenizer.Next() {
|
|
|
@ -387,7 +389,7 @@ OUTER_LOOP:
|
|
|
|
|
|
|
|
|
|
|
|
// If we are not at the end of the input, then some other parsing error has occurred,
|
|
|
|
// If we are not at the end of the input, then some other parsing error has occurred,
|
|
|
|
// so return the input verbatim.
|
|
|
|
// so return the input verbatim.
|
|
|
|
return rawHtml
|
|
|
|
return rawHTML
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Render renders Markdown to HTML with special links.
|
|
|
|
// Render renders Markdown to HTML with special links.
|
|
|
|