我如何在不制作临时文件的情况下像手册页一样查看Markdown文件?

问题描述 投票:0回答:2

我想阅读Markdown文件,例如man页面。我可以这样做:

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

但是,我想不创建临时文件就这样做。我尝试过:

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

但是我有一个错误:

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

有什么想法吗?我did看了this question,但这似乎不适用于macOS的man版本。

我真的不在乎使用man本身,但是我希望能够在终端中查看格式简单的Markdown文件。 pandoc可以转换为groff,然后我可以将其发送到man以得到漂亮的显示。 man是否有可能在后台使用的程序?

bash macos markdown pandoc manpage
2个回答
4
投票

尝试使用此管道进行灌浆:

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

([Source


0
投票

我使用此shell函数:

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
}

基本思想与接受的答案相同,我只是在它周围加上了几分花哨,并将其包装在有文档记录的函数中

© www.soinside.com 2019 - 2024. All rights reserved.