Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/html2markdown/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ def wrap_node(node,contents=nil)
when 'li'
result << "*#{contents}\n"
when 'blockquote'
contents.split('\n').each do |part|
result << ">#{contents}\n"
contents.split("\n").each do |part|
if not part.strip.empty?
result << ">#{part}\n\n"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why double \n\n?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reference from Daring Fireball:

> This is a blockquote.
> 
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote
<blockquote>
    <p>This is a blockquote.</p>

    <p>This is the second paragraph in the blockquote.</p>

    <h2>This is an H2 in a blockquote</h2>
</blockquote>

Any ideas?

end
end
when 'strong'
result << "**#{contents}**\n"
Expand Down
18 changes: 14 additions & 4 deletions spec/cases/html_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
<font face="微软雅黑 "><font size="3"><strong>DIY的手绘行程图</strong></font></font><br>
<span style="position: absolute; display: none" id="attach_1254048" onmouseover="showMenu({'ctrlid':this.id,'pos':'13'})"><img src="images/go2eu/attachimg.gif" border="0"></span>
<img src="http://att.qyer.com/day_111228/1112282241c0deb3a69dcd9cf5.jpg" file="http://att.qyer.com/day_111228/1112282241c0deb3a69dcd9cf5.jpg" width="700" class="zoom" onclick="zoom(this, this.src)" id="aimg_1254048" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" alt="55105222201110032253301023057594630_006.jpg">
<div class="t_attach" id="aimg_1254048_menu" style="position: absolute; display: none">
<div class="t_attach" id="aimg_1254048_menu" style="position: absolute; display: none">
<a href="attachment.php?aid=MTI1NDA0OHxkYmZjODBmY3wxMzMyOTIzMTI4fGM0OTVjaUtKdjEveHl3OW1XSUFScll0MGtwWXFHRlNJUDV4S2ppbFMwU0p5TGNB&amp;nothumb=yes" title="55105222201110032253301023057594630_006.jpg" target="_blank"><strong>下载</strong></a> (247.14 KB)<br>
<div class="t_smallfont">2011-12-28 22:41</div>
</div>
<br>
<br>
<span style="position: absolute; display: none" id="attach_1254049" onmouseover="showMenu({'ctrlid':this.id,'pos':'13'})"><img src="images/go2eu/attachimg.gif" border="0"></span>
<img src="http://att.qyer.com/day_111228/1112282241a7c6f2711722bc9b.jpg" file="http://att.qyer.com/day_111228/1112282241a7c6f2711722bc9b.jpg" width="700" class="zoom" onclick="zoom(this, this.src)" id="aimg_1254049" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" alt="55105222201110032253301023057594630_007.jpg">
<div class="t_attach" id="aimg_1254049_menu" style="position: absolute; z-index: 301; opacity: 1; left: 309px; top: 736px; display: none; ">
<div class="t_attach" id="aimg_1254049_menu" style="position: absolute; z-index: 301; opacity: 1; left: 309px; top: 736px; display: none; ">
<a href="attachment.php?aid=MTI1NDA0OXxhYTE5MTBiMHwxMzMyOTIzMTI4fGM0OTVjaUtKdjEveHl3OW1XSUFScll0MGtwWXFHRlNJUDV4S2ppbFMwU0p5TGNB&amp;nothumb=yes" title="55105222201110032253301023057594630_007.jpg" target="_blank"><strong>下载</strong></a> (241.74 KB)<br>
<div class="t_smallfont">2011-12-28 22:41</div>
</div>
Expand All @@ -68,9 +68,9 @@
if node['src'].end_with? 'gif'
''
elsif node['src'].start_with? 'http'
"![#{node['alt']}](#{node['src']} =300x)"
"![#{node['alt']}](#{node['src']} =300x)"
else
"![#{node['alt']}](http://bbs.qyer.com/#{node['src']} =300x)"
"![#{node['alt']}](http://bbs.qyer.com/#{node['src']} =300x)"
end
end
markdown = page.to_markdown page.contents
Expand All @@ -92,4 +92,14 @@
p.markdown!.should be_include('strong text')
end

it "parses multi-paragraph blockquotes" do
p = HTMLPage.new :contents => <<-EOD
<blockquote>
<p>First paragraph</p>
<p>Second paragraph</p>
</blockquote>
EOD
p.markdown.should == ">First paragraph\n\n>Second paragraph"
end

end