emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 7520f89: Further eww dom.el cleanups


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 7520f89: Further eww dom.el cleanups
Date: Wed, 26 Nov 2014 21:08:58 +0000

branch: master
commit 7520f8919ae4030b5b2c3fbcc4141c85bb65aad1
Author: Lars Magne Ingebrigtsen <address@hidden>
Date:   Wed Nov 26 22:08:44 2014 +0100

    Further eww dom.el cleanups
    
    * net/eww.el (eww-tag-title): Use `dom-text'.
    
    * 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.
---
 lisp/ChangeLog  |    9 +++++++++
 lisp/dom.el     |   12 ++++++++++--
 lisp/net/eww.el |   27 +++++++++++----------------
 3 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1698eb7..4884d5c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
+2014-11-26  Lars Magne Ingebrigtsen  <address@hidden>
+
+       * 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  <address@hidden>
 
        * textmodes/sgml-mode.el (sgml-validate-command): Pass -utf8 to tidy.
diff --git a/lisp/dom.el b/lisp/dom.el
index 3157e0b..04d6c21 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -47,6 +47,12 @@
       (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))
@@ -93,7 +99,7 @@ A name is a symbol like `td'."
                                             (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)))
 
@@ -113,7 +119,9 @@ A name is a symbol like `td'."
   "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)))
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index a1460a8..10298b1 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -453,14 +453,10 @@ See the `eww-search-prefix' variable for the search 
engine used."
     (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)
@@ -589,14 +585,13 @@ the like."
 (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))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]