Refactor flash message and remove SanitizeHTML template func (#37179)

1. Fix the "flash message" layout problem for different cases
* I am sure most of the users should have ever seen the ugly
center-aligned error message with multiple lines.
2. Fix inconsistent "Details" flash message EOL handling, sometimes
`\n`, sometimes `<br>`
   * Now, always use "\n" and use `<pre>` to render
3. Remove SanitizeHTML template func because it is not useful and can be
easily abused.
* But it is still kept for mail templates, for example:
https://github.com/go-gitea/gitea/issues/36049
4. Clarify PostProcessCommitMessage's behavior and add FIXME comment

By the way: cleaned up some devtest pages, move embedded style block to
CSS file
This commit is contained in:
wxiaoguang
2026-04-12 10:17:25 +08:00
committed by GitHub
parent ba9258c478
commit 8fcbdf05b0
29 changed files with 159 additions and 113 deletions

View File

@@ -1,4 +1,4 @@
{{template "base/head" ctx.RootData}}
<link rel="stylesheet" href="{{AssetURI "css/devtest.css"}}">
<div class="tw-hidden" data-global-init="initDevtestPage"></div>
{{template "base/alert" .}}
<div class="ui container tw-mt-4">{{template "base/alert" ctx.RootData}}</div>

View File

@@ -1,6 +1,5 @@
{{template "devtest/devtest-header"}}
<div class="page-content devtest ui container">
{{template "base/alert" .}}
<div>
<h1>link-action</h1>
<div>
@@ -17,29 +16,20 @@
<div>
<h1>form-fetch-action</h1>
<div>Use "window.fetch" to send a form request to backend</div>
<div>
<form method="get" action="fetch-action-test?k=1" class="form-fetch-action">
<div class="flex-relaxed-list fetch-action-demo-forms">
<form method="get" action="./fetch-action-test?k=1" class="form-fetch-action">
<button name="btn">submit get</button>
</form>
<form method="post" action="fetch-action-test?k=1" class="form-fetch-action">
<form method="post" action="./fetch-action-test?k=1" class="form-fetch-action">
<div><textarea name="text" rows="3"></textarea></div>
<div><label><input name="check" type="checkbox"> check</label></div>
<div><button name="btn">submit post</button></div>
</form>
<form method="post" action="no-such-uri" class="form-fetch-action">
<form method="post" action="./no-such-uri" class="form-fetch-action">
<div class="tw-py-8">bad action url</div>
<div><button name="btn">submit test</button></div>
</form>
</div>
</div>
</div>
<style>
.ui.message.flash-message {
text-align: left;
}
.form-fetch-action {
margin-bottom: 1em;
border: 1px red dashed; /* show the border for demo purpose */
}
</style>
{{template "devtest/devtest-footer"}}

View File

@@ -1,5 +1,5 @@
{{template "devtest/devtest-header"}}
<div>
<div class="ui container">
<h1>Toast</h1>
<div>
<button class="ui button toast-test-button" data-toast-level="info" data-toast-message="test info">Show Info Toast</button>