@@ -97,15 +97,18 @@ def initialize(input_file_name, include_path)
97
97
# RDoc::CodeObject#metadata for details.
98
98
99
99
def handle text , code_object = nil , &block
100
+ first_line = 1
100
101
if RDoc ::Comment === text then
101
102
comment = text
102
103
text = text . text
104
+ first_line = comment . line || 1
103
105
end
104
106
105
107
# regexp helper (square brackets for optional)
106
108
# $1 $2 $3 $4 $5
107
109
# [prefix][\]:directive:[spaces][param]newline
108
- text = text . gsub ( /^([ \t ]*(?:#|\/ ?\* )?[ \t ]*)(\\ ?):(\w +):([ \t ]*)(.+)?(\r ?\n |$)/ ) do
110
+ text = text . lines . map . with_index ( first_line ) do |line , num |
111
+ next line unless line =~ /\A ([ \t ]*(?:#|\/ ?\* )?[ \t ]*)(\\ ?):([\w -]+):([ \t ]*)(.+)?(\r ?\n |$)/
109
112
# skip something like ':toto::'
110
113
next $& if $4. empty? and $5 and $5[ 0 , 1 ] == ':'
111
114
@@ -119,9 +122,8 @@ def handle text, code_object = nil, &block
119
122
comment . format = $5. downcase
120
123
next "#{ $1. strip } \n "
121
124
end
122
-
123
- handle_directive $1, $3, $5, code_object , text . encoding , &block
124
- end
125
+ handle_directive $1, $3, $5, code_object , text . encoding , num , &block
126
+ end . join
125
127
126
128
if comment then
127
129
comment . text = text
@@ -148,7 +150,7 @@ def handle text, code_object = nil, &block
148
150
# When 1.8.7 support is ditched prefix can be defaulted to ''
149
151
150
152
def handle_directive prefix , directive , param , code_object = nil ,
151
- encoding = nil
153
+ encoding = nil , line = nil
152
154
blankline = "#{ prefix . strip } \n "
153
155
directive = directive . downcase
154
156
@@ -220,11 +222,11 @@ def handle_directive prefix, directive, param, code_object = nil,
220
222
# remove parameter &block
221
223
code_object . params = code_object . params . sub ( /,?\s *&\w +/ , '' ) if code_object . params
222
224
223
- code_object . block_params = param
225
+ code_object . block_params = param || ''
224
226
225
227
blankline
226
228
else
227
- result = yield directive , param if block_given?
229
+ result = yield directive , param , line if block_given?
228
230
229
231
case result
230
232
when nil then
0 commit comments