markdown-mode
markdown-mode copied to clipboard
Fetch HTML title for URLs
Expected Behavior
It would be helpful, if I could hit C-c C-c
(or any other shortcut) and Emacs would fetch the HTML of the given URL and provide me the title as text. Then I can edit it and jump to the tooltip prompt.
Software Versions
- Markdown Mode: 2.5-dev
- Emacs: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20) of 2020-05-17, modified by Debian
- OS: Debian
I suppose you can write such function as below. I suppose such function should not be implemented in markdown-mode. Because it is too difficult to implement correctly for sites where uses authentications, cookies or other technologies etc.
(defun my/insert-url-title (url)
(interactive
(list (read-string "URL: ")))
(let ((title (with-current-buffer (url-retrieve-synchronously url)
(goto-char (point-min))
(when (re-search-forward "<\\s-*title\\s-*>\\([^<]+\\)" nil t)
(match-string-no-properties 1)))))
(if (not title)
(error "Could not find title in %s" url)
(insert (decode-coding-string title 'utf-8)))))