diff options
Diffstat (limited to 'config.scm')
-rw-r--r-- | config.scm | 40 |
1 files changed, 16 insertions, 24 deletions
@@ -4,16 +4,11 @@ (use-modules (ice-9 regex) (sxml simple) - - ;; TODO this module introduces description-filter. It should be - ;; possible to use set-config! before the declaration point is - ;; known. But I currently get a config error. - ;; (vcomponent datetime output) + (sxml xpath) ) (set-config! 'calendar-files (glob "~/.local/var/cal/*")) -;;; TODO possibly replace with propper lookup (define my-courses '((TSEA82 . "Datorteknik") (TFYA19 . "Kvantdatorer") @@ -32,20 +27,20 @@ 'pre (lambda (m) (aref my-courses (string->symbol (match:substring m)))) 'post))) -(define (a link) `(a (@ (href ,link)) ,link)) - (define (parse-html str) - ;; extra space to ensure that we don't get a self closing - ;; div tag in the final output - ;; TODO Fix a real sxml->html | The space - ;; method instead of pretending | - ;; that HTML is XML. v - (xml->sxml (string-append "<div> " str "</div>") - default-entity-handler: - (lambda (port name) - (case name - [(nbsp) " "] - [else (symbol->string name)]))) ) + (catch 'misc-error + ;; resolve-interface throws misc-error on missing module. + ;; TODO what does html->sxml throw? + (lambda () + (let* ((gumbo (resolve-interface '(sxml gumbo))) + (html->sxml (module-ref gumbo 'html->sxml))) + ;; html->sxml always gives us (html (head ...) (body <content>)) + ;; this strips it down to just <content> + (cdar ((sxpath '(// body)) (html->sxml str))))) + ;; Give up on parsing + (lambda _ str))) + +(define (a link) `(a (@ (href ,link)) ,link)) (define (parse-links str) (define regexp (make-regexp "https?://\\S+")) @@ -91,11 +86,8 @@ (set-config! 'description-filter (lambda (ev str) (cond [(member (prop (parent ev) 'NAME) - html-cals - ) - (parse-html (regexp-substitute/global - #f "<br>" str - 'pre "<br/>" 'post))] + html-cals) + (parse-html str)] [(prop ev 'X-MICROSOFT-SKYPETEAMSMEETINGURL) (parse-teams-description str)] [else (parse-links str)]))) |