Skip to content

Commit 8cf49cb

Browse files
committed
Add "Example" label to example code blocks
The label should help users distinguish example code blocks from other code blocks, such as method source code. It's only applied to Ruby code examples.
1 parent 403c0de commit 8cf49cb

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

Diff for: lib/rdoc/generator/template/darkfish/css/rdoc.css

+18
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,24 @@ main .method-source-code.active-menu {
597597
max-height: 100vh;
598598
}
599599

600+
main .method-example::before {
601+
content: "Example";
602+
color: var(--secondary-color);
603+
border-bottom: 1px solid var(--border-color);
604+
display: block;
605+
padding: 10px 0;
606+
font-size: 0.9em;
607+
margin-bottom: 10px;
608+
}
609+
610+
main .method-example {
611+
margin: 0;
612+
padding: 0px 16px 16px 16px;
613+
overflow-x: auto;
614+
border-radius: 4px;
615+
border-color: var(--border-color);
616+
}
617+
600618
main .method-description .method-calls-super {
601619
color: var(--text-color);
602620
font-weight: bold;

Diff for: lib/rdoc/markup/to_html.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def accept_verbatim verbatim
221221
content = if verbatim.ruby? or parseable? text then
222222
begin
223223
tokens = RDoc::Parser::RipperStateLex.parse text
224-
klass = ' class="ruby"'
224+
klass = ' class="ruby method-example"'
225225

226226
result = RDoc::TokenStream.to_html tokens
227227
result = result + "\n" unless "\n" == result[-1]

Diff for: test/rdoc/test_rdoc_markup_to_html.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def accept_rule
293293
end
294294

295295
def accept_verbatim
296-
assert_equal "\n<pre class=\"ruby\"><span class=\"ruby-identifier\">hi</span>\n <span class=\"ruby-identifier\">world</span>\n</pre>\n", @to.res.join
296+
assert_equal "\n<pre class=\"ruby method-example\"><span class=\"ruby-identifier\">hi</span>\n <span class=\"ruby-identifier\">world</span>\n</pre>\n", @to.res.join
297297
end
298298

299299
def end_accepting
@@ -459,7 +459,7 @@ def test_accept_verbatim_parseable
459459

460460
expected = <<-EXPECTED
461461
462-
<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">C</span>
462+
<pre class="ruby method-example"><span class="ruby-keyword">class</span> <span class="ruby-constant">C</span>
463463
<span class="ruby-keyword">end</span>
464464
</pre>
465465
EXPECTED
@@ -491,7 +491,7 @@ def test_accept_verbatim_nl_after_backslash
491491

492492
expected = <<-EXPECTED
493493
494-
<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">first_flag_var</span> <span class="ruby-keyword">and</span> \\
494+
<pre class="ruby method-example"><span class="ruby-identifier">a</span> = <span class="ruby-value">1</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">first_flag_var</span> <span class="ruby-keyword">and</span> \\
495495
<span class="ruby-identifier">this_is_flag_var</span>
496496
</pre>
497497
EXPECTED
@@ -549,7 +549,7 @@ def bar
549549

550550
expected = <<-'EXPECTED'
551551
552-
<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
552+
<pre class="ruby method-example"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
553553
[
554554
<span class="ruby-string">&#39;\\&#39;</span>,
555555
<span class="ruby-string">&#39;\&#39;&#39;</span>,
@@ -599,7 +599,7 @@ def bar
599599

600600
expected = <<-'EXPECTED'
601601
602-
<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
602+
<pre class="ruby method-example"><span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">foo</span>
603603
[
604604
<span class="ruby-string">`\\`</span>,
605605
<span class="ruby-string">`\&#39;\&quot;\``</span>,
@@ -626,7 +626,7 @@ def test_accept_verbatim_ruby
626626

627627
expected = <<-EXPECTED
628628
629-
<pre class="ruby"><span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
629+
<pre class="ruby method-example"><span class="ruby-value">1</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
630630
</pre>
631631
EXPECTED
632632

@@ -645,7 +645,7 @@ def test_accept_verbatim_redefinable_operators
645645

646646
expected = <<-EXPECTED
647647
648-
<pre class="ruby">
648+
<pre class="ruby method-example">
649649
EXPECTED
650650
expected = expected.rstrip
651651

@@ -880,8 +880,8 @@ def test_list_verbatim_2
880880
<ul><li>
881881
<p>one</p>
882882
883-
<pre class=\"ruby\"><span class=\"ruby-identifier\">verb1</span>
884-
<span class=\"ruby-identifier\">verb2</span>
883+
<pre class="ruby method-example"><span class="ruby-identifier">verb1</span>
884+
<span class="ruby-identifier">verb2</span>
885885
</pre>
886886
</li><li>
887887
<p>two</p>

Diff for: test/rdoc/test_rdoc_markup_to_html_snippet.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def accept_rule
310310
end
311311

312312
def accept_verbatim
313-
assert_equal "\n<pre class=\"ruby\"><span class=\"ruby-identifier\">hi</span>\n <span class=\"ruby-identifier\">world</span>\n</pre>\n", @to.res.join
313+
assert_equal "\n<pre class=\"ruby method-example\"><span class=\"ruby-identifier\">hi</span>\n <span class=\"ruby-identifier\">world</span>\n</pre>\n", @to.res.join
314314
assert_equal 10, @to.characters
315315
end
316316

@@ -404,7 +404,7 @@ def test_accept_verbatim_ruby
404404

405405
expected = <<-EXPECTED
406406
407-
<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">C</span>
407+
<pre class="ruby method-example"><span class="ruby-keyword">class</span> <span class="ruby-constant">C</span>
408408
<span class="ruby-keyword">end</span>
409409
</pre>
410410
EXPECTED
@@ -586,8 +586,8 @@ def test_convert_limit_verbatim_multiline
586586
expected = <<-EXPECTED
587587
<p>Look for directives in a normal comment block:
588588
589-
<pre class=\"ruby\"><span class=\"ruby-comment\"># :stopdoc:</span>
590-
<span class=\"ruby-comment\">#{inner}</span>
589+
<pre class="ruby method-example"><span class="ruby-comment"># :stopdoc:</span>
590+
<span class="ruby-comment">#{inner}</span>
591591
</pre>
592592
EXPECTED
593593

@@ -664,8 +664,8 @@ def test_list_verbatim_2
664664
expected = <<-EXPECTED
665665
<p>one
666666
667-
<pre class=\"ruby\"><span class=\"ruby-identifier\">verb1</span>
668-
<span class=\"ruby-identifier\">verb2</span>
667+
<pre class="ruby method-example"><span class="ruby-identifier">verb1</span>
668+
<span class="ruby-identifier">verb2</span>
669669
</pre>
670670
<p>two
671671

Diff for: test/rdoc/test_rdoc_parser_ruby.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2984,7 +2984,7 @@ def blah
29842984
expected = <<EXPECTED
29852985
<p>doc
29862986
2987-
<pre class="ruby"><span class="ruby-comment">=begin
2987+
<pre class="ruby method-example"><span class="ruby-comment">=begin
29882988
test embdoc
29892989
=end</span>
29902990
</pre>

0 commit comments

Comments
 (0)