Reapply "ox-html: Use <img> tags for svgs, not <object>"

This reverts commit 302bc6393a.

It turns out that <object ...> tags with data pointing outside the
website are not rendered by the modern
qtwebengine (linked svgs in https://orgmode.org/tools.html are not
rendered). Even though Firefox does render the same page, it no longer
appears safe to use <object ...> for svg.  So, we have to use <img...>
with its limitations.
This commit is contained in:
Ihor Radchenko 2024-06-03 11:14:41 +02:00
parent 8e8e635eba
commit 77e77f051c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 12 additions and 37 deletions

View File

@ -1772,43 +1772,18 @@ SOURCE is a string specifying the location of the image.
ATTRIBUTES is a plist, as returned by ATTRIBUTES is a plist, as returned by
`org-export-read-attribute'. INFO is a plist used as `org-export-read-attribute'. INFO is a plist used as
a communication channel." a communication channel."
(if (string= "svg" (file-name-extension source)) (org-html-close-tag
(org-html--svg-image source attributes info) "img"
(org-html-close-tag (org-html--make-attribute-string
"img" (org-combine-plists
(org-html--make-attribute-string (list :src source
(org-combine-plists :alt (if (string-match-p
(list :src source (concat "^" org-preview-latex-image-directory) source)
:alt (if (string-match-p (org-html-encode-plain-text
(concat "^" org-preview-latex-image-directory) source) (org-find-text-property-in-string 'org-latex-src source))
(org-html-encode-plain-text (file-name-nondirectory source)))
(org-find-text-property-in-string 'org-latex-src source)) attributes))
(file-name-nondirectory source))) info))
attributes))
info)))
(defun org-html--svg-image (source attributes info)
"Return \"object\" embedding svg file SOURCE with given ATTRIBUTES.
INFO is a plist used as a communication channel.
The special attribute \"fallback\" can be used to specify a
fallback image file to use if the object embedding is not
supported. CSS class \"org-svg\" is assigned as the class of the
object unless a different class is specified with an attribute."
(let ((fallback (plist-get attributes :fallback))
(attrs (org-html--make-attribute-string
(org-combine-plists
;; Remove fallback attribute, which is not meant to
;; appear directly in the attributes string, and
;; provide a default class if none is set.
'(:class "org-svg") attributes '(:fallback nil)))))
(format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
source
attrs
(if fallback
(org-html-close-tag
"img" (format "src=\"%s\" %s" fallback attrs) info)
"Sorry, your browser does not support SVG."))))
(defun org-html--textarea-block (element) (defun org-html--textarea-block (element)
"Transcode ELEMENT into a textarea block. "Transcode ELEMENT into a textarea block.