diff options
| author | Lars Ingebrigtsen | 2019-09-27 00:32:37 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-27 00:33:45 +0200 |
| commit | 45727c4e6de7f6f6f61a4ae3589d5dd271ea8803 (patch) | |
| tree | a853f0eadc96373bef56e7d870cf8ceb0df275cc /lisp | |
| parent | ed9402f81907f5810d70fc421b456791d624ba1a (diff) | |
| download | emacs-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.el | 12 |
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. | ||
| 113 | PREDICATE 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) |