diff options
| -rw-r--r-- | doc/lispref/text.texi | 3 | ||||
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/dom.el | 6 | ||||
| -rw-r--r-- | test/lisp/dom-tests.el | 7 |
4 files changed, 19 insertions, 0 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index 58424a4231b..9317362a70a 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -5161,6 +5161,9 @@ The following are functions for altering the @acronym{DOM}. | |||
| 5161 | @item dom-set-attribute @var{node} @var{attribute} @var{value} | 5161 | @item dom-set-attribute @var{node} @var{attribute} @var{value} |
| 5162 | Set the @var{attribute} of the node to @var{value}. | 5162 | Set the @var{attribute} of the node to @var{value}. |
| 5163 | 5163 | ||
| 5164 | @item dom-remove-attribute @var{node} @var{attribute} | ||
| 5165 | Remove @var{attribute} from @var{node}. | ||
| 5166 | |||
| 5164 | @item dom-append-child @var{node} @var{child} | 5167 | @item dom-append-child @var{node} @var{child} |
| 5165 | Append @var{child} as the last child of @var{node}. | 5168 | Append @var{child} as the last child of @var{node}. |
| 5166 | 5169 | ||
| @@ -358,6 +358,9 @@ optional argument specifying whether to follow symbolic links. | |||
| 358 | ** 'parse-time-string' can now parse ISO 8601 format strings, | 358 | ** 'parse-time-string' can now parse ISO 8601 format strings, |
| 359 | such as "2020-01-15T16:12:21-08:00". | 359 | such as "2020-01-15T16:12:21-08:00". |
| 360 | 360 | ||
| 361 | +++ | ||
| 362 | ** The new function 'dom-remove-attribute' has been added. | ||
| 363 | |||
| 361 | --- | 364 | --- |
| 362 | ** 'make-network-process', 'make-serial-process' :coding behavior change. | 365 | ** 'make-network-process', 'make-serial-process' :coding behavior change. |
| 363 | Previously, passing ":coding nil" to either of these functions would | 366 | Previously, passing ":coding nil" to either of these functions would |
diff --git a/lisp/dom.el b/lisp/dom.el index 34df0e9af4c..7ff9e07b729 100644 --- a/lisp/dom.el +++ b/lisp/dom.el | |||
| @@ -67,6 +67,12 @@ | |||
| 67 | (setcdr old value) | 67 | (setcdr old value) |
| 68 | (setcar (cdr node) (nconc (cadr node) (list (cons attribute value))))))) | 68 | (setcar (cdr node) (nconc (cadr node) (list (cons attribute value))))))) |
| 69 | 69 | ||
| 70 | (defun dom-remove-attribute (node attribute) | ||
| 71 | "Remove ATTRIBUTE from NODE." | ||
| 72 | (setq node (dom-ensure-node node)) | ||
| 73 | (when-let ((old (assoc attribute (cadr node)))) | ||
| 74 | (setcar (cdr node) (delq old (cadr node))))) | ||
| 75 | |||
| 70 | (defmacro dom-attr (node attr) | 76 | (defmacro dom-attr (node attr) |
| 71 | "Return the attribute ATTR from NODE. | 77 | "Return the attribute ATTR from NODE. |
| 72 | A typical attribute is `href'." | 78 | A typical attribute is `href'." |
diff --git a/test/lisp/dom-tests.el b/test/lisp/dom-tests.el index d44851eb13b..eb15500d84c 100644 --- a/test/lisp/dom-tests.el +++ b/test/lisp/dom-tests.el | |||
| @@ -84,6 +84,13 @@ | |||
| 84 | (dom-set-attribute dom attr value) | 84 | (dom-set-attribute dom attr value) |
| 85 | (should (equal (dom-attr dom attr) value)))) | 85 | (should (equal (dom-attr dom attr) value)))) |
| 86 | 86 | ||
| 87 | (ert-deftest dom-tests-remove-attribute () | ||
| 88 | (let ((dom `(body ((foo . "bar") (zot . "foobar"))))) | ||
| 89 | (should (equal (dom-attr dom 'foo) "bar")) | ||
| 90 | (dom-remove-attribute dom 'foo) | ||
| 91 | (should (equal (dom-attr dom 'foo) nil)) | ||
| 92 | (should (equal dom '(body ((zot . "foobar"))))))) | ||
| 93 | |||
| 87 | (ert-deftest dom-tests-attr () | 94 | (ert-deftest dom-tests-attr () |
| 88 | (let ((dom (dom-tests--tree))) | 95 | (let ((dom (dom-tests--tree))) |
| 89 | (should-not (dom-attr dom 'id)) | 96 | (should-not (dom-attr dom 'id)) |