2

我正在使用 ActionText 呈现一些富文本,由于某种原因,我在使用 actiontext 提供的部分向呈现的部分添加额外元素时受到限制

我需要将附加图像包裹在表格元素周围,以便它们可以在 Outlook 中正确呈现电子邮件。ActionText 似乎总是忽略我放入的这个部分中的任何额外元素。任何人都知道为什么会发生这种情况以及是否有任何解决方法?

这是我的部分,表格元素被忽略:

/views/active_storage/blob/_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>
4

4 回答 4

2

我发现问题与使用内部方法在渲染之前对字符串进行清理的操作文本有关。

我在初始化程序中覆盖了允许的属性和标签:

ActionText::ContentHelper.allowed_attributes.add 'style'
ActionText::ContentHelper.allowed_attributes.add 'controls'

ActionText::ContentHelper.allowed_tags.add 'video'
ActionText::ContentHelper.allowed_tags.add 'source'
于 2019-12-09T11:34:47.117 回答
0

就我而言,当我在 _blob.html.erb 中将自定义属性 (data-) 添加到 link_to 助手时,它并未包含在呈现的链接标记中。

<% if blob.representable? %>
  <%= link_to image_tag(blob.representation(resize_to_limit: 
local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), 
class: 'rounded'), rails_blob_path(blob), { 'data-fancybox': 'gallery' } %>
<% end %>
于 2019-12-09T10:00:05.740 回答
0

我想知道如何在 _blob.html.erb 文件中获取 action_name。因为我想根据动作名称显示或关闭图像链接,例如show,,edit

于 2019-12-10T21:44:44.723 回答
0
# config/initializers/html_sanitation.rb

Rails::Html::WhiteListSanitizer.allowed_tags << 'h2'
于 2020-05-03T13:06:30.183 回答