aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-09-27 00:32:37 +0200
committerLars Ingebrigtsen2019-09-27 00:33:45 +0200
commit45727c4e6de7f6f6f61a4ae3589d5dd271ea8803 (patch)
treea853f0eadc96373bef56e7d870cf8ceb0df275cc /lisp
parented9402f81907f5810d70fc421b456791d624ba1a (diff)
downloademacs-45727c4e6de7f6f6f61a4ae3589d5dd271ea8803.tar.gz
emacs-45727c4e6de7f6f6f61a4ae3589d5dd271ea8803.zip
Add a new `dom-search' function
* doc/lispref/text.texi (Document Object Model): Document it. * lisp/dom.el (dom-search): New function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dom.el12
1 files changed, 12 insertions, 0 deletions
diff --git a/lisp/dom.el b/lisp/dom.el
index d8c44339985..f01da5221b8 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -108,6 +108,18 @@ A name is a symbol like `td'."
108 (cons dom matches) 108 (cons dom matches)
109 matches))) 109 matches)))
110 110
111(defun dom-search (dom predicate)
112 "Return elements in DOM where PREDICATE is non-nil.
113PREDICATE is called with the node as its only parameter."
114 (let ((matches (cl-loop for child in (dom-children dom)
115 for matches = (and (not (stringp child))
116 (dom-search child predicate))
117 when matches
118 append matches)))
119 (if (funcall predicate dom)
120 (cons dom matches)
121 matches)))
122
111(defun dom-strings (dom) 123(defun dom-strings (dom)
112 "Return elements in DOM that are strings." 124 "Return elements in DOM that are strings."
113 (cl-loop for child in (dom-children dom) 125 (cl-loop for child in (dom-children dom)