;;; dom.el --- XML/HTML (etc.) DOM manipulation and searching functions
-;; Copyright (C) 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; Keywords: xml, html
;;; Code:
(require 'cl-lib)
+(eval-when-compile (require 'subr-x))
(defsubst dom-tag (node)
"Return the NODE tag."
(cons dom matches)
matches)))
+(defun dom-strings (dom)
+ "Return elements in DOM that are strings."
+ (cl-loop for child in (dom-children dom)
+ if (stringp child)
+ collect child
+ else
+ append (dom-strings child)))
+
(defun dom-by-class (dom match)
"Return elements in DOM that have a class name that matches regexp MATCH."
(dom-elements dom 'class match))
(setq result (dom-parent elem node))))
result)))
+(defun dom-previous-sibling (dom node)
+ (when-let (parent (dom-parent dom node))
+ (let ((siblings (dom-children parent))
+ (previous nil))
+ (while siblings
+ (when (eq (cadr siblings) node)
+ (setq previous (car siblings)))
+ (pop siblings))
+ previous)))
+
(defun dom-node (tag &optional attributes &rest children)
"Return a DOM node with TAG and ATTRIBUTES."
(if children