Permalink
Browse files

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

  • Loading branch information...
1 parent cb5e05c commit b7e5447c1d9af935943c18677ccfb7f66681eadb @jcs jcs committed Sep 17, 2012
View
2 app/models/story.rb
@@ -251,7 +251,7 @@ def calculated_hotness
end
def generated_markeddown_description
- Markdowner.to_html(self.description)
+ Markdowner.to_html(self.description, allow_images = true)
end
def description=(desc)
View
9 app/views/global/_markdownhelp.html.erb
@@ -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
3 app/views/stories/edit.html.erb
@@ -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
3 app/views/stories/new.html.erb
@@ -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
7 extras/markdowner.rb
@@ -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>" }

0 comments on commit b7e5447

Please sign in to comment.