self closing (void) elementlerin düzgün yazdırılması

This commit is contained in:
riton
2025-03-31 23:52:03 +03:00
parent ba8fe59c0f
commit 2e16ed1e2a

View File

@@ -19,6 +19,10 @@
((:html :head :body :div :ol :ul :li :p :title :pre :h1 :h2 :h3 :h4 :h5 :h6) t)
((:b :i :code) nil)))
(defun tag-sonu-tagsız? (tag)
(case tag
(:img t)))
(defun yeni-satır-yaz (stream)
(write-char #\Newline stream)
(setf *satır-başı* t))
@@ -38,18 +42,21 @@
(loop :for i :from 0 :below *indent*
:do (write-char #\Space stream)))
(if (null (props node))
(format stream "<~a>" (tag node))
(format stream "<~a" (tag node))
(loop :initially (format stream "<~a" (tag node))
:for (k v) :on (props node) :by #'cddr
:do (format stream " ~a=\"~a\"" k v)
:finally (write-char #\> stream)))
:do (format stream " ~a=\"~a\"" k v)))
(if (tag-sonu-tagsız? (tag node))
(write-string " />" stream)
(write-char #\> stream))
(setf *satır-başı* nil)
(when (tag-başı-yeni-satır? (tag node))
(yeni-satır-yaz stream)))
(defmethod node->html ((node node) &optional (stream *standard-output*))
(if (null (children node))
(kaçışlı-içerik-yazdır (value node) stream)
(when (not (null (value node)))
(kaçışlı-içerik-yazdır (value node) stream))
(let ((*indent* (+ *indent* *indent-increment*)))
(loop :for child :in (children node)
:do (node->html child stream)))))
@@ -58,7 +65,8 @@
(unless (not *satır-başı*)
(loop :for i :from 0 :below *indent*
:do (write-char #\Space stream)))
(format stream "</~a>" (tag node))
(unless (tag-sonu-tagsız? (tag node))
(format stream "</~a>" (tag node)))
(when (tag-sonu-yeni-satır? (tag node))
(yeni-satır-yaz stream)))