allow embedded images in story text, but still not in comments

This commit is contained in:
joshua stein 2012-09-17 13:24:29 -05:00
parent cb5e05c461
commit b7e5447c1d
5 changed files with 18 additions and 6 deletions

View file

@ -251,7 +251,7 @@ class Story < ActiveRecord::Base
end
def generated_markeddown_description
Markdowner.to_html(self.description)
Markdowner.to_html(self.description, allow_images = true)
end
def description=(desc)

View file

@ -27,5 +27,14 @@
text</pre></td>
<td>prefix text with at least <tt>&nbsp;&nbsp;&nbsp;3 spaces</tt></td>
</tr>
<% if defined?(allow_images) && allow_images %>
<tr>
<td>(inline image)</td>
<td><tt>![alt text](http://example.com/image.jpg)</tt> (only allowed in
story text</td>
</tr>
<% end %>
</table>
</div>

View file

@ -32,7 +32,8 @@
<div style="clear: both;"></div>
<%= render :partial => "global/markdownhelp" %>
<%= render :partial => "global/markdownhelp",
:locals => { :allow_images => true } %>
</div>
</div>
<% end %>

View file

@ -85,7 +85,8 @@
<div style="clear: both;"></div>
<%= render :partial => "global/markdownhelp" %>
<%= render :partial => "global/markdownhelp",
:locals => { :allow_images => true } %>
</div>
</div>
<% end %>

View file

@ -1,10 +1,11 @@
class Markdowner
def self.to_html(text)
def self.to_html(text, allow_images = false)
if text.blank?
return ""
else
html = RDiscount.new(text.to_s, :smart, :autolink, :safelink,
:filter_styles, :filter_html, :no_image).to_html
html = RDiscount.new(text.to_s, *[ :smart, :autolink, :safelink,
:filter_styles, :filter_html ] + (allow_images ? [] : [ :no_image ])).
to_html
# change <h1> headings to just emphasis tags
html.gsub!(/<(\/)?h(\d)>/) {|_| "<#{$1}strong>" }