问题描述
我希望 less
以某种格式显示 *.md
降价文件-就像我知道 less
可以用于手册页一样,等等.我正在运行Ubuntu 12.04.
I would like to have less
display *.md
markdown files with some formatting -- like I know less
can, for manpages, etc. I am running Ubuntu 12.04.
我尽可能将用户定义的过滤器放入 .lessfilter
:
#!/bin/sh
case "$1" in
*.md)
fn=/tmp/$1.$$.html
markdown "$1" | html2txt > $fn ### LOSES FORMATTING
cat $fn ### TO STDOUT???
;;
*)
# We don't handle this format
exit 1
esac
# No further processing by lesspipe necessary
exit 0
因此,主要问题是:
- 如何将一些基本格式设置信息也传递给
less
,而不是因为html2txt
而丢失 - 仅将新内容打印到 stdout 是否正确?还是我可以将
*.html
写入文件磁盘,并让less
自行处理该html(查看html扩展名并对其进行操作?)
- How can I pass some basic formatting information to
less
as well, instead of losing it withhtml2txt
- Is it correct to just print the new content to stdout? Or could I just write the
*.html
to file disk and letless
handle that html at its own digression (seeing the html-extension and acting on it?)
推荐答案
看看 Pandoc .它可以将文件从markdown格式转换为groff手册页,然后可以在 man
中查看.
Take a look at Pandoc. It can convert files from markdown format to groff man pages which you can then view in man
.
您的 .lessfilter
脚本为:
case "$1" in
*.md)
pandoc -s -f markdown -t man "$1" | man -l -
;;
或者,使用 markdown
命令将其转换为html,然后使用 lynx
浏览器进行查看,但这对我来说并不是很好.
Alternatively, convert it to html using the markdown
command and then use the lynx
browser to view it, but this didn't work too well for me.
case "$1" in
*.md)
markdown "$1" | lynx -stdin
;;
是的, lessfilter
脚本必须写入标准输出.
And, yes, the lessfilter
script must write to stdout.
这篇关于如何配置“较少"以显示格式化的降价文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!