From DC Toedt: Copy Org Mode as Markdown

| emacs, org

DC Toedt is a lawyer and professor of practice who uses Emacs and Org Mode. He wanted a small Emacs Lisp function to convert Org Mode syntax to Markdown and copy it to the clipboard to make it easier to copy the materials he's writing for a course on contract drafting. This seems to be a common need, and here are several other approaches:

Anyway, DC shared how he used Claude to generate a simple function to do it, which is here under public domain:

(defun my/org-to-markdown-clipboard ()
  "Export org region (or buffer) to Markdown and copy to clipboard.
With no active region, exports the whole buffer."
  (interactive)
  (require 'ox-md)
  (let* ((text (if (use-region-p)
                   (buffer-substring-no-properties (region-beginning)
(region-end))
                 (buffer-substring-no-properties (point-min) (point-max))))
         (md (org-export-string-as text 'md t '(:with-toc nil
                                                :with-author nil
                                                :with-date nil
                                                :with-title nil))))
    (kill-new md)
    (message "Markdown copied (%d chars)" (length md))))
(with-eval-after-load 'org
  (define-key org-mode-map (kbd "C-c m") #'my/org-to-markdown-clipboard))
View Org source for this post