Created
November 13, 2024 18:42
-
-
Save RyanFleck/988b04d300588b51882d53eecc0492fb to your computer and use it in GitHub Desktop.
Copy a region of ORG-mode code to Markdown formatted and un-filled text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun r/copy-org-to-markdown (point mark) | |
"Copy the region from POINT to MARK as Markdown." | |
(interactive "r") | |
;; Load a trimmed copy of the highlighted region to memory | |
(let ((astring (s-trim (buffer-substring-no-properties point mark)))) | |
(with-temp-buffer | |
;; Copy the highlighted region and run 'export to markdown' org command | |
(insert astring) | |
(setq org-export-with-toc nil) | |
(setq org-export-with-broken-links t) | |
(org-md-export-as-markdown) | |
;; Correctly 'unfill' the copied region | |
(markdown-mode) | |
(set-fill-column 10000) | |
(fill-region (point-min) (point-max)) | |
;; (unfill-region (point-min) (point-max)) | |
;; Copy to clipboard and remove window | |
(clipboard-kill-region (point-min) (point-max)) | |
(message "Copied markdown to clipboard!") | |
(delete-window)) | |
;; Done work - jump to end point. | |
(deactivate-mark) | |
(goto-char mark))) | |
;; On Mac: Command-Shift-C copies org to markdown. | |
(define-key org-mode-map (kbd "s-C") 'r/copy-org-to-markdown) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment