Skip to content

Commit e59e037

Browse files
committed
feat: add stdin support for direct markdown → HTML conversion
Enables pipe mode: echo '**Bold**' | fizzy-md When no args and stdin is piped: - Read markdown from stdin - Convert to HTML - Output to stdout Wrapper mode (intercepting fizzy flags) still works as before.
1 parent 8593b52 commit e59e037

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ func main() {
138138
os.Exit(0)
139139
}
140140

141+
// Handle stdin mode: if no args and stdin is piped, convert and output
142+
if len(args) == 0 {
143+
stat, _ := os.Stdin.Stat()
144+
if (stat.Mode() & os.ModeCharDevice) == 0 {
145+
// Stdin is piped, not a terminal
146+
var buf bytes.Buffer
147+
if _, err := buf.ReadFrom(os.Stdin); err != nil {
148+
fmt.Fprintf(os.Stderr, "fizzy-md error: failed to read stdin: %v\n", err)
149+
os.Exit(1)
150+
}
151+
152+
html, err := convertMarkdownToHTML(buf.String())
153+
if err != nil {
154+
fmt.Fprintf(os.Stderr, "fizzy-md error: %v\n", err)
155+
os.Exit(1)
156+
}
157+
158+
fmt.Print(html)
159+
os.Exit(0)
160+
}
161+
}
162+
141163
// Process args for Markdown conversion
142164
processedArgs, err := processArgs(args)
143165
if err != nil {

0 commit comments

Comments
 (0)