aboutsummaryrefslogtreecommitdiff
path: root/module/html/util.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-08-13 10:43:33 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-08-13 10:43:33 +0200
commita902eb51621521d45c648d6a4d06d70d981dfaeb (patch)
treeafc31d4d17fa3939585ad30878b5b690d3b80db3 /module/html/util.scm
parentAdd TODO's (diff)
parentComment about generalizing. (diff)
downloadcalp-a902eb51621521d45c648d6a4d06d70d981dfaeb.tar.gz
calp-a902eb51621521d45c648d6a4d06d70d981dfaeb.tar.xz
Merge branch 'calchooser' into master
Diffstat (limited to 'module/html/util.scm')
-rw-r--r--module/html/util.scm31
1 files changed, 29 insertions, 2 deletions
diff --git a/module/html/util.scm b/module/html/util.scm
index 36b1d929..edbcf756 100644
--- a/module/html/util.scm
+++ b/module/html/util.scm
@@ -1,10 +1,37 @@
(define-module (html util)
+ :use-module ((util base64)
+ :select (base64encode base64decode))
:use-module (util))
+;;; @var{html-attr} & @var{html-unattr} used to just strip any
+;;; attributes not valid in css. That allowed a human reader to
+;;; quickly see what data it was. The downside was that it was one
+;;; way. The new base64 based system supports both an encode and a
+;;; decode without problem.
+;;;
+;;; The encoded string substitutes { + => å, / => ä, = => ö } to be
+;;; valid CSS selector names.
+
;; Retuns an HTML-safe version of @var{str}.
(define-public (html-attr str)
- (define cs (char-set-adjoin char-set:letter+digit #\- #\_))
- (string-filter (lambda (c) (char-set-contains? cs c)) str))
+ (string-map (lambda (c)
+ (case c
+ ((#\+) #\å)
+ ((#\/) #\ä)
+ ((#\=) #\ö)
+ (else c)))
+ (base64encode str)))
+
+(define-public (html-unattr str)
+ (base64decode
+ (string-map (lambda (c)
+ (case c
+ ((#\å) #\+)
+ ((#\ä) #\/)
+ ((#\ö) #\=)
+ (else c)))
+ str)))
+
(define-public (date-link date)
((@ (datetime) date->string) date "~Y-~m-~d"))