summaryrefslogtreecommitdiffhomepage
path: root/custom
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2024-03-29 05:32:43 +0000
committerjao <jao@gnu.org>2024-03-29 05:32:43 +0000
commit5a62a773a095b5ec2b40d51567f70b95c2cbab34 (patch)
tree80ccd539b386b53e1647797ec75d70eb67a48e84 /custom
parent76bd5b7251284a48d38e649fd00ebfa1e259a36d (diff)
downloadelibs-5a62a773a095b5ec2b40d51567f70b95c2cbab34.tar.gz
elibs-5a62a773a095b5ec2b40d51567f70b95c2cbab34.tar.bz2
jao-eww-to-org
Diffstat (limited to 'custom')
-rw-r--r--custom/jao-custom-eww.el44
1 files changed, 43 insertions, 1 deletions
diff --git a/custom/jao-custom-eww.el b/custom/jao-custom-eww.el
index 507069f..0b444a4 100644
--- a/custom/jao-custom-eww.el
+++ b/custom/jao-custom-eww.el
@@ -114,6 +114,48 @@
(use-package jao-eww-session
:custom ((jao-eww-session-file "~/.emacs.d/cache/eww-session.eld")))
+;;; eww to org
+(defun jao-eww-to-org (&optional dest)
+ (interactive)
+ (unless (org-region-active-p)
+ (let ((shr-width 80)) (eww-readable)))
+ (let* ((start (if (org-region-active-p) (region-beginning) (point-min)))
+ (end (if (org-region-active-p) (region-end) (point-max)))
+ (buff (or dest (generate-new-buffer "*eww-to-org*")))
+ (link (eww-current-url))
+ (title (or (plist-get eww-data :title) "")))
+ (with-current-buffer buff
+ (insert "#+title: " title "\n#+link: " link "\n\n")
+ (org-mode))
+ (save-excursion
+ (goto-char start)
+ (while (< (point) end)
+ (let* ((p (point))
+ (props (text-properties-at p))
+ (k (seq-find (lambda (x) (plist-get props x))
+ '(shr-url image-url outline-level face)))
+ (prop (and k (list k (plist-get props k))))
+ (next (if prop
+ (next-single-property-change p (car prop) nil end)
+ (next-property-change p nil end)))
+ (txt (buffer-substring (point) next))
+ (txt (replace-regexp-in-string "\\*" "ยท" txt)))
+ (with-current-buffer buff
+ (insert
+ (pcase prop
+ ((and (or `(shr-url ,url) `(image-url ,url))
+ (guard (string-match-p "^http" url)))
+ (let ((tt (replace-regexp-in-string "\n\\([^$]\\)" " \\1" txt)))
+ (org-link-make-string url tt)))
+ (`(outline-level ,n)
+ (concat (make-string (- (* 2 n) 1) ?*) " " txt "\n"))
+ ('(face italic) (format "/%s/ " (string-trim txt)))
+ ('(face bold) (format "*%s* " (string-trim txt)))
+ (t txt))))
+ (goto-char next))))
+ (pop-to-buffer buff)
+ (goto-char (point-min))))
+
;;; package
(use-package shr
:custom ((shr-width nil)
@@ -157,7 +199,7 @@
("T" . jao-mastodon-toot-url)
("u" . jao-eww-reopen)
("U" . jao-eww-reopen-new)
- ("w" . org-eww-copy-for-org-mode)
+ ("w" . jao-eww-to-org)
("q" . jao-eww-close)
("x" . jao-rss-subscribe)
("y" . jao-eww-copy-link)