5

Seems like restructured text markup is very limited when it comes to image options:

The following options are recognized:
alt : text
height : length
width : length or percentage of the current line width
scale : integer percentage (the "%" symbol is optional)
align : "top", "middle", "bottom", "left", "center", or "right"
target : text (URI or reference name)

Is it possible to set some custom attributes like title via reStructuredText markup?

e.g.

.. image:: foobar.jpg 
    :title: mouse over text, hi!

Would output:

<img src="foobar.jpg" title="mouse over text, hi!"></img>
Granitosaurus
  • 20,530
  • 5
  • 57
  • 82
  • Possible duplicate of [How I can add attribute to img tag in Pelican](https://stackoverflow.com/questions/43819422/how-i-can-add-attribute-to-img-tag-in-pelican) – jonrsharpe Jan 29 '18 at 22:17

3 Answers3

4

You can use figure

.. figure:: picture.png

   This is the caption of the figure.
  • This results in the caption showing up below the image. While this can be very useful, it is different from adding a `title` attribute in `` (which makes the text show up when hovering the mouse over the image). – luator Sep 30 '21 at 10:08
3

According to docutils, the following options are recognized: alt, height, width, scale, align, target, class, and name. No title.

Options include rewriting in the client with JavaScript or work with the docutils team to make a feature request and implement it.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
  • Yes, I pointed this out in my question. Having some javascript to move `alt` attribute to `title` is a great idea though! I'll consider a PR to docutils too :) – Granitosaurus Jan 29 '18 at 10:16
  • The `alt` attribute isn't really intended to be a caption, the way a title sometimes is, but to describe the image in case it can't be displayed; either because it did not load or for screen readers. e.g. `The head and torso of a dinosaur skeleton; it has a large head with long sharp teeth` https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Images_in_HTML#image_titles – Ryan Allen May 14 '22 at 13:25
2

Alternatively you could simply use the "raw" directive and directly use your ideal target html

.. raw:: html

    <img src="foobar.jpg" title="mouse over text, hi!"></img>
Trevor
  • 434
  • 4
  • 8