ewwを使っていたら「error in process filter: Invalid image type ‘svg’」というエラーが出たとき

ewwでリンク先のページに飛んだ時、表題のエラーに出会うことがある。 これはEmacssvgをサポートする形でコンパイルされていないから、ということ。 しかしeww(というかshr)はsvgが使える前提で一部の関数が実装されているのが問題。

当面、以下の関数を再定義して、しのぐことにする。 オリジナルの関数からの変更点は、(memq 'svg image-types)を関数後部あたりに入れたこと。

(defun shr-parse-image-data ()
  (let ((data (buffer-substring (point) (point-max)))
        (content-type
         (save-excursion
           (save-restriction
             (narrow-to-region (point-min) (point))
             (let ((content-type (mail-fetch-field "content-type")))
               (and content-type
                    ;; Remove any comments in the type string.
                    (intern (replace-regexp-in-string ";.*" "" content-type)
                            obarray)))))))
    ;; SVG images may contain references to further images that we may
    ;; want to block.  So special-case these by parsing the XML data
    ;; and remove anything that looks like a blocked bit.
    (when (and shr-blocked-images
               (eq content-type 'image/svg+xml))
      (setq data
            ;; Note that libxml2 doesn't parse everything perfectly,
            ;; so glitches may occur during this transformation.  And
            ;; encode as utf-8: There may be text (and other elements)
            ;; that are non-ASCII.
            (shr-dom-to-xml
             (libxml-parse-xml-region (point) (point-max)) 'utf-8)))
    ;; SVG images often do not have a specified foreground/background
    ;; color, so wrap them in styles.
    (when (and (display-images-p)
               (eq content-type 'image/svg+xml)
               (memq 'svg image-types)) ;; ←SVGが含まれていないときにnil
      (setq data (svg--wrap-svg data)))
    (list data content-type)))