Created
December 29, 2021 09:28
-
-
Save afroisalreadyinu/e17497f66d6b7f42ce1beb9cb4f1aaff to your computer and use it in GitHub Desktop.
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 fetch-page-title (&rest args) | |
(let* ((page-tree (libxml-parse-html-region (point-min) (point-max))) | |
(titles (dom-by-tag page-tree 'title)) | |
(url (cadr args)) | |
(target-buffer (nth 1 (cdr args))) | |
(target-point (nth 2 (cdr args)))) | |
(message "URL: %s" url) | |
(if (null titles) (error "Title not found on page") | |
(save-excursion | |
(switch-to-buffer target-buffer) | |
(goto-char target-point) | |
(insert (format "[[%s][%s]]" url (caddar titles))))))) | |
(defun insert-with-title (target-url) (interactive "sURL: ") | |
(let ((argument (list target-url (current-buffer) (point)))) | |
(url-retrieve target-url #'fetch-page-title argument 't))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment