我创建了一个WordpressComment类,该类检查注释是否引用了另一个注释。如果这样做,则会以与用户界面相同的方式添加引用
def body(lookup)
quoted = nil
parent = nil
if parent_import_id != nil then
parent_id = lookup::post_id_from_imported_post_id(parent_import_id)
parent = Post.where(id:parent_id).first
if parent != nil then
user = User.where(id:parent.user_id).first
@parent_user_name = user.username_lower
quoted = "[quoted=\"#{parent_user_name}, post:#{parent.post_number}, topic:#{parent.topic_id}\"]<br/><br/>#{parent.cooked}<br/>[/quote]<br/>"
end
end
return "#{quoted}#{content}<p /><p />#{author}<p />#{author_url}".gsub(/\\n/,'<br/>').strip[0...32000]
end
它插入了正确的链接..但显示不正确。
看起来像这样
[quote =“ {username},post:{post_id},topic:topic_id”] ...引用文字... [/ quote]
我研究了search?q=quoting another post #dev
有趣的是,我发现了几则引用相同问题的帖子。
如何在post.raw中的另一篇文章中添加报价,以使其呈现出来?
答案 0 :(得分:0)
干杯致谢,感谢meta.discousre.org上的Florian
问题是我已经引用而不是引用,并且引用行末必须有换行符。
修复错字并插入换行符就可以了!
def body(lookup)
quoted = nil
parent = nil
if parent_import_id != nil then
parent_id = lookup::post_id_from_imported_post_id(parent_import_id)
parent = Post.where(id:parent_id).first
if parent != nil then
user = User.where(id:parent.user_id).first
@parent_user_name = user.username_lower
quoted = "[quote=\"#{parent_user_name}, post:#{parent.post_number}, topic:#{parent.topic_id}\"]<br/><br/>#{parent.cooked}<br/>[/quote]\n<br/>"
end
end
return "#{quoted}#{content}<p /><p />#{author}<p />#{author_url}".gsub(/\\n/,'<br/>').strip[0...32000]
end