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.
  • 151
  • 7

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,231
  • 2
  • 41
  • 66
  • Thanks. But unfortunately, it blocks external resources! … Seems like [this is the reason](https://blog.mozilla.org/security/2017/11/27/blocking-top-level-navigations-data-urls-firefox-59/), any _safe workaround_ here? – Anas R. Mar 18 '21 at 16:41
  • 1
    This should work even better with `pandoc --self-containted`, as that will cause pandoc to put all resources into the HTML. – tarleb Mar 22 '21 at 07:16
  • @tarleb Interesting! However, for my use case, "Argument list too long" :( – Anas R. Mar 26 '21 at 12:24
  • @AnasR. try with a temporary file? – tarleb Mar 27 '21 at 13:25
  • @tarleb Yes, it works fine, but not when using a massive css file. – Anas R. Mar 27 '21 at 17:40