varsayılan olarak standard outputa yaz

This commit is contained in:
riton
2025-03-23 19:47:39 +03:00
parent 2b6760e54b
commit 99571117b7

View File

@@ -4,15 +4,17 @@
(defparameter *indent-increment* 2) (defparameter *indent-increment* 2)
(defparameter *yeni-satır* t) (defparameter *yeni-satır* t)
(defgeneric node->html (node stream) (defgeneric node->html (node &optional stream)
(:method (node &optional (stream *standard-output*))
(write-string node stream))
(:documentation "NODE u STREAM e yazar")) (:documentation "NODE u STREAM e yazar"))
(defun tag-yeni-satır? (tag) (defun tag-yeni-satır? (tag)
(case tag (case tag
((:html :head :body) t) ((:html :head :body) t)
((:title :p) nil))) ((:title :p :b :i :code) nil)))
(defmethod node->html :before (node stream) (defmethod node->html :before ((node node) &optional (stream *standard-output*))
(loop :for i :from 0 :below *indent* (loop :for i :from 0 :below *indent*
:do (write-char #\Space stream)) :do (write-char #\Space stream))
(setf *yeni-satır* nil) (setf *yeni-satır* nil)
@@ -26,14 +28,14 @@
(write-char #\Newline stream) (write-char #\Newline stream)
(setf *yeni-satır* t))) (setf *yeni-satır* t)))
(defmethod node->html (node stream) (defmethod node->html ((node node) &optional (stream *standard-output*))
(if (null (children node)) (if (null (children node))
(format stream "~a" (value node)) (format stream "~a" (value node))
(let ((*indent* (+ *indent* *indent-increment*))) (let ((*indent* (+ *indent* *indent-increment*)))
(loop :for child :in (children node) (loop :for child :in (children node)
:do (node->html child stream))))) :do (node->html child stream)))))
(defmethod node->html :after (node stream) (defmethod node->html :after ((node node) &optional (stream *standard-output*))
(unless (null *yeni-satır*) (unless (null *yeni-satır*)
(loop :for i :from 0 :below *indent* (loop :for i :from 0 :below *indent*
:do (write-char #\Space stream))) :do (write-char #\Space stream)))