我想使用标题来构建Atom Feed的内容:
atom_feed do |feed|
feed.title "#{Page.model_name.human(count: :other)} - #{t('app.name')}"
feed.updated(@pages[0].created_at) if @pages.length > 0
@pages.each do |page|
feed.entry(page) do |entry|
entry.title(page.title)
entry.content(type: 'html') do |html|
html.h1 t('.position_in_hierarchy')
html.p page.ancestors.reverse.map(&:title).join ': '
html.h1 Page.human_attribute_name :lead
html.div markdown page.lead
html.h1 Page.human_attribute_name :content
html.div markdown page.content
end
end
end
end
对于我的每个页面,这会产生以下生成的XML:
<entry>
<id>tag:localhost,2005:PageDecorator/1</id>
<published>2017-02-24T18:11:26+01:00</published>
<updated>2017-04-05T09:58:42+02:00</updated>
<link rel="alternate" type="text/html" href="http://localhost:3001/en/pages/1"/>
<title>Preparation</title>
<content type="html">
<h1>Position in page hierarchy</h1>
<p>Preparation</p>
<h1>Lead</h1>
<div><p>This the lead.</p></div>
<h1>Content</h1>
<div><p>This is some content!</p>
<h2 id="with-a-heading">With a heading</h2>
<p><a href="http://www.example.com">And a link!</a></p></div>
<h1>Notice about Atom feed</h1>
<p>Your feed reader has downloaded version 14 of the current page, which was current at April 05, 2017 09:58. Meanwhile there could be an updated version of the page available online. Visit the original page to see the most current version!</p>
</content>
</entry>
如您所见,html.h1
调用呈现为普通<h1>
。但有趣的是,我的饲料阅读器维也纳没有显示它们!更有趣的是,html.div
的内容是由我的自定义markdown
方法呈现的标记,是html转义...这些内容由维也纳呈现!
markdown
方法本身会转义HTML:
def markdown(string)
PandocRuby.convert(string, to: :html).html_safe
end
所以我现在还不确定如何使我的其他HTML标记在维也纳工作。
答案 0 :(得分:0)
正如Kris在评论中指出的那样,内容需要被转义:https://validator.w3.org/feed/docs/atom.html#text
最简单的方法就是渲染这样的部分:
entry.content(render(page), type: 'html')
这将呈现_page.atom.slim
(或.erb
或其他)并自动转义HTML。