Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ToRdoc generating incorrect {label,name}-lists #1093

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/rdoc/markup/to_bs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ def accept_heading heading
@res << "\n"
end

##
# Prepares the visitor for consuming +list_item+

def accept_list_item_start list_item
type = @list_type.last

case type
when :NOTE, :LABEL then
bullets = Array(list_item.label).map do |label|
attributes(label).strip
end.join "\n"

bullets << ":\n" unless bullets.empty?

@prefix = ' ' * @indent
@indent += 2
@prefix << bullets + (' ' * @indent)
else
bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
@prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
width = bullet.length + 1
@indent += width
end
end

##
# Turns on or off regexp handling for +convert_string+

Expand Down
14 changes: 11 additions & 3 deletions lib/rdoc/markup/to_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@ def accept_list_item_start list_item

case type
when :NOTE, :LABEL then
bullets = Array(list_item.label).map do |label|
stripped_labels = Array(list_item.label).map do |label|
attributes(label).strip
end.join "\n"
end

bullets = case type
when :NOTE
stripped_labels.map { |b| "#{b}::" }
when :LABEL
stripped_labels.map { |b| "[#{b}]" }
end

bullets << ":\n" unless bullets.empty?
bullets = bullets.join("\n")
bullets << "\n" unless stripped_labels.empty?

@prefix = ' ' * @indent
@indent += 2
Expand Down
18 changes: 9 additions & 9 deletions test/rdoc/test_rdoc_markup_to_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def accept_list_item_end_bullet
end

def accept_list_item_end_label
assert_equal "cat:\n", @to.res.join
assert_equal "[cat]\n", @to.res.join
assert_equal 0, @to.indent, 'indent'
end

Expand All @@ -79,7 +79,7 @@ def accept_list_item_end_lalpha
end

def accept_list_item_end_note
assert_equal "cat:\n", @to.res.join
assert_equal "cat::\n", @to.res.join
assert_equal 0, @to.indent, 'indent'
end

Expand All @@ -100,7 +100,7 @@ def accept_list_item_start_bullet

def accept_list_item_start_label
assert_equal [""], @to.res
assert_equal "cat:\n ", @to.prefix
assert_equal "[cat]\n ", @to.prefix

assert_equal 2, @to.indent
end
Expand All @@ -115,7 +115,7 @@ def accept_list_item_start_lalpha

def accept_list_item_start_note
assert_equal [""], @to.res
assert_equal "cat:\n ", @to.prefix
assert_equal "cat::\n ", @to.prefix

assert_equal 2, @to.indent
end
Expand Down Expand Up @@ -243,16 +243,16 @@ def accept_heading_suppressed_crossref
end

def accept_list_item_start_note_2
assert_equal "<tt>teletype</tt>:\n teletype description\n\n", @to.res.join
assert_equal "<tt>teletype</tt>::\n teletype description\n\n", @to.res.join
end

def accept_list_item_start_note_multi_description
assert_equal "label:\n description one\n\n description two\n\n",
assert_equal "label::\n description one\n\n description two\n\n",
@to.res.join
end

def accept_list_item_start_note_multi_label
assert_equal "one\ntwo:\n two headers\n\n", @to.res.join
assert_equal "one::\ntwo::\n two headers\n\n", @to.res.join
end

def accept_paragraph_b
Expand Down Expand Up @@ -355,8 +355,8 @@ def test_convert_list_note
NOTE_LIST

expected = <<-EXPECTED
foo
bar:
foo::
bar::
hi

EXPECTED
Expand Down
Loading