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 | |
| 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.
| -rw-r--r-- | doc/lispref/text.texi | 5 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/dom.el | 12 |
3 files changed, 23 insertions, 0 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index d7b04d2934f..8d78a9b24ff 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -5162,6 +5162,11 @@ which is a regular expression. | |||
| 5162 | Return all nodes in @var{dom} that have IDs that match @var{match}, | 5162 | Return all nodes in @var{dom} that have IDs that match @var{match}, |
| 5163 | which is a regular expression. | 5163 | which is a regular expression. |
| 5164 | 5164 | ||
| 5165 | @item dom-search @var{dom} @var{predicate} | ||
| 5166 | Return all nodes in @var{dom} where @var{predicate} returns a | ||
| 5167 | non-@code{nil} value. @var{predicate} is called with the node to be | ||
| 5168 | tested as its parameter. | ||
| 5169 | |||
| 5165 | @item dom-strings @var{dom} | 5170 | @item dom-strings @var{dom} |
| 5166 | Return all strings in @var{dom}. | 5171 | Return all strings in @var{dom}. |
| 5167 | 5172 | ||
| @@ -276,6 +276,12 @@ used to remove comments before calling the libxml functions to parse | |||
| 276 | the data. | 276 | the data. |
| 277 | 277 | ||
| 278 | +++ | 278 | +++ |
| 279 | ** A new DOM (the XML/HTML document structure returned by functions | ||
| 280 | such as 'libxml-parse-html-region') traversal function has been added: | ||
| 281 | 'dom-search', which takes a DOM and a predicate and returns all nodes | ||
| 282 | that match. | ||
| 283 | |||
| 284 | +++ | ||
| 279 | ** The Network Security Manager now allows more fine-grained control | 285 | ** The Network Security Manager now allows more fine-grained control |
| 280 | of what checks to run via the 'network-security-protocol-checks' | 286 | of what checks to run via the 'network-security-protocol-checks' |
| 281 | variable. | 287 | variable. |
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) |