Skip to content

Commit

Permalink
If hardwrap is enabled, replace newlines with br tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbyron committed Mar 12, 2012
1 parent 90c5cb8 commit abd3cf0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/md_emoji/render.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module MdEmoji
class Render < Redcarpet::Render::HTML
def initialize(options={})
@options = options
super options
end

def paragraph(text)
text.gsub!("\n", "<br>\n") if @options[:hard_wrap]

"<p>#{replace_emoji(text)}</p>\n"
end

Expand Down
10 changes: 6 additions & 4 deletions test/md_emoji_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,23 @@ def setup
end

test "works with no_styles enabled" do
@markdown = Redcarpet::Markdown.new(MdEmoji::Render, :no_styles => true)
@markdown = Redcarpet::Markdown.new(MdEmoji::Render.new(:no_styles => true))

text = ":wink2:"
text = ":wink2: <a style='color: red;'></a>"
parsed_text = @markdown.render(text)

assert_emoji 'wink2', parsed_text
end

test "works with hard_wrap enabled" do
@markdown = Redcarpet::Markdown.new(MdEmoji::Render, :hard_wrap => true)
@markdown = Redcarpet::Markdown.new(MdEmoji::Render.new(:hard_wrap => true))

text = ":wink2:"
text = ":wink2:\nline"
parsed_text = @markdown.render(text)

assert_emoji 'wink2', parsed_text
assert parsed_text.include?(%{<br>}),
"<br> not present in parsed text: #{parsed_text}"
end

test "does not render emoji in codeblocks" do
Expand Down

0 comments on commit abd3cf0

Please sign in to comment.