Created
March 23, 2011 19:34
-
-
Save danlei/883777 to your computer and use it in GitHub Desktop.
Show src/alt comparison table of a site's images.
This file contains 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
(require 'xml) | |
(require 'html-lite) | |
(defun xml-get-nodes (node node-name) | |
(let ((nodes (list))) | |
(labels ((match (node) (eq (xml-node-name node) node-name)) | |
(rec (node) | |
(when (listp node) | |
(if (match node) | |
(push node nodes) | |
(mapc 'rec (xml-node-children node)))))) | |
(rec node)) | |
nodes)) | |
(defun img/alt-table (root) | |
(let ((images (xml-get-nodes root 'img))) | |
(html-table | |
(html-th "src") (html-th "alt") (html-th "thumb") | |
(mapcar (lambda (img) | |
(let ((src (xml-get-attribute img 'src)) | |
(alt (xml-get-attribute img 'alt))) | |
(html-tr (html-td src) | |
(html-td alt) | |
(html-td (html-img :src src | |
:width "100"))))) | |
images)))) | |
(defun insert-img/alt-table (url) | |
(interactive "sURL: ") | |
(lexical-let ((buffer (current-buffer))) | |
(url-retrieve | |
url | |
(lambda (status) | |
(let ((table (img/alt-table (car (xml-parse-region (point-min) | |
(point-max)))))) | |
(with-current-buffer buffer (html-lite-write-tree table)) | |
(kill-buffer)))))) | |
(defun browse-img/alt-table (url) | |
(interactive "sURL: ") | |
(url-retrieve | |
url | |
(lambda (status) | |
(html-lite-browse-tree | |
(with-html-lite-header "img/alt" | |
(img/alt-table (car (xml-parse-region (point-min) | |
(point-max)))))) | |
(kill-buffer)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment