diff --git a/modules/htmlutil/html.go b/modules/htmlutil/html.go
index efbc174b2e..8dbfe0c22e 100644
--- a/modules/htmlutil/html.go
+++ b/modules/htmlutil/html.go
@@ -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
}
diff --git a/modules/markup/common/footnote.go b/modules/markup/common/footnote.go
index 1ece436c66..e552a28237 100644
--- a/modules/markup/common/footnote.go
+++ b/modules/markup/common/footnote.go
@@ -405,9 +405,9 @@ func (r *FootnoteHTMLRenderer) renderFootnoteLink(w util.BufWriter, source []byt
if entering {
n := node.(*FootnoteLink)
is := strconv.Itoa(n.Index)
- _, _ = w.WriteString(`