Skip to content

Commit

Permalink
Preformatted text should bypass the html stream.
Browse files Browse the repository at this point in the history
Closes #20.
  • Loading branch information
ruricolist committed Jul 14, 2017
1 parent d50add1 commit d80c90d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
12 changes: 8 additions & 4 deletions run.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@
(when (> col goal)
(terpri stream)))))

(defun fill-text (string &optional safe? &aux (html *html*))
(defun fill-text (string &optional safe?
&aux (html *html*)
(pretty? *print-pretty*)
(pre? *pre*))
(check-type string string)
(cond
((= (length string) 0))
(*pre*
(fast-format html "~&~A~%" string))
(*print-pretty*
(pre?
(let ((stream (html-stream.base-stream html)))
(fast-format stream "~A" string)))
(pretty?
(let* ((start-col (get-indent))
(fill *fill-column*)
(goal (+ fill start-col)))
Expand Down
7 changes: 6 additions & 1 deletion stream.lisp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
(in-package :spinneret)

(defgeneric html-stream.base-stream (stream)
(:method ((stream stream))
stream))

(defclass html-stream (fundamental-character-output-stream)
((col :type (integer 0 *) :initform 0
:reader html-stream-column
Expand All @@ -12,7 +16,8 @@
(elastic-newline :type boolean
:initform nil)
(base-stream :type stream
:initarg :base-stream))
:initarg :base-stream
:reader html-stream.base-stream))
(:default-initargs))

(defun make-html-stream (base-stream)
Expand Down
23 changes: 23 additions & 0 deletions tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,26 @@
(with-html-string
(:div
(:p "Text " (:a "link text") " more text"))))))))

(test textarea-preformatting
(flet ((test1 ()
(with-html-string
(:div (:textarea "123"))))
(test2 ()
(with-html-string
(let ((*print-pretty*))
(:div (:textarea "123"))))))
(with-pretty-printing
(is (visually-equal (test1)
(format nil "~
<div>
<textarea>123
</textarea>
</div>")))
(is (visually-equal (test2)
"<div><textarea>123</textarea></div>")))
;; Test that dereferencing the underlying stream works when the
;; stream is not, in fact, an HTML stream.
(without-pretty-printing
(is (visually-equal (test2)
"<div><textarea>123</textarea></div>")))))

0 comments on commit d80c90d

Please sign in to comment.