diff options
author | nicholas a. evans <[email protected]> | 2024-12-08 05:43:43 -0500 |
---|---|---|
committer | git <[email protected]> | 2024-12-08 10:43:47 +0000 |
commit | dd43af3be7eddb832c77ef367456fa023fed7d7a (patch) | |
tree | 9f1f4b18eb420b94b7baf7f433d8da8cfa2b1850 | |
parent | bd831bcca534955533d9135d8c2f22d7ae5b9aa8 (diff) |
[ruby/rdoc] Use distinct styles for note lists and label lists
(https://github.com/ruby/rdoc/pull/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
https://github.com/ruby/rdoc/commit/9e69ea6d75
-rw-r--r-- | lib/rdoc/generator/template/darkfish/css/rdoc.css | 22 | ||||
-rw-r--r-- | lib/rdoc/markup/to_html.rb | 2 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_markup_to_html.rb | 12 |
3 files changed, 26 insertions, 10 deletions
diff --git a/lib/rdoc/generator/template/darkfish/css/rdoc.css b/lib/rdoc/generator/template/darkfish/css/rdoc.css index 82c1e4baf6..69b1d08577 100644 --- a/lib/rdoc/generator/template/darkfish/css/rdoc.css +++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css @@ -469,14 +469,30 @@ main dl { } main dt { - margin-bottom: 0.5em; + line-height: 1.5; /* matches `main p` */ + font-weight: bold; +} + +main dl.note-list dt { margin-right: 1em; float: left; - font-weight: bold; +} + +main dl.note-list dt:has(+ dt) { + margin-right: 0.25em; +} + +main dl.note-list dt:has(+ dt)::after { + content: ', '; + font-weight: normal; } main dd { - margin: 0 1em 1em 0.5em; + margin: 0 0 1em 1em; +} + +main dd p:first-child { + margin-top: 0; } /* Headers within Main */ diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 91cadf9d16..dd37bf9eb3 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -407,7 +407,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter "<li>" when :LABEL, :NOTE then Array(list_item.label).map do |label| - "<dt>#{to_html label}\n" + "<dt>#{to_html label}</dt>\n" end.join << "<dd>" else raise RDoc::Error, "Invalid list type: #{list_type.inspect}" diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index e3affa533c..225598a651 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -146,7 +146,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def accept_list_item_start_label - assert_equal "<dl class=\"rdoc-list label-list\"><dt>cat\n<dd>", @to.res.join + assert_equal "<dl class=\"rdoc-list label-list\"><dt>cat</dt>\n<dd>", @to.res.join end def accept_list_item_start_lalpha @@ -154,13 +154,13 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase end def accept_list_item_start_note - assert_equal "<dl class=\"rdoc-list note-list\"><dt>cat\n<dd>", + assert_equal "<dl class=\"rdoc-list note-list\"><dt>cat</dt>\n<dd>", @to.res.join end def accept_list_item_start_note_2 expected = <<-EXPECTED -<dl class="rdoc-list note-list"><dt><code>teletype</code> +<dl class="rdoc-list note-list"><dt><code>teletype</code></dt> <dd> <p>teletype description</p> </dd></dl> @@ -171,7 +171,7 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase def accept_list_item_start_note_multi_description expected = <<-EXPECTED -<dl class="rdoc-list note-list"><dt>label +<dl class="rdoc-list note-list"><dt>label</dt> <dd> <p>description one</p> </dd><dd> @@ -184,8 +184,8 @@ class TestRDocMarkupToHtml < RDoc::Markup::FormatterTestCase def accept_list_item_start_note_multi_label expected = <<-EXPECTED -<dl class="rdoc-list note-list"><dt>one -<dt>two +<dl class="rdoc-list note-list"><dt>one</dt> +<dt>two</dt> <dd> <p>two headers</p> </dd></dl> |