我正在尝试这样做,以便在将正文图像插入页面时,将引导类“img-responsive”添加到图像标签中?
谁能告诉我如何实现这一目标?
我正在尝试这样做,以便在将正文图像插入页面时,将引导类“img-responsive”添加到图像标签中?
谁能告诉我如何实现这一目标?
您可以通过图像格式做到这一点:
将图像插入富文本区域时通常会得到的“全宽”/“左对齐”/“右对齐”选项来自 Format 对象,它决定了如何将图像引用转换为最终标记。因此,您需要将内置的 Format 对象替换为插入您的类名的对象。在您的应用程序中创建一个文件“image_formats.py”,其中包含以下内容:
from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format
unregister_image_format('fullwidth')
register_image_format(Format('fullwidth', 'Full width', 'richtext-image full-width img-responsive', 'width-800'))
unregister_image_format('left')
register_image_format(Format('left', 'Left-aligned', 'richtext-image left img-responsive', 'width-500'))
unregister_image_format('right')
register_image_format(Format('right', 'Right-aligned', 'richtext-image right img-responsive', 'width-500'))