Skip to content

Commit 71da58e

Browse files
committed
RDoc --pipe with markdown output is spec-compliant
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.
1 parent ceb81dd commit 71da58e

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

History.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Fixed `rdoc --ri-site`. Bug #193 by Michal Papis.
1818
* RDoc no longer attempts to parse binary files. Bug #189 by postmodern,
1919
Bug #190 by Christoffer Lervåg, Bug #195 by Aaron Patterson
20+
* `rdoc --pipe` output now contains <code></code> for markdown compliance.
2021

2122
=== 4.0.0 / 2013-02-24
2223

lib/rdoc/markup/to_html.rb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,26 @@ def accept_paragraph paragraph
186186
def accept_verbatim verbatim
187187
text = verbatim.text.rstrip
188188

189-
@res << if verbatim.ruby? or parseable? text then
190-
begin
191-
tokens = RDoc::RubyLex.tokenize text, @options
192-
193-
html = RDoc::TokenStream.to_html tokens
194-
195-
"\n<pre class=\"ruby\">#{html}</pre>\n"
196-
rescue RDoc::RubyLex::Error
197-
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
189+
klass = nil
190+
191+
content = if verbatim.ruby? or parseable? text then
192+
begin
193+
tokens = RDoc::RubyLex.tokenize text, @options
194+
klass = ' class="ruby"'
195+
196+
RDoc::TokenStream.to_html tokens
197+
rescue RDoc::RubyLex::Error
198+
CGI.escapeHTML text
199+
end
200+
else
201+
CGI.escapeHTML text
198202
end
199-
else
200-
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
201-
end
203+
204+
if @options.pipe then
205+
@res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
206+
else
207+
@res << "\n<pre#{klass}>#{content}</pre>\n"
208+
end
202209
end
203210

204211
##

test/test_rdoc_markup_to_html.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,24 @@ def test_accept_verbatim_parseable_error
422422
assert_equal expected, @to.res.join
423423
end
424424

425+
def test_accept_verbatim_pipe
426+
@options.pipe = true
427+
428+
verb = @RM::Verbatim.new("1 + 1\n")
429+
verb.format = :ruby
430+
431+
@to.start_accepting
432+
@to.accept_verbatim verb
433+
434+
expected = <<-EXPECTED
435+
436+
<pre><code>1 + 1
437+
</code></pre>
438+
EXPECTED
439+
440+
assert_equal expected, @to.res.join
441+
end
442+
425443
def test_accept_verbatim_ruby
426444
verb = @RM::Verbatim.new("1 + 1\n")
427445
verb.format = :ruby

0 commit comments

Comments
 (0)