chatgpt-shell
chatgpt-shell copied to clipboard
Is there way to remove Markdown?
Is there any way to automatically remove Markdown markups?
Could try asking not to reply with markdown in chatgpt-shell-system-prompt though in early tries it wasn't super effective (maybe better these days). Otherwise post processing via chatgpt-shell-after-command-functions hook.
pandoc is good at converting markdown to org-mode or plaintext.
Check https://github.com/xenodium/chatgpt-shell/issues/140 @agzam has a pandoc copy solution.
Yup, yup.... here it is:
(defun yank-as-org ()
"Convert region of markdown text to org while yanking."
(interactive)
(let* ((_ (unless (executable-find "pandoc")
(user-error "pandoc not found")))
(beg (if evil-mode
(marker-position evil-visual-beginning)
(region-beginning)))
(end (if evil-mode
(marker-position evil-visual-end)
(region-end)))
(region-content (buffer-substring-no-properties beg end))
(_ (print region-content))
(converted-content
(with-temp-buffer
(insert region-content)
(shell-command-on-region
(point-min)
(point-max)
"pandoc --wrap=none -f markdown -t org" nil t)
(buffer-string))))
(kill-new converted-content)
(message "yanked Markdown as Org")))
(defun yank-as-markdown ()
"Convert region of Org-mode to markdown while yanking."
(interactive)
(let* ((_ (unless (executable-find "pandoc")
(user-error "pandoc not found")))
(beg (if evil-mode
(marker-position evil-visual-beginning)
(region-beginning)))
(end (if evil-mode
(marker-position evil-visual-end)
(region-end)))
(region-content (buffer-substring-no-properties beg end))
(_ (print region-content))
(converted-content
(with-temp-buffer
(insert region-content)
(shell-command-on-region
(point-min)
(point-max)
"pandoc --wrap=none -f org -t markdown_strict" nil t)
(buffer-string))))
(kill-new converted-content)
(message "yanked Org as Markdown")))
(defun maybe-yank-and-convert-a (orig-fun beg end &optional type register yank-handler)
"Advice function to convert marked region to org before yanking."
(let ((yank-fn (cond
((derived-mode-p 'markdown-mode)
#'yank-as-org)
((derived-mode-p 'org-mode)
#'yank-as-markdown))))
(if (and current-prefix-arg (use-region-p)
yank-fn)
(funcall yank-fn)
(funcall
orig-fun
beg end type register
yank-handler))))
;; advise 'kill-ring-save or whatever if you're not using Evil
(advice-add 'evil-yank :around #'maybe-yank-and-convert-a)
I know there's some repetition there, it can use some DRYing, I just wrote it, saw that it works and pretty much forgot about it. Maybe one day I'll clean up and make it into a separate package. It basically works this way - if you copy normally, it would just do the normal copy, but if you do copy with a prefix (C-u) - in markdown mode it will copy it as org, and in the org-mode - it'll copy it as markdown.