Skip to content

Instantly share code, notes, and snippets.

@jhacksworth
Created September 3, 2020 00:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jhacksworth/1aaccec3bf645f835f010eceee68bd92 to your computer and use it in GitHub Desktop.
Save jhacksworth/1aaccec3bf645f835f010eceee68bd92 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.

@jhacksworth
Copy link
Author

Screenshot:

markdown-xwidget-webkit

@cfclrk
Copy link

cfclrk commented May 13, 2022

Absolutely awesome. This should be the default behavior if Emacs has xwidget support.

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