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.
I am as far as putting a user defined filter into .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
So, the main questions are:
less as well, instead of losing it with html2txt
*.html to file disk and let less handle that html at its own digression (seeing the html-extension and acting on it?)The first step to convert Markdown to HTML is to open your Markdown document in Atom. Then toggle the Markdown preview by pressing the CTRL+SHIFT+M keyboard shortcut. Another way to toggle the Markdown preview is from Packages —> Markdown Preview —> Toggle Preview.
Markdown applications use something called a Markdown processor (also commonly referred to as a “parser” or an “implementation”) to take the Markdown-formatted text and output it to HTML format. At that point, your document can be viewed in a web browser or combined with a style sheet and printed.
If you haven't seen any markdown document yet, just head over to GitHub and enter any open-source project. The README file almost certainly will be written using Markdown. Basically, you use some 'code' before your text and your text will be formatted for display accordingly.
Take a look at Pandoc. It can convert files from markdown format to groff man pages which you can then view in man.
Your .lessfilter script would be:
case "$1" in
*.md)
pandoc -s -f markdown -t man "$1" | man -l -
;;
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
;;
And, yes, the lessfilter script must write to stdout.
Dogbane's answer is great, but if you use groff -T utf8 -man instead of man -l to do the formatting, then the bold, italic, etc. come through. As seen here: https://stackoverflow.com/a/20197316/2674930.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With