我们有一个内容编辑想要的用例
虽然富文本编辑器允许我们选择右对齐格式的图像,但没有指定图像宽度的选项。
如何自定义 Wagtail“选择格式”模式来添加图像宽度的新字段并在渲染输出中使用它?我希望避免创建额外的图像格式以及可能的图像对齐/宽度排列,因为这是两个独立的属性。
请参阅 WordPress 古腾堡图像设置 下面的 UI 了解现有技术。
# image_formats.py
from wagtail.images.formats import Format, register_image_format
class SubclassedImageFormat(Format):
def image_to_html(self, image, alt_text, extra_attributes=None):
original_html = super().image_to_html(image, alt_text, extra_attributes)
return original_html.replace('class="', 'class="foo')
register_image_format(
SubclassedImageFormat('subclassed_format', 'Subclassed Format', classnames, filter_spec)
)
全部大写的答案是错误的。 Brylie Christopher Oxley 明确表示:“我希望避免创建额外的图像格式以及可能的图像对齐/宽度排列,因为这是两个独立的属性。”我有同样的问题。如何添加额外的 css 类选择字段,而不是为每个可能的尺寸和对齐组合乘以格式?