diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-06-07 06:50:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-06 18:50:07 -0400 |
commit | b6762e23060972f0ad35aeab48850064687ea400 (patch) | |
tree | ea0a65b706c23c0888e3931610bf2d3e79b9938a | |
parent | b3ef6a61e5fc3f9d64e3a9f61fb0027cbb48ba73 (diff) | |
download | gitea-b6762e23060972f0ad35aeab48850064687ea400.tar.gz gitea-b6762e23060972f0ad35aeab48850064687ea400.zip |
Fix regression of renderer (#16091)
* Fix regression of renderer
* Fix render setting load twice bug
-rw-r--r-- | modules/markup/renderer.go | 58 | ||||
-rw-r--r-- | modules/setting/markup.go | 2 |
2 files changed, 36 insertions, 24 deletions
diff --git a/modules/markup/renderer.go b/modules/markup/renderer.go index 7cc81574ba..5d35bd5a67 100644 --- a/modules/markup/renderer.go +++ b/modules/markup/renderer.go @@ -48,6 +48,7 @@ type RenderContext struct { type Renderer interface { Name() string // markup format name Extensions() []string + NeedPostProcess() bool Render(ctx *RenderContext, input io.Reader, output io.Writer) error } @@ -94,7 +95,7 @@ func RenderString(ctx *RenderContext, content string) (string, error) { return buf.String(), nil } -func render(ctx *RenderContext, parser Renderer, input io.Reader, output io.Writer) error { +func render(ctx *RenderContext, renderer Renderer, input io.Reader, output io.Writer) error { var wg sync.WaitGroup var err error pr, pw := io.Pipe() @@ -103,29 +104,38 @@ func render(ctx *RenderContext, parser Renderer, input io.Reader, output io.Writ _ = pw.Close() }() - pr2, pw2 := io.Pipe() - defer func() { - _ = pr2.Close() - _ = pw2.Close() - }() - - wg.Add(1) - go func() { - buf := SanitizeReader(pr2) - _, err = io.Copy(output, buf) - _ = pr2.Close() - wg.Done() - }() - - wg.Add(1) - go func() { - err = PostProcess(ctx, pr, pw2) - _ = pr.Close() - _ = pw2.Close() - wg.Done() - }() - - if err1 := parser.Render(ctx, input, pw); err1 != nil { + if renderer.NeedPostProcess() { + pr2, pw2 := io.Pipe() + defer func() { + _ = pr2.Close() + _ = pw2.Close() + }() + + wg.Add(1) + go func() { + buf := SanitizeReader(pr2) + _, err = io.Copy(output, buf) + _ = pr2.Close() + wg.Done() + }() + + wg.Add(1) + go func() { + err = PostProcess(ctx, pr, pw2) + _ = pr.Close() + _ = pw2.Close() + wg.Done() + }() + } else { + wg.Add(1) + go func() { + buf := SanitizeReader(pr) + _, err = io.Copy(output, buf) + _ = pr.Close() + wg.Done() + }() + } + if err1 := renderer.Render(ctx, input, pw); err1 != nil { return err1 } _ = pw.Close() diff --git a/modules/setting/markup.go b/modules/setting/markup.go index f0849a863a..43df4ce442 100644 --- a/modules/setting/markup.go +++ b/modules/setting/markup.go @@ -38,6 +38,8 @@ type MarkupSanitizerRule struct { } func newMarkup() { + ExternalMarkupRenderers = make([]MarkupRenderer, 0, 10) + ExternalSanitizerRules = make([]MarkupSanitizerRule, 0, 10) for _, sec := range Cfg.Section("markup").ChildSections() { name := strings.TrimPrefix(sec.Name(), "markup.") if name == "" { |