blob: 09b26ad4a02e8bccf9ac81600e51566109672d5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
;;; Commentary:
;;; Module for transforming an already generated sxml tree.
;;; Ideally we would just generate the correct tree directly. But in some
;; circumstances that would lead to an absurd ammount of options and the
;; like, so these come in handy.
;;; Code:
(define-module (sxml transformations)
:use-module (hnh util)
:use-module ((srfi srfi-1) :select (concatenate))
:use-module ((sxml transform) :select (pre-post-order))
:export (attribute-transformer
href-transformer
href-prefixer
))
;; sxml, bindings → sxml
(define (attribute-transformer
tree attribute-bindings)
(define bindings
`((@ ,attribute-bindings
. ,(lambda (_ . b) `(@ ,@b)))
(*default* . ,(lambda (t . b) `(,t ,@b)))
(*text* . ,(lambda (_ . b) (concatenate b)))))
(pre-post-order tree bindings))
(define (href-transformer tree transformer)
(attribute-transformer
tree
`((href . ,(lambda (_ . content)
`(href ,@(transformer (string-concatenate (map ->string content))))
)))))
(define (href-prefixer tree prefix)
(href-transformer
tree (lambda (str) (string-append prefix str))))
|