Skip to content

Read markdown from standard input when the filename is - - #58

Merged
mapitman merged 1 commit into
mainfrom
feature/read-markdown-from-stdin
Aug 21, 2026
Merged

Read markdown from standard input when the filename is -#58
mapitman merged 1 commit into
mainfrom
feature/read-markdown-from-stdin

Conversation

@mapitman

Copy link
Copy Markdown
Owner

What

mdview - now reads the markdown from standard input instead of from a file.

Why

Piping markdown in avoids writing it to disk first. That matters when the content is decrypted or generated on the fly, where a temporary plaintext file is undesirable:

age -d -i ~/.config/age/key.txt notes.md.age | mdview -

Previously the only option was to decrypt to a temp file, view it, then delete it, which leaves plaintext on disk for the lifetime of the command.

How

When the first positional argument is -, main() reads with io.ReadAll(os.Stdin). Otherwise the existing os.ReadFile path is unchanged.

Relative image paths resolve against the working directory in the stdin case, since there is no input file to anchor them to. The rest of the pipeline (image inlining, Goldmark parsing, title extraction, mermaid embedding, templating) is untouched.

Verification

Checked manually, as the repo has no test suite:

  • stdin and file input produce byte-identical HTML for the same content
  • H1 title extraction works through the pipe
  • empty stdin renders an empty document rather than crashing
  • -b/-bare works via stdin
  • missing-file errors are unchanged
  • end to end: age -d ... | mdview - renders the decrypted content

Also updated

mdview.1.md, README.md, and CLAUDE.md to document the new form.

No CHANGELOG entry: entries there are per-release with dates and PR numbers, so this belongs to the next release rather than the branch.

Two pre-existing issues were left alone, both in code this branch does not touch: a go vet redundant-newline warning in the Snap hint, and some gofmt comment-alignment drift.

Piping markdown in avoids writing it to disk first, which matters when the
content is decrypted or generated on the fly. Relative image paths resolve
against the working directory, since there is no input file to anchor them to.
@mapitman
mapitman merged commit 194bae3 into main Aug 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant