Skip to content

Instantly share code, notes, and snippets.

@holocronweaver
Last active November 8, 2025 21:13
Show Gist options
  • Select an option

  • Save holocronweaver/4f18acf4659efc8c4750d328038b8092 to your computer and use it in GitHub Desktop.

Select an option

Save holocronweaver/4f18acf4659efc8c4750d328038b8092 to your computer and use it in GitHub Desktop.
Yank/Paste Markdown in Emacs Org-Mode Syntax
(defun hw-yank-markdown-as-org ()
"Yank markdown from clipboard/kill-ring and insert as org-mode syntax.
Converts via pandoc while preserving long lines for visual-line-mode."
(interactive)
(let* ((markdown (current-kill 0))
(org-text (with-temp-buffer
(insert markdown)
(shell-command-on-region
(point-min)
(point-max)
"pandoc -f markdown -t org --wrap=preserve"
t t "*pandoc-error*")
;; Remove CUSTOM_ID property drawers
(goto-char (point-min))
(while (re-search-forward
":PROPERTIES:\n:CUSTOM_ID: .*\n:END:\n"
nil t)
(replace-match ""))
(buffer-string))))
(insert org-text)))
@holocronweaver
Copy link
Author

This is especially useful when copying markdown output from LLMs.

May be worth adding a more generalized version to https://github.com/tecosaur/org-pandoc-import if it is ever supported again.

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