Skip to content

Commit

Permalink
allow embedded images in story text, but still not in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs committed Sep 17, 2012
1 parent cb5e05c commit b7e5447
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/story.rb
Expand Up @@ -251,7 +251,7 @@ def calculated_hotness
end end


def generated_markeddown_description def generated_markeddown_description
Markdowner.to_html(self.description) Markdowner.to_html(self.description, allow_images = true)
end end


def description=(desc) def description=(desc)
Expand Down
9 changes: 9 additions & 0 deletions app/views/global/_markdownhelp.html.erb
Expand Up @@ -27,5 +27,14 @@
text</pre></td> text</pre></td>
<td>prefix text with at least <tt>&nbsp;&nbsp;&nbsp;3 spaces</tt></td> <td>prefix text with at least <tt>&nbsp;&nbsp;&nbsp;3 spaces</tt></td>
</tr> </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> </table>
</div> </div>
3 changes: 2 additions & 1 deletion app/views/stories/edit.html.erb
Expand Up @@ -32,7 +32,8 @@


<div style="clear: both;"></div> <div style="clear: both;"></div>


<%= render :partial => "global/markdownhelp" %> <%= render :partial => "global/markdownhelp",
:locals => { :allow_images => true } %>
</div> </div>
</div> </div>
<% end %> <% end %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/stories/new.html.erb
Expand Up @@ -85,7 +85,8 @@


<div style="clear: both;"></div> <div style="clear: both;"></div>


<%= render :partial => "global/markdownhelp" %> <%= render :partial => "global/markdownhelp",
:locals => { :allow_images => true } %>
</div> </div>
</div> </div>
<% end %> <% end %>
Expand Down
7 changes: 4 additions & 3 deletions extras/markdowner.rb
@@ -1,10 +1,11 @@
class Markdowner class Markdowner
def self.to_html(text) def self.to_html(text, allow_images = false)
if text.blank? if text.blank?
return "" return ""
else else
html = RDiscount.new(text.to_s, :smart, :autolink, :safelink, html = RDiscount.new(text.to_s, *[ :smart, :autolink, :safelink,
:filter_styles, :filter_html, :no_image).to_html :filter_styles, :filter_html ] + (allow_images ? [] : [ :no_image ])).
to_html


# change <h1> headings to just emphasis tags # change <h1> headings to just emphasis tags
html.gsub!(/<(\/)?h(\d)>/) {|_| "<#{$1}strong>" } html.gsub!(/<(\/)?h(\d)>/) {|_| "<#{$1}strong>" }
Expand Down

0 comments on commit b7e5447

Please sign in to comment.