I'm using spacemacs and I'm looking for a plugin to preview markdown in real time. I have found a plugin markdown-preview-eww, but it requires a gem and I prefer not to install ruby.
The markdown-mode just exports md to html, and it can't preview markdown in real time. Also, I don't like to generate any file without my agreement.
So, is there any plugin to preview markdown in emacs? Or does everyone use org-mode in emacs rather than markdown?
Tip: You can also right-click on the editor Tab and select Open Preview (Ctrl+Shift+V) or use the Command Palette (Ctrl+Shift+P) to run the Markdown: Open Preview to the Side command (Ctrl+K V).
To previewUse the shortcut Cmd + Shift + P then select MarkdownPreview to show the follow commands (you will be prompted to select which parser you prefer): Markdown Preview: Preview in Browser.
Configuring Markdown on macOS with Homebrew Then, in Emacs, type M-x customize-mode RET markdown-mode and set “Markdown Command” to the path of the executable you just installed: /usr/local/bin/markdown , /usr/local/bin/pandoc , or /usr/local/bin/multimarkdown .
Show the rendered HTML markdown to the right of the current editor using ctrl-shift-m.
There are a few solutions listed here: http://wikemacs.org/wiki/Markdown#Live_preview_as_you_type.
The pure-Emacs (nearly) solution and easy one, requiring no extra library from Python or Nodejs, is impatient-mode.
It's designed to work with html but the doc gives a trick to make it work with markdown. It also works like a charm but requires one configuration step:
M-x package-install RET impatient-mode RET
, given you have configured package.el to use the melpa repository.M-x httpd-start
.M-x impatient-mode
.To enable markdown conversion, we follow wikemacs:
Define this elisp function somewhere, like in your init file:
(defun markdown-html (buffer) (princ (with-current-buffer buffer (format "<!DOCTYPE html><html><title>Impatient Markdown</title><xmp theme=\"united\" style=\"display:none;\"> %s </xmp><script src=\"http://strapdownjs.com/v/0.2/strapdown.js\"></script></html>" (buffer-substring-no-properties (point-min) (point-max)))) (current-buffer)))
Tell impatient mode to use it: M-x imp-set-user-filter RET markdown-html RET
.
edit: thanks to the comments, flymd-fyit doesn't work in Firefox 68 and beyond.
Install it with package.el (M-x package-install RET flymd RET
), then simply call M-x flymd-flyit. It opens the browser with the rendered markdown.
We can enable/disable auto-reloading and github markdown flavour.
edit: newer solutions, requiring an external package.
https://github.com/shime/emacs-livedown requires the livedown
npm package. Also, this emacs package is not in MELPA, you have to clone it locally. Otherwise, it is a good and lightweight solution.
Another solution is vmd-mode, which works with the vmd
node package. This is not the most heavy-weight solution: vmd is based on Electron (!).
Another one is grip-mode, that relies on a Python package:
pip install --user grip M-x package-install grip-mode
Then run M-x grip-mode
in the markdown buffer. It opens a new tab in your browser.
Unfortunately, at the time of writing, it is limited by Github's rate limit. Indeed, to render content as precisely as Github, it calls its API. It doesn't render content locally. As such we are limited to 60 calls an hour, which is very few. See this issue: https://github.com/joeyespo/grip/issues/35
I like this simpler approach that doesn't require another package nor a browser:
Execute M-x markdown-other-window
on current buffer and display the result in other window.
Change to M-x html-mode
and hide HTML tags M-x sgml-tags-invisible
.
Then to update the html buffer run again markdown-other-window
C-c C-c m on the markdown buffer.
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