+2014-11-26 Lars Magne Ingebrigtsen <larsi@gnus.org>
+
+ * dom.el (dom-by-tag): Use `equal' for comparisons so that tags
+ can be strings.
+ (dom-elements): Protect against non-text nodes.
+ (dom-non-text-children): New function.
+
+ * net/eww.el (eww-tag-title): Use `dom-text'.
+
2014-11-26 Sam Steingold <sds@gnu.org>
* textmodes/sgml-mode.el (sgml-validate-command): Pass -utf8 to tidy.
(cddr (car node))
(cddr node)))
+(defun dom-non-text-children (node)
+ "Return all non-text-node children of NODE."
+ (cl-loop for child in (dom-children node)
+ unless (stringp child)
+ collect child))
+
(defun dom-set-attributes (node attributes)
"Set the attributes of NODE to ATTRIBUTES."
(setq node (dom-ensure-node node))
(dom-by-tag child tag))
when matches
append matches)))
- (if (eq (dom-tag dom) tag)
+ (if (equal (dom-tag dom) tag)
(cons dom matches)
matches)))
"Find elements matching MATCH (a regexp) in ATTRIBUTE.
ATTRIBUTE would typically be `class', `id' or the like."
(let ((matches (cl-loop for child in (dom-children dom)
- for matches = (dom-elements child attribute match)
+ for matches = (and (not (stringp child))
+ (dom-elements child attribute
+ match))
when matches
append matches))
(attr (dom-attr dom attribute)))
(setq header-line-format nil)))
(defun eww-tag-title (dom)
- (let ((title ""))
- (dolist (sub (dom-children dom))
- (when (stringp sub)
- (setq title (concat title sub))))
- (plist-put eww-data :title
- (replace-regexp-in-string
- "^ \\| $" ""
- (replace-regexp-in-string "[ \t\r\n]+" " " title))))
+ (plist-put eww-data :title
+ (replace-regexp-in-string
+ "^ \\| $" ""
+ (replace-regexp-in-string "[ \t\r\n]+" " " (dom-text dom))))
(eww-update-header-line-format))
(defun eww-tag-body (dom)
(defun eww-highest-readability (node)
(let ((result node)
highest)
- (dolist (elem (dom-children node))
- (when (and (not (stringp elem))
- (> (or (dom-attr
- (setq highest (eww-highest-readability elem))
- :eww-readability-score)
- most-negative-fixnum)
- (or (dom-attr result :eww-readability-score)
- most-negative-fixnum)))
+ (dolist (elem (dom-non-text-children node))
+ (when (> (or (dom-attr
+ (setq highest (eww-highest-readability elem))
+ :eww-readability-score)
+ most-negative-fixnum)
+ (or (dom-attr result :eww-readability-score)
+ most-negative-fixnum))
(setq result highest)))
result))