mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-25 17:26:49 +09:00
Fix markup heading parsing, fix emphasis parsing (#36284)
Fixes #36106, fix #17958 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ package htmlutil
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
@@ -31,7 +32,7 @@ func ParseSizeAndClass(defaultSize int, defaultClass string, others ...any) (int
|
||||
return size, class
|
||||
}
|
||||
|
||||
func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
|
||||
func htmlFormatArgs(s template.HTML, rawArgs []any) []any {
|
||||
if !strings.Contains(string(s), "%") || len(rawArgs) == 0 {
|
||||
panic("HTMLFormat requires one or more arguments")
|
||||
}
|
||||
@@ -50,5 +51,35 @@ func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
|
||||
args[i] = template.HTMLEscapeString(fmt.Sprint(v))
|
||||
}
|
||||
}
|
||||
return template.HTML(fmt.Sprintf(string(s), args...))
|
||||
return args
|
||||
}
|
||||
|
||||
func HTMLFormat(s template.HTML, rawArgs ...any) template.HTML {
|
||||
return template.HTML(fmt.Sprintf(string(s), htmlFormatArgs(s, rawArgs)...))
|
||||
}
|
||||
|
||||
func HTMLPrintf(w io.Writer, s template.HTML, rawArgs ...any) (int, error) {
|
||||
return fmt.Fprintf(w, string(s), htmlFormatArgs(s, rawArgs)...)
|
||||
}
|
||||
|
||||
func HTMLPrint(w io.Writer, s template.HTML) (int, error) {
|
||||
return io.WriteString(w, string(s))
|
||||
}
|
||||
|
||||
func HTMLPrintTag(w io.Writer, tag template.HTML, attrs map[string]string) (written int, err error) {
|
||||
n, err := io.WriteString(w, "<"+string(tag))
|
||||
written += n
|
||||
if err != nil {
|
||||
return written, err
|
||||
}
|
||||
for k, v := range attrs {
|
||||
n, err = fmt.Fprintf(w, ` %s="%s"`, template.HTMLEscapeString(k), template.HTMLEscapeString(v))
|
||||
written += n
|
||||
if err != nil {
|
||||
return written, err
|
||||
}
|
||||
}
|
||||
n, err = io.WriteString(w, ">")
|
||||
written += n
|
||||
return written, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user