RestructuredText - adding title attributes to links

心已入冬 提交于 2019-12-12 08:50:08

问题


I am trying to use a jQuery lightBox implementation on my website that is generated from reStructuredText. The lightBox takes the title of the link around the images as the caption of the image in the lightBox display.

However, I can't seem to find a way in reStructuredText of providing a title attribute on a link - does anyone know of a way of doing this? My images are defined like so:

.. image:: image001.thumb.jpg
    :alt: Some alt text here
    :target: image001.jpg

So I can add an alt attribute, but not a title. A possible alternative may be to use a target as the reference like so:

.. image:: image001.thumb.jpg
    :alt: Some alt text here
    :target: image1_

.. _image1: image001.jpg

In this latter case, I am not sure how to add attributes to the link defined at the bottom (if it is possible at all).


回答1:


I assume (try it out!), the title attribute is no longer needed by lightbox after lightbox is initialized. So if you'd like to provide the images alt-attributes as title, this one should do so, if you call it after lightbox-initialization:

function alt_2_title () {
    $("img[alt]").each(function(){
        $(this).attr('title', $(this).attr('alt'));
    });
});

This copies alt to title for every image that has an alt-attribute; If you like to modify only a few images, you might restrict you images selection by using something like ...

function alt_2_title (name_of_container) {
    $("img[alt]", "#"+name_of_container).each(function(){
        $(this).attr('title', $(this).attr('alt'));
    });
});


来源:https://stackoverflow.com/questions/4561953/restructuredtext-adding-title-attributes-to-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!