From 3924728babeaa809f263e127381d44f7ee0dd140 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 2 Jul 2021 02:28:27 -0700 Subject: [PATCH] Add trickery to support embedded SVG images - Specify the svg and xlink namespaces to the `xml->sxml' procedure so that it doesn't include them in full for each tag. - For the default `pre-post-order' handler strip the `svg:' prefix if found. - Strip the `svg:' namespace from the SVG element and insert the `xmlns' and `xmlns:xlink' namespace definition attributes into the attributes. This is all very brittle and badly done, but for the moment this fixes my use-case of wanting to display SVG images embedded in the HTML. --- tekuti/filters.scm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tekuti/filters.scm b/tekuti/filters.scm index be37d0c..5c64f39 100644 --- a/tekuti/filters.scm +++ b/tekuti/filters.scm @@ -80,15 +80,24 @@ (define (wordpress->sxml text) (let ((sxml (cadr (with-input-from-string* (string-append "
" text "
") - xml->sxml)))) + (lambda () (xml->sxml #:namespaces '((svg . "http://www.w3.org/2000/svg")))))))) (pre-post-order sxml `((*default* . ,(lambda (tag . body) - (if (can-contain-p? tag) - (wpautop tag body) - (cons tag body)))) + (let ((tag (if (string-prefix? "svg:" (symbol->string tag)) + (string->symbol (substring (symbol->string tag) 4)) + tag))) + (if (can-contain-p? tag) + (wpautop tag body) + (cons tag body))))) (*text* . ,(lambda (tag text) - text)))))) + text)) + (svg:svg . ,(lambda (tag . body) + (cons 'svg + (cons `(@ (xmlns "http://www.w3.org/2000/svg") + (xmlns:xlink "http://www.w3.org/1999/xlink") + ,@(cdar body)) + (cdr body))))))))) (define *allowed-tags* `((a (href . ,urlish?) title)