Revert "lisp/ox-html.el: Convert :alt to :aria-label attribute in svg images"

This reverts commit 0e5ac43324.
This commit is contained in:
Ihor Radchenko 2024-06-03 11:14:31 +02:00
parent 5f050580d8
commit 8e8e635eba
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 24 additions and 41 deletions

View File

@ -1772,60 +1772,43 @@ 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."
(let ((alt (if (string= "svg" (file-name-extension source))
(if (string-match-p (org-html--svg-image source attributes info)
(concat "^" org-preview-latex-image-directory) source) (org-html-close-tag
(org-html-encode-plain-text "img"
(org-find-text-property-in-string 'org-latex-src source)) (org-html--make-attribute-string
(file-name-nondirectory source)))) (org-combine-plists
(if (string= "svg" (file-name-extension source)) (list :src source
(org-html--svg-image :alt (if (string-match-p
source (concat "^" org-preview-latex-image-directory) source)
(org-combine-plists (org-html-encode-plain-text
(list :alt alt) ; fallback when no :alt in attributes (org-find-text-property-in-string 'org-latex-src source))
attributes) (file-name-nondirectory source)))
info) attributes))
(org-html-close-tag info)))
"img"
(org-html--make-attribute-string
(org-combine-plists
(list :src source :alt alt) ; fallback when no :alt in attributes
attributes))
info))))
(defun org-html--svg-image (source attributes info) (defun org-html--svg-image (source attributes info)
"Return \"object\" embedding svg file SOURCE with given ATTRIBUTES. "Return \"object\" embedding svg file SOURCE with given ATTRIBUTES.
INFO is a plist used as a communication channel. ALT is the INFO is a plist used as a communication channel.
alternative text to be used as a fallback when image is not suitable
for display.
The special attribute \"fallback\" can be used to specify a The special attribute \"fallback\" can be used to specify a
fallback image file to use if the object embedding is not fallback image file to use if the object embedding is not
supported. Attribute :alt can be specified and will be transformed supported. CSS class \"org-svg\" is assigned as the class of the
into :aria-label. CSS class \"org-svg\" is assigned as the class of object unless a different class is specified with an attribute."
the object unless a different class is specified with an attribute."
(let ((fallback (plist-get attributes :fallback)) (let ((fallback (plist-get attributes :fallback))
(attrs (org-html--make-attribute-string (attrs (org-html--make-attribute-string
(org-combine-plists (org-combine-plists
'(:class "org-svg")
;; Replace :alt attribute not allowed in object tags
;; with :aria-label. :aria-label in attributes, if
;; any, takes priority.
(when-let ((alt (plist-get attributes :alt)))
`(:aria-label ,alt))
attributes
;; Remove fallback attribute, which is not meant to ;; Remove fallback attribute, which is not meant to
;; appear directly in the attributes string, and ;; appear directly in the attributes string, and
;; provide a default class if none is set. ;; provide a default class if none is set.
'(:fallback nil) '(:class "org-svg") attributes '(:fallback nil)))))
;; Remove :alt attribute not allowed in object tags. (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
'(:alt nil) source
`(:type "image/svg+xml" :data ,source)))))
(format "<object %s>\n%s</object>"
attrs attrs
(cond (if fallback
(fallback (org-html--format-image fallback attrs info)) (org-html-close-tag
(t "Sorry, your browser does not support SVG."))))) "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.