[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Save in Lnum format with links footnoted [CODE INCLUDED]
- From: Boruch Baum <boruch_baum@xxxxxxx>
- Date: Thu, 21 Dec 2017 22:00:25 -0500
- X-ml-name: emacs-w3m
- X-mail-count: 12856
The attached code offers an ability to save a URL as rendered HTML, but
with the advantage of having links marked as footnotes.
Be forewarned that for this purpose, the code commits the heresy of
using `lynx', a competitor command line program of w3m, but which is
probably on your linux distribution by default.
I propose adding it to the project, but don't yet have a suggestion for
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
(defun w3m-lynx-dump (&optional url name)
"Save URL as a lynx-style dump (requires external program `lynx').
Save the URL as a rendered page in `Lnum' format, ie. with links
identified as footnotes. This is a feature natively offered by
the command line program `lynx', which is installed by default in
many common linux distributions."
; Based upon functions `w3m-pipe-source' and `w3m-save-buffer'
; TODO w3m-pipe-source: review handling of output redirection
(let* ((dummy (when (/= 0 (call-process "which" nil nil nil "lynx"))
(error "external program 'lynx' not found.")))
(url (or (if current-prefix-arg
(or (w3m-image) (w3m-anchor))
(or (w3m-anchor) (w3m-image)))
(y-or-n-p (format "Lynx -dump %s ? " w3m-current-url))
(name (or (and (stringp w3m-current-title)
(not (string-match "\\`[\C-@- ]*\\'" w3m-current-title))
(and (not (string-match "\\`[\C-@- ]*\\'" w3m-current-url))
(name (w3m-replace-in-string name "[\C-@- \"*/:<>?\|]+" "_"))
(name (read-file-name "Save to: "
name nil (concat name ".html.txt"))))
(list url name)))
(cond ((eq url 'none) nil)
((and (stringp url)
(w3m-message "Lynx -dump <%s> to \"| %s\"..." url name)
(let ((inhibit-message t))
((string-match "\\`about://source/" url)
((string-match "\\`about://header/" url)
(substring url (match-end 0))))
(t (concat "about://source/" url)))))
(call-process-region (point-min) (point-max) shell-file-name
nil nil nil shell-command-switch (concat "lynx -dump -stdin >" name))
(w3m-message "Completed: Lynx -dump"))))))