Created
October 3, 2017 18:46
-
-
Save TeMPOraL/92e10724b095df670453ffb9ba658b6e to your computer and use it in GitHub Desktop.
Some examples of using Plump.
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
(defun parse-tree/fix-anchors (tree base-url) | |
"Fix anchor URLs in the `TREE' to work correctly with the <base> tag." | |
(plump:traverse tree | |
(lambda (node) | |
(when (starts-with-subseq "#" (plump:attribute node "href")) | |
(setf (plump:attribute node "href") (concatenate 'string base-url (plump:attribute node "href"))))) | |
:test (lambda (node) | |
(and (plump:element-p node) | |
(string-equal (plump:tag-name node) "a"))))) | |
(defun parse-tree/extract-urls (tree) | |
(let ((urls)) | |
(plump:traverse tree | |
(lambda (node) | |
(let ((url (or (plump:attribute node "href") | |
(plump:attribute node "src")))) | |
(when url | |
(pushnew url urls :test #'string=)))) | |
:test (lambda (node) | |
(and (plump:element-p node) | |
(member (plump:tag-name node) | |
'("a" "img") | |
:test #'string-equal)))) | |
urls)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment