diff options
| -rw-r--r-- | üretim.lisp | 30 | 
1 files changed, 16 insertions, 14 deletions
| diff --git a/üretim.lisp b/üretim.lisp index 3f8c8cc..51d75e0 100644 --- a/üretim.lisp +++ b/üretim.lisp @@ -2,25 +2,29 @@  (defparameter *indent* 0)  (defparameter *indent-increment* 2) -(defparameter *yeni-satır* t) +(defparameter *satır-başı* t)  (defgeneric node->html (node &optional stream)    (:method (node &optional (stream *standard-output*))      (write-string node stream))    (:documentation "NODE u STREAM e yazar")) -(defun tag-yeni-satır? (tag) +(defun tag-başı-yeni-satır? (tag)    (case tag      ((:html :head :body :div :ol :ul :link) t)      ((:title :p :b :i :code :li) nil))) -(defun tag-inline? (tag) +(defun tag-sonu-yeni-satır? (tag)    (case tag -    ((:html :head :body :div :ol :ul :li :p :title) nil) +    ((:html :head :body :div :ol :ul :li :p :title :pre) nil)      ((:b :i :code) t))) +(defun yeni-satır-yaz (stream) +  (write-char #\Newline stream) +  (setf *satır-başı* t)) +  (defmethod node->html :before ((node node) &optional (stream *standard-output*)) -  (unless (not *yeni-satır*) +  (unless (not *satır-başı*)      (loop :for i :from 0 :below *indent*            :do (write-char #\Space stream)))    (if (null (props node)) @@ -29,10 +33,9 @@              :for (k v) :on (props node) :by #'cddr              :do (format stream " ~a=\"~a\"" k v)              :finally (write-char #\> stream))) -  (setf *yeni-satır* nil) -  (when (tag-yeni-satır? (tag node)) -    (write-char #\Newline stream) -    (setf *yeni-satır* t))) +  (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)) @@ -42,13 +45,12 @@                :do (node->html child stream)))))  (defmethod node->html :after ((node node) &optional (stream *standard-output*)) -  (unless (not *yeni-satır*) +  (unless (not *satır-başı*)      (loop :for i :from 0 :below *indent*            :do (write-char #\Space stream))) -  (if (tag-inline? (tag node)) -      (format stream "</~a>" (tag node)) -      (progn (format stream "</~a>~%" (tag node)) -             (setf *yeni-satır* t)))) +  (format stream "</~a>" (tag node)) +  (when (tag-sonu-yeni-satır? (tag node)) +    (yeni-satır-yaz stream)))  (defun node->cons (node) | 
