0

I would like to convert Markdown files so these can be viewed via less...

However, I want the formatting (bold, italic, etc.) to be preserved and displayed accordingly... Unfortunately I cannot find the specifications.


My preferred approach would have been to use Pandoc to convert the md-files into a file type that less can properly display...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
trekkerly
  • 31
  • 5
  • 1
    Styled/coloured text in a terminal window? Some keywords may be "[ANSI color escape sequence](https://en.wikipedia.org/wiki/ANSI_escape_code)" and "[OSC](https://en.wikipedia.org/wiki/ANSI_escape_code#OSC_(Operating_System_Command)_sequences)" (Operating System Command) (very search unfriendly). – Peter Mortensen Jun 26 '22 at 10:25
  • In general, formats like bold and italics don't exist on traditional text-based terminals. You usually have a palette of colours, and some limited effects like invert and blink, signalled by special control sequences. Less itself doesn't interpret these, but it can pass them through to the underlying terminal with the `-R` option. – IMSoP Jun 26 '22 at 10:27
  • What format exactly do you want to have it converted to? – Peter Mortensen Jun 26 '22 at 10:30
  • Somewhat related: *[List of ANSI color escape sequences](https://stackoverflow.com/questions/4842424/)*. [An answer](https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences/33206814#33206814) includes *"Font Effects ... Italic ... Not widely supported. Sometimes treated as inverse. ... Bold or increased intensity"*. And *[How do I print colored text to the terminal?](https://stackoverflow.com/questions/287871/)*. – Peter Mortensen Jun 26 '22 at 11:11
  • 1
    @IMSoP Less by default interprets backspaces (as if it is a hardcopy terminal). Character-backspace-underline has the effect of underlining the character. Character-backspace-character has the effect of bolding the character. This is how you see these effects in man pages. – n. m. could be an AI Jun 26 '22 at 11:11

1 Answers1

1

Files of any format supported by pandoc can be read like Unix man pages:

pandoc --standalone --to=man INPUT_FILE | man -l -

This uses less by default, unless you have the PAGER variable set to some other value.

A good way to use it is to create a shell function:

mandoc () { pandoc --standalone --to=man "$@" | man -l - }

Now you can read files using Markdown, docx, LaTeX, etc. as if they were manpages.

mandoc README.md
mandoc term-project.tex
mandoc thesis.docx
# and so on

As you can see, the command causes pandoc to convert its input to a format called man, which is really groff man (see https://man.cx/groff_man(7)).

tarleb
  • 19,863
  • 4
  • 51
  • 80