mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-14 14:17:37 +08:00
fix: route result output through Config.Output, not os.Stdout
mark.Run and ProcessFile were writing directly to os.Stdout via fmt.Println, which is a surprising side-effect for library callers. Add Config.Output io.Writer for callers to provide their own sink. When nil the helper falls back to io.Discard, so library embedders that do not set Output receive no implicit stdout writes. The CLI layer sets Output: os.Stdout to preserve existing behaviour. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
06c3afef25
commit
4e3b90c03c
19
mark.go
19
mark.go
@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@ -67,6 +68,20 @@ type Config struct {
|
||||
Features []string
|
||||
ImageAlign string
|
||||
IncludePath string
|
||||
|
||||
// Output is the writer used for result output (e.g. published page URLs,
|
||||
// compiled HTML). If nil, output is discarded; the CLI sets this to
|
||||
// os.Stdout.
|
||||
Output io.Writer
|
||||
}
|
||||
|
||||
// output returns the configured writer, falling back to io.Discard so that
|
||||
// library callers that do not set Output receive no implicit stdout writes.
|
||||
func (c Config) output() io.Writer {
|
||||
if c.Output != nil {
|
||||
return c.Output
|
||||
}
|
||||
return io.Discard
|
||||
}
|
||||
|
||||
// Run processes all files matching Config.Files and publishes them to Confluence.
|
||||
@ -101,7 +116,7 @@ func Run(config Config) error {
|
||||
|
||||
if target != nil {
|
||||
log.Infof(nil, "page successfully updated: %s", config.BaseURL+target.Links.Full)
|
||||
fmt.Println(config.BaseURL + target.Links.Full)
|
||||
fmt.Fprintln(config.output(), config.BaseURL+target.Links.Full)
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +258,7 @@ func ProcessFile(file string, api *confluence.API, config Config) (*confluence.P
|
||||
ImageAlign: imageAlign,
|
||||
}
|
||||
html, _ := markmd.CompileMarkdown(markdown, std, file, cfg)
|
||||
fmt.Println(html)
|
||||
fmt.Fprintln(config.output(), html)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@ -83,6 +83,8 @@ func RunMark(ctx context.Context, cmd *cli.Command) error {
|
||||
Features: cmd.StringSlice("features"),
|
||||
ImageAlign: cmd.String("image-align"),
|
||||
IncludePath: cmd.String("include-path"),
|
||||
|
||||
Output: os.Stdout,
|
||||
}
|
||||
|
||||
return mark.Run(config)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user