Skip to content

Commit 9de83f6

Browse files
Fix a warning when the line number option is active.
1 parent 0d81416 commit 9de83f6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/rdoc/generator.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,18 @@ def add_line_numbers(src)
10431043
first = $1.to_i - 1
10441044
last = first + src.count("\n")
10451045
size = last.to_s.length
1046-
real_fmt = "%#{size}d: "
1047-
fmt = " " * (size+2)
1046+
fmt = "%#{size}d: "
1047+
is_first_line = true
1048+
line_num = first
10481049
src.gsub!(/^/) do
1049-
res = sprintf(fmt, first)
1050-
first += 1
1051-
fmt = real_fmt
1050+
if is_first_line then
1051+
is_first_line = false
1052+
res = " " * (size+2)
1053+
else
1054+
res = sprintf(fmt, line_num)
1055+
end
1056+
1057+
line_num += 1
10521058
res
10531059
end
10541060
end

0 commit comments

Comments
 (0)