如何在Pelican中将属性添加到img标签 [英] How I can add attribute to img tag in Pelican

查看:120
本文介绍了如何在Pelican中将属性添加到img标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向图像标签添加属性,以便从JavaScript库进行引用,如下所示.

I want to add attribute to image tag in order to reference from JavaScript library as below.

<img src="img/sample.png" data-action="zoom">  

但是,作为鹈鹕的结果,我只能添加如下所示的alt,宽度,高度.

However, I only can add alt, width, height as I know as below as outcome from Pelican.

<img alt="thumbnail" height="250px" src="/images/mech2.jpg">

推荐答案

如果使用的是Markdown(.md)文件来创建文章,则可以从字面上包括一个具有所需属性的图像元素:

If you're using a Markdown (.md) file to create your article, then you can literally just include an image element with any attributes you like:

![This image is in Markdown format]({filename}/images/foo.png)

<img alt="This one is just a literal element" src="{filename}/images/bar.png" data-action="zoom" >

将成为:

<p><img alt="This image is in Markdown format" src="../images/foo.png"></p>
<p><img alt="This one is just a literal element" src="../images/bar.png" data-action="zoom"></p>


对于reStructuredText(.rst)文章,您不能执行此操作; 根据文档仅支持有限的一组图像选项*,如果您只是尝试包含HTML内联,则会按原样呈现:


For reStructuredText (.rst) articles, you can't do this; per the documentation only a limited set of image options are supported*, and if you just try and include HTML inline it gets rendered out as-is:

.. image:: {filename}/images/foo.png
   :alt: this is an RST image directive

<img alt="This one is just a literal element" src="{filename}/images/bar.png" data-action="zoom">

成为:

<img alt="this is an RST image directive" src="../../../images/foo.png">
<p>&lt;img alt="This one is just a literal element" src="{filename}/images/bar.png" data-action="zoom"&gt;</p>

*具体为:altheightwidthscalealigntargetclassname.

* Specifically: alt, height, width, scale, align, target, class and name.

这篇关于如何在Pelican中将属性添加到img标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆