You can use the ASCII exporter if you customize the option org-ascii-verbatim-format
to %s
.
Export to a buffer and copy the code there.
The following command sets the options temporarily for you as needed and then exports directly into the kill-ring:
(defun org+-copy-code ()
"Export code silently to kill-ring."
(interactive)
(require 'ox-ascii)
(cl-letf (((symbol-function 'org-element-normalize-string) #'identity))
(save-excursion
(kill-new
(org-export-as 'ascii
nil nil t
'(:ascii-verbatim-format "%s" :ascii-paragraph-spacing auto :ascii-headline-spacing nil :preserve-breaks t))
))))
You can try that command after evaluating the code above by selecting the region you want to copy and M-x org+-copy-code
RET.
If you like what you see you can copy the code to your init file and bind org+-copy-code
to some key, e.g., C-c c by the following line in your init file.
(with-eval-after-load 'org
(define-key org-mode-map (kbd "C-c c") #'org+-copy-code))
cd ~~
~` lines with the function. For me they all paste on one line. – lecodesportif Jun 10 '21 at 18:09