Menu

#108 title/tooltip option for the "image" directive

Default
pending-moreinfo
nobody
None
5
2025-04-28
2024-09-29
toastal
No

Like image’s :alt: directive, allow :title: for creating titles on pointer hover. The use case here is different from alt as alt is for assistive technologies & titles are more to give a labels for images for those with pointer cursors.

Expected input

.. image:: /house.jxl
    :alt: Home
    :title: Navigate home
    :target: /

.. image:: /cat.jxl
    :alt: A Siamese cat on a chair
    :title: Chula says, “meow”

Expected HTML output

<a href="/"><img src="/house.jxl" alt="Home" title="Navigate home"></a>
<img src="/cat.jxl" alt="A Siamese cat on a chair" title="Chula says, “meow”">

~~~

Discussion

  • Günter Milde

    Günter Milde - 2024-10-01

    Thank you for the suggestion.
    Support for the <img> "title" attribute in HTML output would require a means to store the
    title in the <image> document tree element, e.g. a new attribute.
    Before an implementation, we would have to consider how an image "title" option/attribute should be handled in other output formats like LaTeX/PDF or OpenDocument text.

    Alternatively, a figure with approbiately styled caption might suit your needs:

    For the rST source

    .. figure:: meow.png
    
       A siamese cat.
    

    a possible styling of HTML5 writer output would be

    figcaption {
      display: none;
      padding: 1em;
      width: 30vw;
      background: lightyellow}
    figure:hover figcaption { display: block; }
    
     

    Last edit: Günter Milde 2024-10-01
  • Günter Milde

    Günter Milde - 2024-10-01
    • summary: Image title directive --> Image title directive option
     
  • toastal

    toastal - 2024-10-01

    I would say the title is strictly for HTML output. In the way that touch pointers often can’t read the title, it is left for cursor pointer & screen readers. Thinking about it in this sense tho, I think even if the HTML attribute is called title the name is probably easily confused with something visible. HTML spec says to not ‘rely’ on it, but it makes a good place for Easter eggs or other flavor commentary.

    For context, my existing workaround is, as you noted, using a .. figure & post-processing based on a specific CSS class to 1) move <figcaption> contents to title, 2) ‘unwrap’ the parent figure node to just leave the <img> behind, but this feels like a hack/abuse, especially since the flavor text isn’t meant to be visible for PDFs which the .. figure would show.

    More info: https://html.spec.whatwg.org/multipage/dom.html#the-title-attribute

     
  • Günter Milde

    Günter Milde - 2024-10-14
    • summary: Image title directive option --> "title" option for the "image" directive
     
  • Günter Milde

    Günter Milde - 2024-10-15

    If at all, an attribute/option to-be-translated to the HTML "title" attribute would come under a different name ("tooltip" or "annotation", say):

    • Looking at its description in the HTML standard, the "title" attribute seems misnamed. It contains "advisory information" presented as a tooltip (or not at all).
    • It can easily be confused with the HTML <title> element.
    • In Docutils, there is already a "title" attribute: Used on the <document> element for the "metadata title" (which corresponds to the HTML <title> element) and is, e.g. shown on a browsers toolbar.

    Where should Docutils/rST support stop?

    • In HTML, "title" is one of the common attributes, supported by (almost) all elements.

    • The LaTeX package "pdfcomment" provides a \pdftooltip macro that creates
      pop-ups in PDF output. Like the HTML "title" attribute, it can be used on paragraphs, tables, footnote references, and more.

    However, whether support for an attribute you may use for easter eggs but must not rely on is a valuable addition for a lightweight markup language remains questionable.
    For the rare use cases exist workarounds in form of CSS rules or "raw" HTML.

    Commit [r9950] adds support for class values on the figure caption. Now you can write:

    .. figure:: meow.png
        .. class:: tooltip
    
       A siamese cat.
    

    and style the resulting HTML5 writer output with

     figcaption.tooltip {
       display: none;
       padding: 0.5em;
       width: 20vh;
       background: lightyellow;
       }
     figure:hover figcaption.tooltip { 
       display: block; 
       position: absolute;
       }
    

    To suppress the tooltip in PDF output, convert with

    rst2latex --strip-elements-with-class=tooltip
    
     

    Related

    Commit: [r9950]


    Last edit: Günter Milde 2025-04-28
  • Günter Milde

    Günter Milde - 2024-10-17
    • status: open --> pending-works-for-me
     
  • Günter Milde

    Günter Milde - 2025-02-15
    • summary: "title" option for the "image" directive --> title/tooltip option for the "image" directive
    • status: pending-works-for-me --> pending
     
  • Günter Milde

    Günter Milde - 2025-04-28
    • status: pending --> pending-moreinfo
     
  • Günter Milde

    Günter Milde - 2025-04-28

    This feature request needs more thought and discussion.
    It may be a topic for a new enhancement proposal.

     

    Last edit: Günter Milde 2025-04-29

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.