I've attached a patch for restoring the correct case of SVG attributes
parsed with libxml-parse-html-region when displayed with shr, so that
SVGs can be displayed properly. HTML attributes are case-insensitive and
converted to lowercase, but SVG attributes are case-sensitive, so things
like viewBox don't work if they're lowercased. It looks like other
implementations (ex: https://github.com/w3c/svgwg/issues/161 ) also use
the workaround of fixing attribute cases for SVGs, so I took the list
from
https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
and fixed those attributes.
Here's a small test to demonstrate the issue:
;; The following should display a full circle, not a quarter circle
(with-current-buffer (get-buffer-create "*test*")
(erase-buffer)
(insert "\n")
(shr-insert-document (libxml-parse-html-region (point-min) (point-max)))
(display-buffer (current-buffer)))
And for shr-correct-dom-case to make sure it's working correctly:
(ert-deftest shr-correct-dom-case ()
(let ((case-fold-search nil))
(should
(string-match
"viewBox"
(shr-dom-to-xml
(shr-correct-dom-case
(with-temp-buffer
(insert "")
(libxml-parse-html-region (point-min) (point-max)))))))))
There are a few more screenshots at
https://sachachua.com/blog/2024/01/patching-elfeed-and-shr-to-handle-svg-images-with-viewbox-attributes/ .
I should have copyright assignment papers on file.