[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] shr.el: correct SVG attribute case
From: |
Sacha Chua |
Subject: |
[PATCH] shr.el: correct SVG attribute case |
Date: |
Fri, 26 Jan 2024 09:15:15 -0500 |
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 "<svg width=\"100px\" height=\"100px\" viewBox=\"0 0 200
200\"><circle cx=\"100\" cy=\"100\" r=\"100\"/></svg>\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 "<svg viewBox=\"0 0 100
100\"></svg>")
(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.
0001-shr-Correct-SVG-attribute-case.patch
Description: Text Data
What do you think?
Sacha
- [PATCH] shr.el: correct SVG attribute case,
Sacha Chua <=