[Top][All Lists]

[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
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*")
        (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))
                                        (insert "<svg viewBox=\"0 0 100 
                                        (libxml-parse-html-region (point-min) 

There are a few more screenshots at

I should have copyright assignment papers on file.

Attachment: 0001-shr-Correct-SVG-attribute-case.patch
Description: Text Data

What do you think?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]