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),

  • 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
4

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.

| improve this answer | |
  • 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
7

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.