Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metacritical/c9dd3a50d05ee6cd5915dd14d9f8bf2d to your computer and use it in GitHub Desktop.
Save metacritical/c9dd3a50d05ee6cd5915dd14d9f8bf2d to your computer and use it in GitHub Desktop.
Doom Emacs: Markdown live preview with xwidget-webkit

Doom Emacs: Markdown live preview with xwidget-webkit

I saw that there's a markdown-live-preview-mode and the var markdown-live-preview-window-function which was set to the function markdown-live-preview-window-eww. That function looks like this:

(defun markdown-live-preview-window-eww (file)
  "Preview FILE with eww.
To be used with `markdown-live-preview-window-function'."
  (eww-open-file file)
  (get-buffer "*eww*"))

I hacked around to get something working with xwidget-webkit:

(defun +markdown-live-preview-window-xwidget-webkit (file)
  "Preview FILE with xwidget-webkit.
To be used with `markdown-live-preview-window-function'."
  (let ((uri (format "file://%s" file)))
      (xwidget-webkit-browse-url uri)
      xwidget-webkit-last-session-buffer))

Then I set a quick popup rule:

(set-popup-rule! "^\\*xwidget" :side 'right :size .50 :ttl 0 :quit nil)

And enabled the new hacky function:

(setq markdown-live-preview-window-function
      'markdown-live-preview-window-xwidget-webkit)

Now I get live preview in xwidget-webkit. This is just a quick hack to see if it's doable. I haven't tested it for more than five minutes, and only with one markdown file open.

Still, it's nicer than eww. 😄

Is there a better way to do this? I saw grip-mode but that seems to use an online service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment