Skip to content

Commit

Permalink
don't output newlines in the end if there are no reference-style links
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Jul 21, 2009
1 parent b35a69b commit 4027918
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/remark.rb
Expand Up @@ -11,7 +11,7 @@ def initialize(source, options = {})
def to_markdown
parent = scope
collect_ignored_elements(parent)
remark_block(parent) + (inline_links?? '' : "\n\n\n" + output_reference_links)
remark_block(parent) + (inline_links? || @links.empty?? '' : "\n\n\n" + output_reference_links)
end

def scope
Expand Down
29 changes: 16 additions & 13 deletions spec/remark_spec.rb
Expand Up @@ -135,19 +135,6 @@ def remark(source, options = {})
remark("<p>I <a href='#'>am <em>fine</em></a></p>").should == "I [am _fine_](#)"
end

it "should support hyperlinks" do
remark("<p>Click <a href='http://mislav.uniqpath.com'>here</a></p>").should ==
"Click [here](http://mislav.uniqpath.com)"
remark("<a href='/foo' title='bar'>baz</a>").should == '[baz](/foo "bar")'
end

it "should have reference-style hyperlinks" do
remark("<p>Click <a href='foo' title='mooslav'>here</a> and <a href='bar'>there</a></p>", :inline_links => false).should ==
"Click [here][1] and [there][2]\n\n\n[1]: foo \"mooslav\"\n[2]: bar"
remark("<p>Click <a href='foo'>here</a> and <a href='foo'>there</a></p>", :inline_links => false).should ==
"Click [here][1] and [there][1]\n\n\n[1]: foo"
end

it "should support image tags" do
remark("<img src='moo.jpg' alt='cow'>").should == '![cow](moo.jpg)'
remark("<img src='moo.jpg' alt='cow' width='16'>").should == '<img src="moo.jpg" alt="cow" width="16" />'
Expand All @@ -166,6 +153,22 @@ def remark(source, options = {})
end
end

describe "hyperlinks" do
it "should support hyperlinks" do
remark("<p>Click <a href='http://mislav.uniqpath.com'>here</a></p>").should ==
"Click [here](http://mislav.uniqpath.com)"
remark("<a href='/foo' title='bar'>baz</a>").should == '[baz](/foo "bar")'
end

it "should have reference-style hyperlinks" do
remark("<p>Click <a href='foo' title='mooslav'>here</a> and <a href='bar'>there</a></p>", :inline_links => false).should ==
"Click [here][1] and [there][2]\n\n\n[1]: foo \"mooslav\"\n[2]: bar"
remark("<p>Click <a href='foo'>here</a> and <a href='foo'>there</a></p>", :inline_links => false).should ==
"Click [here][1] and [there][1]\n\n\n[1]: foo"
remark("", :inline_links => false).should == ""
end
end

it "should support blockquotes" do
remark("<blockquote>Cogito, ergo sum</blockquote>").should == '> Cogito, ergo sum'
remark("<blockquote><p>I think</p><p>therefore I am</p></blockquote>").should == "> I think\n> \n> therefore I am"
Expand Down

0 comments on commit 4027918

Please sign in to comment.