2

Out of GUI-based software like ReText or Formiko, and using just a command-line tool like pandoc, is it possible to open markdown files (MIME type association) as an HTML file in a web browser, without any browser-addon too?

Notice that the original markdown file may include links to images or any kind of resources. Therefore, this process should be on-fly (stdout?), without saving the output HTML file to somewhere else like /tmp/ directory.

And how can such a command be included in a .desktop file?

Anas R.
  • 161

1 Answers1

4

Based on this:

pandoc README.md | firefox "data:text/html;base64,$(base64 -w 0 <&0)"
# or
python3 -m markdown README.md | firefox "data:text/html;base64,$(base64 -w 0 <&0)"

So, you can create a function:

mdopen(){ pandoc "$1" | firefox "data:text/html;base64,$(base64 -w 0 <&0)"; }

Usage:

mdopen README.md

Alternative: Use grip. It opens a local webserver to serve markdown-files.

$ pip install grip
$ grip
[...]
* Running on http://localhost:6419/ (Press CTRL+C to quit)

When you point your browser to that location, you can see your markdown files.

pLumo
  • 22,565