reader: html: Add support for multiple top-level elements.
authorJakob L. Kreuze <zerodaysfordays@sdf.lonestar.org>
Sun, 28 Apr 2019 16:47:39 +0000 (12:47 -0400)
committerDavid Thompson <dthompson@vistahigherlearning.com>
Tue, 21 May 2019 12:40:40 +0000 (08:40 -0400)
Currently, if given a file containing more than one top-level elements,
'read-html-post will only return the first.

haunt/reader.scm

index 305bcee..37c390b 100644 (file)
@@ -105,8 +105,17 @@ post."
 
 (define (read-html-post port)
   (values (read-metadata-headers port)
-          (match (xml->sxml port)
-            (('*TOP* sxml) sxml))))
+          (let loop ()
+            (let ((next-char (peek-char port)))
+              (cond
+               ((eof-object? next-char)
+                '())
+               ((char-set-contains? char-set:whitespace next-char)
+                (read-char port)
+                (loop))
+               (else
+                (match (xml->sxml port)
+                  (('*TOP* sxml) (cons sxml (loop))))))))))
 
 (define html-reader
   (make-reader (make-file-extension-matcher "html")