aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob/utils/sxml.scm
diff options
context:
space:
mode:
Diffstat (limited to 'haunt/jakob/utils/sxml.scm')
-rw-r--r--haunt/jakob/utils/sxml.scm40
1 files changed, 33 insertions, 7 deletions
diff --git a/haunt/jakob/utils/sxml.scm b/haunt/jakob/utils/sxml.scm
index 0bde0fe..5753f2d 100644
--- a/haunt/jakob/utils/sxml.scm
+++ b/haunt/jakob/utils/sxml.scm
@@ -14,17 +14,20 @@
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
-;;; Commentary:
-;;;
-;;; A number of utility procedure to aid in writing SXML by hand.
-;;;
-;;; Code:
-
(define-module (jakob utils sxml)
+ #:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
#:export (hyperlink
image
stylesheet
- script))
+ script
+
+ sanitize-subtree))
+
+
+;;;
+;;; Utility procedures to aid in writing SXML by hand.
+;;;
(define (hyperlink target text)
`(a (@ (href ,target)) ,text))
@@ -41,3 +44,26 @@
(define (script file-name)
(let ((src (string-append "/static/js/" file-name)))
`(script (@ (src ,src)))))
+
+
+;;;
+;;; A reader extension for implicitly-sanitized SXML trees.
+;;;
+
+(define (sanitize-subtree subtree)
+ "Remove `nil', `#f', and any unspecified elements from `sbtree'"
+ (if (list? subtree)
+ (map sanitize-subtree (remove (lambda (elt)
+ (or (unspecified? elt)
+ (eq? 'nil elt)
+ (eq? #f elt)))
+ subtree))
+ subtree))
+
+(define (sxml-reader chr port)
+ "Read an SXML literal expression possibly containing unquote forms and
+sanitize the resultant subtree."
+ `(sanitize-subtree ,(cons 'quasiquote (list (read port)))))
+
+;; Install the reader extension when imported.
+(read-hash-extend #\< sxml-reader)

© 2015 - 2026 Jakob L. Kreuze