reddit / emacs

Rewriting http(s) links as specific org link types

CommanderThunderous · 2022-03-01 15:47
I want to be able to do both of the following: 1. Insert a HTTP-based link into an org mode file and have that link automatically reformatted to an appropriate org-link. ;; Assume I have a google-doc link defined. (org-insert-link nil "https://docs.google.com/document/d/12345/edit" "My Document") => [[google-doc:12345][My Document]] 1. Run a command and rewrite all HTTP-based links in the current buffer to use appropriate org-link patterns if one is set. A link to my file: [[https://docs.google.com/document/d/12345/edit][My Document]], another link: https://docs.google.com/document/d/67890/edit (rewrite-links-in-buffer) A link to my file: [[google-doc:12345][My Document]], another link: [[google-doc:67890][67890]] Does anything like this exist?
akirakom · 2022-03-01 17:54
You could rewrite org links using a regexp search. There is org-link-any-re variable, so you can use re-search-forward. I have written such scripts many times.
shryzr · 2022-03-05 02:37
org-web-tools and org-download should help with the first part.