diff options
Diffstat (limited to 'haunt/jakob/utils/comments.scm')
| -rw-r--r-- | haunt/jakob/utils/comments.scm | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/haunt/jakob/utils/comments.scm b/haunt/jakob/utils/comments.scm index a1deea7..65befca 100644 --- a/haunt/jakob/utils/comments.scm +++ b/haunt/jakob/utils/comments.scm @@ -17,24 +17,39 @@ (define-module (jakob utils comments) ;; #:use-module (dynamic capabilities comments) #:use-module (dynamic util) - #:use-module (hashing md5) + #:use-module (gcrypt base16) + #:use-module (gcrypt hash) #:use-module (ice-9 receive) #:use-module (ice-9 iconv) #:use-module (ice-9 match) #:use-module (srfi srfi-19) #:use-module (srfi srfi-43) + #:use-module (srfi-197) #:use-module (json) #:use-module (web client) #:use-module (web response) #:export (render-comment-view fetch-comments)) (define (gravatar-url email) - (format #f "https://www.gravatar.com/avatar/~a" (md5->string (md5 (string->bytevector (string-trim-both (string-downcase email)) "utf8"))))) -;; (chain email -;; (string-downcase _) -;; (string-trim-both _) -;; (string->bytevector _ "utf8") -;; (md5 _)) + (chain email + (string-downcase _) + (string-trim-both _) + (string->bytevector _ "utf8") + (bytevector-hash _ (lookup-hash-algorithm 'md5)) + (bytevector->base16-string _) + (format #f "https://www.gravatar.com/avatar/~a" _))) + +(define (safe-markdown->sxml text) + "Convert TEXT to an sxml form filtering out any unsafe entities" + (define (sanitize sexp) + (cond ((and (list? sexp) + (positive? (length sexp)) + (eqv? 'img (car sexp))) + #f) + ((list? sexp) + (filter identity (map sanitize sexp))) + (else sexp))) + (sanitize (commonmark->sxml text))) (define (format-comment comment) "Format `comment', an alist, as SXML for a comment-type interaction" |