Browse code
Flesh out the formatter a bit
fiddlerwoaroof authored on 31/01/2017 22:34:17
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -30,11 +30,13 @@ |
30 | 30 |
|
31 | 31 |
(defmethod format-document (formatter stream (document alimenta:item)) |
32 | 32 |
(call-next-method) |
33 |
- (let ((paragraphs (lquery:$ (initialize (alimenta:content document)) |
|
34 |
- (children) |
|
35 |
- (text)))) |
|
36 |
- (format stream "~&~v,4@t~a~2&" |
|
37 |
- (level formatter) (format-paragraph formatter (map 'list #'identity paragraphs))))) |
|
33 |
+ (let ((paragraphs (remove-if (op (every #'whitespacep _)) |
|
34 |
+ (lquery:$ (initialize (alimenta:content document)) |
|
35 |
+ (children) |
|
36 |
+ (text))))) |
|
37 |
+ (format stream "~&~{~a~%~}~2&" |
|
38 |
+ (map 'list (op (format-paragraph formatter _)) |
|
39 |
+ paragraphs)))) |
|
38 | 40 |
|
39 | 41 |
|
40 | 42 |
;;; Define some output formats |
... | ... |
@@ -48,8 +50,11 @@ |
48 | 50 |
(defmethod format-link ((formatter indent-formatter) (link string)) |
49 | 51 |
(format nil " Link: ~a" link)) |
50 | 52 |
|
53 |
+(defmethod format-paragraph ((formatter indent-formatter) (paragraph string)) |
|
54 |
+ (format nil "~&~v,4@t ~a~%" (level formatter) paragraph)) |
|
55 |
+ |
|
51 | 56 |
(defmethod format-paragraph ((formatter indent-formatter) (paragraph list)) |
52 |
- (format nil "~{ ~a~}" paragraph)) |
|
57 |
+ (format nil "~&~{ ~a~%~}" paragraph)) |
|
53 | 58 |
|
54 | 59 |
(defmethod format-document ((formatter indent-formatter) stream (document alimenta:feed)) |
55 | 60 |
(call-next-method) |
... | ... |
@@ -66,13 +71,16 @@ |
66 | 71 |
(defmethod format-link ((formatter html-formatter) (link string)) |
67 | 72 |
(format nil "<a href=\"~a\">~:*~a</a>" link)) |
68 | 73 |
|
74 |
+(defmethod format-paragraph ((formatter html-formatter) (paragraph string)) |
|
75 |
+ (format nil "~&<p>~a</p>" paragraph)) |
|
76 |
+ |
|
69 | 77 |
(defmethod format-paragraph ((formatter html-formatter) (paragraph list)) |
70 | 78 |
(format nil "~%~{<p>~a</p>~}" paragraph)) |
71 | 79 |
|
72 | 80 |
(defmethod format-document ((formatter html-formatter) stream (document alimenta:feed)) |
73 | 81 |
(let ((ostream (or stream (make-string-output-stream)))) |
74 | 82 |
(unwind-protect |
75 |
- (progn (format ostream "~&<html><head></head><body><main>~%") |
|
83 |
+ (progn (format ostream "~&<html><head><style>main{max-width:40em;margin-left:20em}h1,h2{margin-left:-3em}</style></head><body><main>~%") |
|
76 | 84 |
(call-next-method formatter ostream document) |
77 | 85 |
(incf (level formatter)) |
78 | 86 |
(for:for ((item over document)) |