Commit 45727c4e authored by Lars Ingebrigtsen's avatar Lars Ingebrigtsen
Browse files

Add a new `dom-search' function

* doc/lispref/text.texi (Document Object Model): Document it.

* lisp/dom.el (dom-search): New function.
parent ed9402f8
......@@ -5162,6 +5162,11 @@ which is a regular expression.
Return all nodes in @var{dom} that have IDs that match @var{match},
which is a regular expression.
@item dom-search @var{dom} @var{predicate}
Return all nodes in @var{dom} where @var{predicate} returns a
non-@code{nil} value. @var{predicate} is called with the node to be
tested as its parameter.
@item dom-strings @var{dom}
Return all strings in @var{dom}.
......@@ -275,6 +275,12 @@ obsolete, and the new utility function 'xml-remove-comments' can be
used to remove comments before calling the libxml functions to parse
the data.
** A new DOM (the XML/HTML document structure returned by functions
such as 'libxml-parse-html-region') traversal function has been added:
'dom-search', which takes a DOM and a predicate and returns all nodes
that match.
** The Network Security Manager now allows more fine-grained control
of what checks to run via the 'network-security-protocol-checks'
......@@ -108,6 +108,18 @@ A name is a symbol like `td'."
(cons dom matches)
(defun dom-search (dom predicate)
"Return elements in DOM where PREDICATE is non-nil.
PREDICATE is called with the node as its only parameter."
(let ((matches (cl-loop for child in (dom-children dom)
for matches = (and (not (stringp child))
(dom-search child predicate))
when matches
append matches)))
(if (funcall predicate dom)
(cons dom matches)
(defun dom-strings (dom)
"Return elements in DOM that are strings."
(cl-loop for child in (dom-children dom)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment