Skip to content

Commit

Permalink
improve comment, fix external render ctx check
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Nov 17, 2024
1 parent 08f0f69 commit fed44af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions modules/markup/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.

_, err = io.Copy(f, input)
if err != nil {
f.Close()
_ = f.Close()
return fmt.Errorf("%s write data to temp file when rendering %s failed: %w", p.Name(), p.Command, err)
}

Expand All @@ -113,10 +113,9 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
args = append(args, f.Name())
}

if ctx == nil || ctx.Ctx == nil {
if ctx == nil {
log.Warn("RenderContext not provided defaulting to empty ctx")
ctx = &markup.RenderContext{}
if ctx.Ctx == nil {
if !setting.IsProd || setting.IsInTesting {
panic("RenderContext did not provide context")
}
log.Warn("RenderContext did not provide context, defaulting to Shutdown context")
ctx.Ctx = graceful.GetManager().ShutdownContext()
Expand Down
3 changes: 2 additions & 1 deletion modules/markup/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func render(ctx *RenderContext, renderer Renderer, input io.Reader, output io.Wr
finalProcessor := ctx.RenderInternal.Init(output)
defer finalProcessor.Close()

// input -> pw1 -> pr1 -> renderer -> pw2 -> pr2 -> SanitizeReader -> finalProcessor -> output
// input -> (pw1=pr1) -> renderer -> (pw2=pr2) -> SanitizeReader -> finalProcessor -> output
// no sanitizer: input -> (pw1=pr1) -> renderer -> pw2(finalProcessor) -> output
pr1, pw1, close1 := pipes()
defer close1()

Expand Down

0 comments on commit fed44af

Please sign in to comment.