Skip to content

Commit

Permalink
RDoc --pipe with markdown output is spec-compliant
Browse files Browse the repository at this point in the history
The Markdown specification states that ` should have <pre><code> in it,
but this was not followed.

Now, in pipe mode, RDoc HTML output will contain markdown-compliant
verbatim sections.
  • Loading branch information
drbrain committed Mar 22, 2013
1 parent ceb81dd commit 71da58e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions History.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Fixed `rdoc --ri-site`. Bug #193 by Michal Papis.
* RDoc no longer attempts to parse binary files. Bug #189 by postmodern,
Bug #190 by Christoffer Lervåg, Bug #195 by Aaron Patterson
* `rdoc --pipe` output now contains <code></code> for markdown compliance.

=== 4.0.0 / 2013-02-24

Expand Down
31 changes: 19 additions & 12 deletions lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,26 @@ def accept_paragraph paragraph
def accept_verbatim verbatim
text = verbatim.text.rstrip

@res << if verbatim.ruby? or parseable? text then
begin
tokens = RDoc::RubyLex.tokenize text, @options

html = RDoc::TokenStream.to_html tokens

"\n<pre class=\"ruby\">#{html}</pre>\n"
rescue RDoc::RubyLex::Error
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
klass = nil

content = if verbatim.ruby? or parseable? text then
begin
tokens = RDoc::RubyLex.tokenize text, @options
klass = ' class="ruby"'

RDoc::TokenStream.to_html tokens
rescue RDoc::RubyLex::Error
CGI.escapeHTML text
end
else
CGI.escapeHTML text
end
else
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
end

if @options.pipe then
@res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
else
@res << "\n<pre#{klass}>#{content}</pre>\n"
end
end

##
Expand Down
18 changes: 18 additions & 0 deletions test/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,24 @@ def test_accept_verbatim_parseable_error
assert_equal expected, @to.res.join
end

def test_accept_verbatim_pipe
@options.pipe = true

verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby

@to.start_accepting
@to.accept_verbatim verb

expected = <<-EXPECTED
<pre><code>1 + 1
</code></pre>
EXPECTED

assert_equal expected, @to.res.join
end

def test_accept_verbatim_ruby
verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby
Expand Down

0 comments on commit 71da58e

Please sign in to comment.