|
|
@ -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,29 +104,38 @@ func render(ctx *RenderContext, parser Renderer, input io.Reader, output io.Writ |
|
|
|
_ = pw.Close() |
|
|
|
_ = pw.Close() |
|
|
|
}() |
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
pr2, pw2 := io.Pipe() |
|
|
|
if renderer.NeedPostProcess() { |
|
|
|
defer func() { |
|
|
|
pr2, pw2 := io.Pipe() |
|
|
|
_ = pr2.Close() |
|
|
|
defer func() { |
|
|
|
_ = pw2.Close() |
|
|
|
_ = pr2.Close() |
|
|
|
}() |
|
|
|
_ = pw2.Close() |
|
|
|
|
|
|
|
}() |
|
|
|
wg.Add(1) |
|
|
|
|
|
|
|
go func() { |
|
|
|
wg.Add(1) |
|
|
|
buf := SanitizeReader(pr2) |
|
|
|
go func() { |
|
|
|
_, err = io.Copy(output, buf) |
|
|
|
buf := SanitizeReader(pr2) |
|
|
|
_ = pr2.Close() |
|
|
|
_, err = io.Copy(output, buf) |
|
|
|
wg.Done() |
|
|
|
_ = pr2.Close() |
|
|
|
}() |
|
|
|
wg.Done() |
|
|
|
|
|
|
|
}() |
|
|
|
wg.Add(1) |
|
|
|
|
|
|
|
go func() { |
|
|
|
wg.Add(1) |
|
|
|
err = PostProcess(ctx, pr, pw2) |
|
|
|
go func() { |
|
|
|
_ = pr.Close() |
|
|
|
err = PostProcess(ctx, pr, pw2) |
|
|
|
_ = pw2.Close() |
|
|
|
_ = pr.Close() |
|
|
|
wg.Done() |
|
|
|
_ = pw2.Close() |
|
|
|
}() |
|
|
|
wg.Done() |
|
|
|
|
|
|
|
}() |
|
|
|
if err1 := parser.Render(ctx, input, pw); err1 != nil { |
|
|
|
} 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 |
|
|
|
return err1 |
|
|
|
} |
|
|
|
} |
|
|
|
_ = pw.Close() |
|
|
|
_ = pw.Close() |
|
|
|