2024-07-19 David Ponce * svg.el (svg-print): Remove useless extra space from the XML representation of SVG node. Use the dom API to access parts of dom node. Improve doc string. diff --git a/lisp/svg.el b/lisp/svg.el index f2eb2ec66dd..1fed6c6b3b8 100644 --- a/lisp/svg.el +++ b/lisp/svg.el @@ -321,19 +321,19 @@ svg-possibly-update-image (put-text-property marker (1+ marker) 'display (svg-image svg)))))) (defun svg-print (dom) - "Convert DOM into a string containing the xml representation." + "Print the XML representation of DOM at point in current buffer." (if (stringp dom) (insert dom) - (insert (format "<%s" (car dom))) - (dolist (attr (nth 1 dom)) - ;; Ignore attributes that start with a colon. - (unless (= (aref (format "%s" (car attr)) 0) ?:) - (insert (format " %s=\"%s\"" (car attr) (cdr attr))))) - (insert ">") - (dolist (elem (nthcdr 2 dom)) - (insert " ") - (svg-print elem)) - (insert (format "" (car dom))))) + (let ((tag (dom-tag dom))) + (insert (format "<%s" tag)) + (dolist (attr (dom-attributes dom)) + ;; Ignore attributes that start with a colon. + (unless (= (aref (format "%s" (car attr)) 0) ?:) + (insert (format " %s=\"%s\"" (car attr) (cdr attr))))) + (insert ">") + (dolist (elem (dom-children dom)) + (svg-print elem)) + (insert (format "" tag))))) (defun svg-remove (svg id) "Remove the element identified by ID from SVG."