14

How can I do that either in a different buffer or even in the current buffer?

I'm trying to do Github README.md and other Github rendering of Markdown (for notes and such),

CodeSammich
  • 365
  • 3
  • 12
  • First glance this seems straightforward to do using `markdown-export` and `eww`, driven from a change notification hook and timer. But it seems like the interesting part would be determining what part of the `eww` buffer HTML corresponds to `point` in the markdown buffer (so the they could scroll "in sync"). – Greg Hendershott Nov 13 '15 at 21:06

2 Answers2

8

As of markdown-mode 2.1, this is functionality is provided in markdown-live-preview-mode (bound to C-c C-c l).

It uses eww for rendering the HTML. Screenshot:

live preview of markdown

Wilfred Hughes
  • 6,890
  • 2
  • 29
  • 59
5

Here's a pretty long but efficient solution.

  1. Install simple-httpd and M-x httpd-start.
  2. Install markdown from your system's package manager.
  3. Open your markdown buffer and run markdown-export. That produces a HTML file in the same directory.
  4. Open that HTML file.
  5. Install impatient-mode and M-x impatient-mode.
  6. Go back to your markdown file.

Finally, evaluate this code:

(defun markdown-export-continuous (&optional output-file)
  (interactive)
  (let ((input-file (buffer-file-name))
        (output-file (markdown-export-file-name ".html")))
    (when output-file
      (with-current-buffer (find-file-noselect output-file)
        (erase-buffer)
        (insert
         (shell-command-to-string
          (format "markdown %s" input-file)))
        (save-buffer)))))
(add-hook 'after-save-hook 'markdown-export-continuous t t)

Note that the add-hook statement needs to be local to Markdown, so run it in that buffer.

After all this, open your browser on http://localhost:8080/imp/ and it will refresh each time you C-x C-s.

abo-abo
  • 13,943
  • 1
  • 29
  • 43
  • I'm seeing the html file in localhost:8080/imp, but I have to click on it to see it, and C-x C-s doesn't seem to refresh. Or is that intended? – CodeSammich Nov 24 '15 at 15:48
  • In addition, instead of just markdown-export, is there a way to do Github-flavored markdown export instead? – CodeSammich Nov 24 '15 at 15:49