1
1
; ;; org-protocol-capture-html.el --- Capture HTML with org-protocol
2
2
3
+ ; ; URL: https://github.com/alphapapa/org-protocol-capture-html
4
+ ; ; Version: 0.1-pre
5
+ ; ; Package-Requires: ((emacs "24.4"))
6
+
3
7
; ;; Commentary:
4
8
5
9
; ; This package captures Web pages into Org-mode using Pandoc to
31
35
; ;;; Require
32
36
33
37
(require 'org-protocol )
34
- (require 'cl )
38
+ (require 'cl-lib )
35
39
(require 'subr-x )
36
40
(require 's )
37
41
@@ -46,8 +50,9 @@ You may want to increase this if you use a sub-heading in your capture template.
46
50
47
51
(defconst org-protocol-capture-html-pandoc-no-wrap-option nil
48
52
; ; Set this so it won't be unbound
49
- " Option to pass to Pandoc to disable wrapping. Pandoc >= 1.16
50
- deprecates `--no-wrap' in favor of `--wrap=none' ." )
53
+ " Option to pass to Pandoc to disable wrapping.
54
+ Pandoc >= 1.16 deprecates `--no-wrap' in favor of
55
+ `--wrap=none' ." )
51
56
52
57
(defun org-protocol-capture-html--define-pandoc-wrap-const ()
53
58
" Set `org-protocol-capture-html-pandoc-no-wrap-option' ."
@@ -81,7 +86,7 @@ deprecates `--no-wrap' in favor of `--wrap=none'.")
81
86
; ;;; Direct-to-Pandoc
82
87
83
88
(defun org-protocol-capture-html--with-pandoc (data )
84
- " Process an org-protocol://capture-html:// URL.
89
+ " Process an org-protocol://capture-html:// URL using DATA .
85
90
86
91
This function is basically a copy of `org-protocol-do-capture' , but
87
92
it passes the captured content (not the URL or title) through
@@ -136,6 +141,8 @@ Pandoc, converting HTML to Org-mode."
136
141
137
142
; ;;; eww-readable
138
143
144
+ (defvar url-http-end-of-headers )
145
+
139
146
(eval-when-compile
140
147
; ; eww-readable only works on Emacs >=25.1, but I think it's better
141
148
; ; to check for the actual symbols. I think using
@@ -165,7 +172,7 @@ Pandoc, converting HTML to Org-mode."
165
172
(unless (= 0 (call-process-region (point-min ) (point-max )
166
173
" pandoc" t t nil " -f" " html" " -t" " org"
167
174
org-protocol-capture-html-pandoc-no-wrap-option))
168
- (error " Pandoc failed. " ))
175
+ (error " Pandoc failed " ))
169
176
(save-excursion
170
177
; ; Remove DOS CR/LF line endings
171
178
(goto-char (point-min ))
@@ -237,7 +244,7 @@ Returns list (HTML . TITLE)."
237
244
(dom (with-temp-buffer
238
245
(insert html)
239
246
(libxml-parse-html-region (point-min ) (point-max ))))
240
- (title (caddr (car (dom-by-tag dom 'title )))))
247
+ (title (cl- caddr (car (dom-by-tag dom 'title )))))
241
248
(eww-score-readability dom)
242
249
(cons (with-temp-buffer
243
250
(shr-dom-print (eww-highest-readability dom))
@@ -252,20 +259,22 @@ Returns list (HTML . TITLE)."
252
259
; ; them to underlines instead of spaces, but this fixes it.
253
260
(replace-regexp-in-string (rx " " ) " " s t t ))
254
261
255
- (defun org-protocol-capture-html--do-capture ()
256
- " Call `org-capture' and demote page headings in capture buffer."
257
- (raise-frame )
258
- (funcall 'org-capture nil template)
259
-
260
- ; ; Demote page headings in capture buffer to below the
261
- ; ; top-level Org heading
262
- (save-excursion
263
- (goto-char (point-min ))
264
- (re-search-forward (rx bol " *" (1+ space)) nil t ) ; Skip 1st heading
265
- (while (re-search-forward (rx bol " *" (1+ space)) nil t )
266
- (dotimes (n org-protocol-capture-html-demote-times)
267
- (org-demote-subtree )))))
262
+ (with-no-warnings
263
+ ; ; Ignore warning about the dynamically scoped `template' variable.
264
+ (defun org-protocol-capture-html--do-capture ()
265
+ " Call `org-capture' and demote page headings in capture buffer."
266
+ (raise-frame )
267
+ (funcall 'org-capture nil template)
268
+
269
+ ; ; Demote page headings in capture buffer to below the
270
+ ; ; top-level Org heading
271
+ (save-excursion
272
+ (goto-char (point-min ))
273
+ (re-search-forward (rx bol " *" (1+ space)) nil t ) ; Skip 1st heading
274
+ (while (re-search-forward (rx bol " *" (1+ space)) nil t )
275
+ (dotimes (n org-protocol-capture-html-demote-times)
276
+ (org-demote-subtree ))))))
268
277
269
278
(provide 'org-protocol-capture-html )
270
279
271
- ; ;; org-protocol-capture-html ends here
280
+ ; ;; org-protocol-capture-html.el ends here
0 commit comments