2

I'd like to read Markdown files like man pages. I can do this:

pandoc README.md -t man --standalone > tmp_file && man ./tmp_file

However, I'd like to do this without creating a temporary file. I tried:

man <(pandoc README.md -t man –standalone)

But I got an error:

fgets: Undefined error: 0
Error reading man page /dev/fd/63
No manual entry for /dev/fd/63

Any ideas? I did look at this question, but that doesn't work on macOS's version of man, it seems.

I really don't care about using man, per se, but I'd like to be able to view prettily-formatted Markdown files in the terminal. pandoc can convert to groff, which I can then send to man to get the nice display. Is there a program that man uses under the hood that might work?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Ashton Wiersdorf
  • 1,865
  • 12
  • 33

2 Answers2

5

Try this pipe to groff:

pandoc -s -f markdown -t man README.md | groff -T utf8 -man | less

(Source)

L. Scott Johnson
  • 4,213
  • 2
  • 17
  • 28
1

I use this shell function:

mdv () { # This function display Markdown in the terminal from file or "-"
  pandoc -s -t man ${1:-"-"} | # Read into Pandoc from file or STDIN
  groff -T utf8 -man         | # format for Pager
  sed 1,4d | head -n -4      | # Chop off 4 leading/trailing (empty) lines
  ${PAGER:-$(DN=/dev/null;     # Use $PAGER, if available
             which less &>$DN && { echo "less -FRSEX"; } || # less w/ opts
               which more 2>$DN || echo cat                )} # Fallbacks
}

The basic idea is the same as in the accepted answer, I just have added a few bells and whistles around it, and wrapped it in a documented function

Alex Stragies
  • 552
  • 6
  • 12