aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup/renderer.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-03-06 16:41:54 +0800
committerGitHub <noreply@github.com>2022-03-06 16:41:54 +0800
commitb24e8d38af21fc1857b6aa66351627e3b1761608 (patch)
tree4b021069697a852808f9a1e9ee7e89ab7b2a42a5 /modules/markup/renderer.go
parent3e28fa72cedc559e0dc3396d0676a5d1dab12624 (diff)
downloadgitea-b24e8d38af21fc1857b6aa66351627e3b1761608.tar.gz
gitea-b24e8d38af21fc1857b6aa66351627e3b1761608.zip
Support ignore all santize for external renderer (#18984)
* Support ignore all santize for external renderer * Update docs * Apply suggestions from code review Co-authored-by: silverwind <me@silverwind.io> * Fix doc Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/markup/renderer.go')
-rw-r--r--modules/markup/renderer.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/modules/markup/renderer.go b/modules/markup/renderer.go
index 0ac0daaea9..cf8b9bace7 100644
--- a/modules/markup/renderer.go
+++ b/modules/markup/renderer.go
@@ -81,6 +81,7 @@ type Renderer interface {
Extensions() []string
NeedPostProcess() bool
SanitizerRules() []setting.MarkupSanitizerRule
+ SanitizerDisabled() bool
Render(ctx *RenderContext, input io.Reader, output io.Writer) error
}
@@ -127,6 +128,12 @@ func RenderString(ctx *RenderContext, content string) (string, error) {
return buf.String(), nil
}
+type nopCloser struct {
+ io.Writer
+}
+
+func (nopCloser) Close() error { return nil }
+
func render(ctx *RenderContext, renderer Renderer, input io.Reader, output io.Writer) error {
var wg sync.WaitGroup
var err error
@@ -136,18 +143,25 @@ func render(ctx *RenderContext, renderer Renderer, input io.Reader, output io.Wr
_ = pw.Close()
}()
- pr2, pw2 := io.Pipe()
- defer func() {
- _ = pr2.Close()
- _ = pw2.Close()
- }()
-
- wg.Add(1)
- go func() {
- err = SanitizeReader(pr2, renderer.Name(), output)
- _ = pr2.Close()
- wg.Done()
- }()
+ var pr2 io.ReadCloser
+ var pw2 io.WriteCloser
+
+ if !renderer.SanitizerDisabled() {
+ pr2, pw2 = io.Pipe()
+ defer func() {
+ _ = pr2.Close()
+ _ = pw2.Close()
+ }()
+
+ wg.Add(1)
+ go func() {
+ err = SanitizeReader(pr2, renderer.Name(), output)
+ _ = pr2.Close()
+ wg.Done()
+ }()
+ } else {
+ pw2 = nopCloser{output}
+ }
wg.Add(1)
go func() {