Skip to content

Commit 9e69ea6

Browse files
authored
Use distinct styles for note lists and label lists (#1209)
* Use the original `label` description list style As a default for all description lists, the original "label" style is more readable. This is slightly different from the original `label` dl though: * slightly increased left margin for `dd` (to 1em) * removed right margin on `dd` * removed `dt` bottom margin and `dd` top margin, to reduce the gap between the term and its description (to only the standard line-height gap). * Add closing tags for description list terms Without the closing tags, the dt elements contain whitespace after the text. This normally isn't a big deal, but does mess some things up, e.g: using `::after` with `content: ", "` in stylesheets. * Restore float:left style for note lists Unlike the original note list styles, this version sets the line-height for all `dt` elements to be the same as the `p` elements contained inside the `dd`, so that the second line has the same indentation as all subsequent lines. * Add commas between note list terms
1 parent 3f9897d commit 9e69ea6

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

lib/rdoc/generator/template/darkfish/css/rdoc.css

+19-3
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,30 @@ main dl {
469469
}
470470

471471
main dt {
472-
margin-bottom: 0.5em;
472+
line-height: 1.5; /* matches `main p` */
473+
font-weight: bold;
474+
}
475+
476+
main dl.note-list dt {
473477
margin-right: 1em;
474478
float: left;
475-
font-weight: bold;
479+
}
480+
481+
main dl.note-list dt:has(+ dt) {
482+
margin-right: 0.25em;
483+
}
484+
485+
main dl.note-list dt:has(+ dt)::after {
486+
content: ', ';
487+
font-weight: normal;
476488
}
477489

478490
main dd {
479-
margin: 0 1em 1em 0.5em;
491+
margin: 0 0 1em 1em;
492+
}
493+
494+
main dd p:first-child {
495+
margin-top: 0;
480496
}
481497

482498
/* Headers within Main */

lib/rdoc/markup/to_html.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def list_item_start(list_item, list_type)
407407
"<li>"
408408
when :LABEL, :NOTE then
409409
Array(list_item.label).map do |label|
410-
"<dt>#{to_html label}\n"
410+
"<dt>#{to_html label}</dt>\n"
411411
end.join << "<dd>"
412412
else
413413
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"

test/rdoc/test_rdoc_markup_to_html.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,21 @@ def accept_list_item_start_bullet
146146
end
147147

148148
def accept_list_item_start_label
149-
assert_equal "<dl class=\"rdoc-list label-list\"><dt>cat\n<dd>", @to.res.join
149+
assert_equal "<dl class=\"rdoc-list label-list\"><dt>cat</dt>\n<dd>", @to.res.join
150150
end
151151

152152
def accept_list_item_start_lalpha
153153
assert_equal "<ol style=\"list-style-type: lower-alpha\"><li>", @to.res.join
154154
end
155155

156156
def accept_list_item_start_note
157-
assert_equal "<dl class=\"rdoc-list note-list\"><dt>cat\n<dd>",
157+
assert_equal "<dl class=\"rdoc-list note-list\"><dt>cat</dt>\n<dd>",
158158
@to.res.join
159159
end
160160

161161
def accept_list_item_start_note_2
162162
expected = <<-EXPECTED
163-
<dl class="rdoc-list note-list"><dt><code>teletype</code>
163+
<dl class="rdoc-list note-list"><dt><code>teletype</code></dt>
164164
<dd>
165165
<p>teletype description</p>
166166
</dd></dl>
@@ -171,7 +171,7 @@ def accept_list_item_start_note_2
171171

172172
def accept_list_item_start_note_multi_description
173173
expected = <<-EXPECTED
174-
<dl class="rdoc-list note-list"><dt>label
174+
<dl class="rdoc-list note-list"><dt>label</dt>
175175
<dd>
176176
<p>description one</p>
177177
</dd><dd>
@@ -184,8 +184,8 @@ def accept_list_item_start_note_multi_description
184184

185185
def accept_list_item_start_note_multi_label
186186
expected = <<-EXPECTED
187-
<dl class="rdoc-list note-list"><dt>one
188-
<dt>two
187+
<dl class="rdoc-list note-list"><dt>one</dt>
188+
<dt>two</dt>
189189
<dd>
190190
<p>two headers</p>
191191
</dd></dl>

0 commit comments

Comments
 (0)