我正在使用 ActionText 渲染一些富文本,由于某种原因,我在使用 actiontext 提供的部分向渲染的部分添加额外元素时受到限制
我需要将附加图像包裹在表格元素周围,以便可以在 Outlook 中为电子邮件正确呈现它们。 ActionText 似乎总是忽略我放入的这部分中的任何额外元素。有人知道为什么会发生这种情况以及是否有任何方法可以解决此问题?
这是我的部分,其中表格元素被忽略:
/views/active_storage/blobs/_blob.html.erb
<table>
<Tr>
<td>
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %> text-center">
<% if blob.representable? %>
<%= image_tag rails_representation_url(blob.representation(resize_to_limit: [600, 400])) %>
<% if caption = blob.try(:caption) %>
<figcaption class="attachment__caption text-center">
<%= caption %>
</figcaption>
<% end %>
<% end %>
</figure>
</td>
</Tr>
</table>
最佳答案
我发现问题与 Action Text 使用内部方法在渲染之前清理字符串有关。
我覆盖初始化程序中允许的属性和标签:
ActionText::ContentHelper.allowed_attributes.add 'style'
ActionText::ContentHelper.allowed_attributes.add 'controls'
ActionText::ContentHelper.allowed_tags.add 'video'
ActionText::ContentHelper.allowed_tags.add 'source'
关于ruby-on-rails - ActionText blob 部分不渲染额外元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59019537/