Documentation
¶
Overview ¶
color.go provides ANSI color output helpers. It exposes Success / Warning / Error / Info helpers and automatically falls back to plain text when color is unavailable.
progress.go provides progress output for build steps. It supports step counting, status markers, and colored output.
Index ¶
- Constants
- func Blue(text string) string
- func Bold(text string) string
- func CopyFile(src, dst string) error
- func Cyan(text string) string
- func DetectImageMIME(path string, data []byte) string
- func Dim(text string) string
- func DownloadImage(urlStr string, destDir string) (string, error)
- func EnsureDir(path string) error
- func Error(format string, args ...interface{})
- func EscapeAttr(s string) string
- func EscapeHTML(s string) string
- func EscapeXML(s string) string
- func FileExists(path string) bool
- func GetImageMIME(path string) string
- func Green(text string) string
- func Header(title string)
- func ImageToBase64(path string) (string, error)
- func Info(format string, args ...interface{})
- func IsColorEnabled() bool
- func IsRemoteURL(path string) bool
- func ProcessImages(htmlContent string, baseDir string, embedAsBase64 bool, logger ...*slog.Logger) (string, error)
- func ReadFile(path string) ([]byte, error)
- func Red(text string) string
- func RelPath(basePath, targetPath string) string
- func SetColorEnabled(enabled bool)
- func Success(format string, args ...interface{})
- func Warning(format string, args ...interface{})
- func WriteFile(path string, data []byte) error
- func Yellow(text string) string
- type ProgressTracker
- func (p *ProgressTracker) Done()
- func (p *ProgressTracker) DoneWithDetail(detail string)
- func (p *ProgressTracker) Fail()
- func (p *ProgressTracker) Finish()
- func (p *ProgressTracker) FinishWithError(err error)
- func (p *ProgressTracker) Skip(reason string)
- func (p *ProgressTracker) Start(description string)
Constants ¶
const MaxImageSize = 50 * 1024 * 1024
MaxImageSize is the maximum allowed size for a downloaded image (50 MB).
const MermaidCDNURL = "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"
MermaidCDNURL is the CDN URL for the Mermaid diagram library. Centralized here so every part of the codebase uses the same version.
Variables ¶
This section is empty.
Functions ¶
func DetectImageMIME ¶
DetectImageMIME determines the MIME type from content when possible. This is more reliable than extension-only detection for remote assets whose URLs do not include a file suffix, such as Shields badges.
func DownloadImage ¶
DownloadImage downloads an image from a URL and returns the local path.
func Error ¶
func Error(format string, args ...interface{})
Error prints a red error message with an error prefix.
func EscapeHTML ¶
EscapeHTML escapes HTML special characters including single quotes. This is the canonical HTML escaping function used throughout mdpress.
func EscapeXML ¶
EscapeXML escapes XML special characters. Similar to EscapeHTML but uses ' for single quotes per the XML specification.
func FileExists ¶
FileExists reports whether a file or directory exists.
func GetImageMIME ¶
GetImageMIME returns a MIME type from the file extension.
func ImageToBase64 ¶
ImageToBase64 converts an image file to a base64 data URI.
func Info ¶
func Info(format string, args ...interface{})
Info prints a blue informational message with an info prefix.
func IsColorEnabled ¶
func IsColorEnabled() bool
IsColorEnabled reports whether color output is enabled.
func IsRemoteURL ¶
IsRemoteURL reports whether a path is an HTTP(S) URL.
func ProcessImages ¶
func ProcessImages(htmlContent string, baseDir string, embedAsBase64 bool, logger ...*slog.Logger) (string, error)
ProcessImages resolves image paths in HTML and optionally embeds them as base64. An optional logger can be provided to record warnings when image processing fails. Pass nil to silently skip failures (legacy behavior).
func SetColorEnabled ¶
func SetColorEnabled(enabled bool)
SetColorEnabled overrides color output for tests or forced modes.
func Success ¶
func Success(format string, args ...interface{})
Success prints a green success message with a checkmark prefix.
func Warning ¶
func Warning(format string, args ...interface{})
Warning prints a yellow warning message with a warning prefix.
Types ¶
type ProgressTracker ¶
type ProgressTracker struct {
// contains filtered or unexported fields
}
ProgressTracker tracks build progress.
func NewProgressTracker ¶
func NewProgressTracker(total int) *ProgressTracker
NewProgressTracker creates a new progress tracker.
func (*ProgressTracker) Done ¶
func (p *ProgressTracker) Done()
Done marks the current step as completed.
func (*ProgressTracker) DoneWithDetail ¶
func (p *ProgressTracker) DoneWithDetail(detail string)
DoneWithDetail marks the current step as completed with extra detail.
func (*ProgressTracker) Fail ¶
func (p *ProgressTracker) Fail()
Fail marks the current step as failed.
func (*ProgressTracker) Finish ¶
func (p *ProgressTracker) Finish()
Finish prints the build-complete summary.
func (*ProgressTracker) FinishWithError ¶
func (p *ProgressTracker) FinishWithError(err error)
FinishWithError prints the build-failed summary.
func (*ProgressTracker) Skip ¶
func (p *ProgressTracker) Skip(reason string)
Skip marks the current step as skipped.
func (*ProgressTracker) Start ¶
func (p *ProgressTracker) Start(description string)
Start marks the beginning of a new step and prints the pending state.