dom: fix void-element, provide tagname method

This commit is contained in:
Helmut Merz 2025-02-12 19:16:34 +01:00
parent 95542a0f5a
commit ec880c3695
2 changed files with 11 additions and 6 deletions

View file

@ -46,7 +46,9 @@
"Link to example.com")) "Link to example.com"))
(format nil (format nil
"<a href=\"https://example.com\" title=\"Demo\" ~ "<a href=\"https://example.com\" title=\"Demo\" ~
class=\"demo-link plain\">Link to example.com</a>"))) class=\"demo-link plain\">Link to example.com</a>"))
(== (dom:render (dom:br nil))
(format nil "<br>")))
(deftest test-jwt () (deftest test-jwt ()
(let ((secret (crypt:create-secret)) (let ((secret (crypt:create-secret))

View file

@ -31,7 +31,7 @@
(make-instance 'xml-element :tag tag :attrs attrs :body body)) (make-instance 'xml-element :tag tag :attrs attrs :body body))
(defmethod put ((el xml-element)) (defmethod put ((el xml-element))
(let ((tag (string-downcase (tag el))) (let ((tag (tagname el))
(body (body el))) (body (body el)))
(start tag (attrs el) :close (not body)) (start tag (attrs el) :close (not body))
(when body (when body
@ -39,12 +39,15 @@
(put c)) (put c))
(end tag)))) (end tag))))
(defgeneric tagname (el)
(:method ((el xml-element)) (string-downcase (tag el))))
;;;; element = HTML element - no self-closing of empty elements ;;;; element = HTML element - no self-closing of empty elements
(defclass element (xml-element) ()) (defclass element (xml-element) ())
(defmethod put ((el element)) (defmethod put ((el element))
(let ((tag (string-downcase (tag el)))) (let ((tag (tagname el)))
(start tag (attrs el)) (start tag (attrs el))
(dolist (c (body el)) (dolist (c (body el))
(put c)) (put c))
@ -60,11 +63,11 @@
(defclass void-element (xml-element) ()) (defclass void-element (xml-element) ())
(defun void-element (tag attrs) (defun void-element (tag &optional attrs body)
(make-instance 'void-element :tag tag :attrs attrs)) (make-instance 'void-element :tag tag :attrs attrs))
(defmethod put ((el void-element)) (defmethod put ((el void-element))
(start (tag el) (attrs el))) (start (tagname el) (attrs el)))
;;;; automatically define standard HTML elements ;;;; automatically define standard HTML elements
@ -79,7 +82,7 @@
(make-elements (a dd div dl dt label))) (make-elements (a dd div dl dt label)))
(eval-when (:compile-toplevel :load-toplevel :execute) (eval-when (:compile-toplevel :load-toplevel :execute)
(make-elements (br input) :void-element)) (make-elements (br input) void-element))
;;;; elements with specific functionality ;;;; elements with specific functionality