tag içeriğinde '<', '>' ve '&' karakterlerini özel yazdır

This commit is contained in:
riton
2025-03-26 00:10:11 +03:00
parent 85b2910290
commit 06cc8a21bf

View File

@@ -23,6 +23,16 @@
(write-char #\Newline stream)
(setf *satır-başı* t))
;;;; https://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-in-html
;;; TODO geliştirme mümkün... ama şimdilik yeter (#\" "&quot;") (#\' "&#39;")
(defun kaçışlı-içerik-yazdır (metin stream)
(loop :for karakter :across metin
:do (case karakter
(#\< (write-string "&lt;" stream))
(#\> (write-string "&gt;" stream))
(#\& (write-string "&amp;" stream))
(t (write-char karakter stream)))))
(defmethod node->html :before ((node node) &optional (stream *standard-output*))
(unless (not *satır-başı*)
(loop :for i :from 0 :below *indent*
@@ -39,7 +49,7 @@
(defmethod node->html ((node node) &optional (stream *standard-output*))
(if (null (children node))
(format stream "~a" (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)))))