Skip to content

Commit 773c9cc

Browse files
committed
fix
1 parent fb42972 commit 773c9cc

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

docs/content/administration/mail-templates.en-us.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ This template produces something along these lines:
259259
The template system contains several functions that can be used to further process and format
260260
the messages. Here's a list of some of them:
261261

262-
| Name | Parameters | Available | Usage |
263-
| ---------------- | ----------- | --------- |-----------------------------------------------------------------------------|
264-
| `AppUrl` | - | Any | Gitea's URL |
265-
| `AppName` | - | Any | Set from `app.ini`, usually "Gitea" |
266-
| `AppDomain` | - | Any | Gitea's host name |
267-
| `EllipsisString` | string, int | Any | Truncates a string to the specified length; adds ellipsis as needed |
268-
| `SanitizeHTML` | string | Body only | Sanitizes text by removing any dangerous HTML tags from it. |
269-
| `SafeHTML` | string | Body only | Takes the input as HTML; can be used for `.ReviewComments.RenderedContent`. |
262+
| Name | Parameters | Available | Usage |
263+
| ---------------- | ----------- | --------- | ------------------------------------------------------------------- |
264+
| `AppUrl` | - | Any | Gitea's URL |
265+
| `AppName` | - | Any | Set from `app.ini`, usually "Gitea" |
266+
| `AppDomain` | - | Any | Gitea's host name |
267+
| `EllipsisString` | string, int | Any | Truncates a string to the specified length; adds ellipsis as needed |
268+
| `SanitizeHTML` | string | Body only | Sanitizes text by removing any dangerous HTML tags from it |
269+
| `SafeHTML` | string | Body only | Takes the input as HTML, can be used for outputing raw HTML content |
270270

271271
These are _functions_, not metadata, so they have to be used:
272272

docs/content/administration/mail-templates.zh-cn.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ _主题_ 和 _邮件正文_ 由 [Golang的模板引擎](https://go.dev/pkg/text/
242242

243243
模板系统包含一些函数,可用于进一步处理和格式化消息。以下是其中一些函数的列表:
244244

245-
| 函数名 | 参数 | 可用于 | 用法 |
246-
|------------------| ----------- | ------------ |---------------------------------------------------------|
247-
| `AppUrl` | - | 任何地方 | Gitea 的 URL |
248-
| `AppName` | - | 任何地方 |`app.ini` 中设置,通常为 "Gitea" |
249-
| `AppDomain` | - | 任何地方 | Gitea 的主机名 |
250-
| `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 |
251-
| `SanitizeHTML` | string | 仅正文部分 | 通过删除其中的危险 HTML 标签对文本进行清理 |
252-
| `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于 `.ReviewComments.RenderedContent` 等字段 |
245+
| 函数名 | 参数 | 可用于 | 用法 |
246+
|------------------| ----------- | ------------ | ------------------------------ |
247+
| `AppUrl` | - | 任何地方 | Gitea 的 URL |
248+
| `AppName` | - | 任何地方 |`app.ini` 中设置,通常为 "Gitea" |
249+
| `AppDomain` | - | 任何地方 | Gitea 的主机名 |
250+
| `EllipsisString` | string, int | 任何地方 | 将字符串截断为指定长度;根据需要添加省略号 |
251+
| `SanitizeHTML` | string | 仅正文部分 | 通过删除其中的危险 HTML 标签对文本进行清理 |
252+
| `SafeHTML` | string | 仅正文部分 | 将输入作为 HTML 处理;可用于输出原始的 HTML 内容 |
253253

254254
这些都是 _函数_,而不是元数据,因此必须按以下方式使用:
255255

modules/templates/mailer.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ func Mailer(ctx context.Context) (*texttmpl.Template, *template.Template) {
6464
bodyTemplates := template.New("")
6565

6666
subjectTemplates.Funcs(mailSubjectTextFuncMap())
67-
bodyTemplates.Funcs(NewFuncMap())
67+
// To do the best to avoid serious breaking, add some functions back for body templates.
68+
// Keep in mind that some behaviors have changed, for worse case, double-escaping.
69+
// Custom template users should migrate to the new template system ASAP.
70+
bodyTemplateFuncMap := NewFuncMap()
71+
bodyTemplateFuncMap["Safe"] = SafeHTML
72+
bodyTemplateFuncMap["Escape"] = HTMLEscape
73+
bodyTemplateFuncMap["Str2html"] = SanitizeHTML
74+
bodyTemplates.Funcs(bodyTemplateFuncMap)
6875

6976
assetFS := AssetFS()
7077
refreshTemplates := func(firstRun bool) {

templates/mail/issue/default.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
{{$.locale.Tr "mail.issue.in_tree_path" .TreePath}}
6666
<div class="review">
6767
<pre>{{.Patch}}</pre>
68-
<div>{{.RenderedContent | SafeHTML}}</div>
68+
<div>{{.RenderedContent}}</div>
6969
</div>
7070
{{end -}}
7171
{{if eq .ActionName "push"}}

0 commit comments

Comments
 (0)