[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 6c1b12e: Add new function dom-remove-attribute
From: |
Lars Ingebrigtsen |
Subject: |
master 6c1b12e: Add new function dom-remove-attribute |
Date: |
Thu, 30 Apr 2020 00:05:33 -0400 (EDT) |
branch: master
commit 6c1b12e7d2ff38e313eae97bfd01746ecacdb02f
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Add new function dom-remove-attribute
* doc/lispref/text.texi (Document Object Model): Document it.
* lisp/dom.el (dom-remove-attribute): Add new function.
---
doc/lispref/text.texi | 3 +++
etc/NEWS | 3 +++
lisp/dom.el | 6 ++++++
test/lisp/dom-tests.el | 7 +++++++
4 files changed, 19 insertions(+)
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 58424a4..9317362 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -5161,6 +5161,9 @@ The following are functions for altering the
@acronym{DOM}.
@item dom-set-attribute @var{node} @var{attribute} @var{value}
Set the @var{attribute} of the node to @var{value}.
+@item dom-remove-attribute @var{node} @var{attribute}
+Remove @var{attribute} from @var{node}.
+
@item dom-append-child @var{node} @var{child}
Append @var{child} as the last child of @var{node}.
diff --git a/etc/NEWS b/etc/NEWS
index 025d5c1..c491172 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -358,6 +358,9 @@ optional argument specifying whether to follow symbolic
links.
** 'parse-time-string' can now parse ISO 8601 format strings,
such as "2020-01-15T16:12:21-08:00".
++++
+** The new function 'dom-remove-attribute' has been added.
+
---
** 'make-network-process', 'make-serial-process' :coding behavior change.
Previously, passing ":coding nil" to either of these functions would
diff --git a/lisp/dom.el b/lisp/dom.el
index 34df0e9..7ff9e07 100644
--- a/lisp/dom.el
+++ b/lisp/dom.el
@@ -67,6 +67,12 @@
(setcdr old value)
(setcar (cdr node) (nconc (cadr node) (list (cons attribute value)))))))
+(defun dom-remove-attribute (node attribute)
+ "Remove ATTRIBUTE from NODE."
+ (setq node (dom-ensure-node node))
+ (when-let ((old (assoc attribute (cadr node))))
+ (setcar (cdr node) (delq old (cadr node)))))
+
(defmacro dom-attr (node attr)
"Return the attribute ATTR from NODE.
A typical attribute is `href'."
diff --git a/test/lisp/dom-tests.el b/test/lisp/dom-tests.el
index d44851e..eb15500 100644
--- a/test/lisp/dom-tests.el
+++ b/test/lisp/dom-tests.el
@@ -84,6 +84,13 @@
(dom-set-attribute dom attr value)
(should (equal (dom-attr dom attr) value))))
+(ert-deftest dom-tests-remove-attribute ()
+ (let ((dom `(body ((foo . "bar") (zot . "foobar")))))
+ (should (equal (dom-attr dom 'foo) "bar"))
+ (dom-remove-attribute dom 'foo)
+ (should (equal (dom-attr dom 'foo) nil))
+ (should (equal dom '(body ((zot . "foobar")))))))
+
(ert-deftest dom-tests-attr ()
(let ((dom (dom-tests--tree)))
(should-not (dom-attr dom 'id))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 6c1b12e: Add new function dom-remove-attribute,
Lars Ingebrigtsen <=