Fix regression of renderer (#16091)

* Fix regression of renderer

* Fix render setting load twice bug
release/v1.15
Lunny Xiao 2021-06-07 06:50:07 +08:00 committed by GitHub
parent b3ef6a61e5
commit b6762e2306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 22 deletions

View File

@ -48,6 +48,7 @@ type RenderContext struct {
type Renderer interface { type Renderer interface {
Name() string // markup format name Name() string // markup format name
Extensions() []string Extensions() []string
NeedPostProcess() bool
Render(ctx *RenderContext, input io.Reader, output io.Writer) error 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 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 wg sync.WaitGroup
var err error var err error
pr, pw := io.Pipe() pr, pw := io.Pipe()
@ -103,6 +104,7 @@ func render(ctx *RenderContext, parser Renderer, input io.Reader, output io.Writ
_ = pw.Close() _ = pw.Close()
}() }()
if renderer.NeedPostProcess() {
pr2, pw2 := io.Pipe() pr2, pw2 := io.Pipe()
defer func() { defer func() {
_ = pr2.Close() _ = pr2.Close()
@ -124,8 +126,16 @@ func render(ctx *RenderContext, parser Renderer, input io.Reader, output io.Writ
_ = pw2.Close() _ = pw2.Close()
wg.Done() wg.Done()
}() }()
} else {
if err1 := parser.Render(ctx, input, pw); err1 != nil { 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 return err1
} }
_ = pw.Close() _ = pw.Close()

View File

@ -38,6 +38,8 @@ type MarkupSanitizerRule struct {
} }
func newMarkup() { func newMarkup() {
ExternalMarkupRenderers = make([]MarkupRenderer, 0, 10)
ExternalSanitizerRules = make([]MarkupSanitizerRule, 0, 10)
for _, sec := range Cfg.Section("markup").ChildSections() { for _, sec := range Cfg.Section("markup").ChildSections() {
name := strings.TrimPrefix(sec.Name(), "markup.") name := strings.TrimPrefix(sec.Name(), "markup.")
if name == "" { if name == "" {