mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-04 21:12:56 +00:00
lisp/ox-html.el: Convert :alt to :aria-label attribute in svg images
* lisp/ox-html.el (org-html--svg-image): When svg image has :alt attribute, convert it to :aria-label instead. (org-html--format-image): Pass default :alt attribute based on the file name to `org-html--svg-image'.
This commit is contained in:
parent
302bc6393a
commit
0e5ac43324
|
@ -1772,43 +1772,60 @@ 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))
|
(let ((alt
|
||||||
(org-html--svg-image source attributes info)
|
(if (string-match-p
|
||||||
(org-html-close-tag
|
(concat "^" org-preview-latex-image-directory) source)
|
||||||
"img"
|
(org-html-encode-plain-text
|
||||||
(org-html--make-attribute-string
|
(org-find-text-property-in-string 'org-latex-src source))
|
||||||
(org-combine-plists
|
(file-name-nondirectory source))))
|
||||||
(list :src source
|
(if (string= "svg" (file-name-extension source))
|
||||||
:alt (if (string-match-p
|
(org-html--svg-image
|
||||||
(concat "^" org-preview-latex-image-directory) source)
|
source
|
||||||
(org-html-encode-plain-text
|
(org-combine-plists
|
||||||
(org-find-text-property-in-string 'org-latex-src source))
|
(list :alt alt) ; fallback when no :alt in attributes
|
||||||
(file-name-nondirectory source)))
|
attributes)
|
||||||
attributes))
|
info)
|
||||||
info)))
|
(org-html-close-tag
|
||||||
|
"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.
|
INFO is a plist used as a communication channel. ALT is the
|
||||||
|
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. CSS class \"org-svg\" is assigned as the class of the
|
supported. Attribute :alt can be specified and will be transformed
|
||||||
object unless a different class is specified with an attribute."
|
into :aria-label. 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))
|
(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.
|
||||||
'(:class "org-svg") attributes '(:fallback nil)))))
|
'(:fallback nil)
|
||||||
(format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
|
;; Remove :alt attribute not allowed in object tags.
|
||||||
source
|
'(:alt nil)
|
||||||
|
`(:type "image/svg+xml" :data ,source)))))
|
||||||
|
(format "<object %s>\n%s</object>"
|
||||||
attrs
|
attrs
|
||||||
(if fallback
|
(cond
|
||||||
(org-html-close-tag
|
(fallback (org-html--format-image fallback attrs info))
|
||||||
"img" (format "src=\"%s\" %s" fallback attrs) info)
|
(t "Sorry, your browser does not support SVG.")))))
|
||||||
"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.
|
||||||
|
|
Loading…
Reference in a new issue