@@ -97,15 +97,18 @@ def initialize(input_file_name, include_path)
9797 # RDoc::CodeObject#metadata for details.
9898
9999 def handle text , code_object = nil , &block
100+ first_line = 1
100101 if RDoc ::Comment === text then
101102 comment = text
102103 text = text . text
104+ first_line = comment . line || 1
103105 end
104106
105107 # regexp helper (square brackets for optional)
106108 # $1 $2 $3 $4 $5
107109 # [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 |$)/
109112 # skip something like ':toto::'
110113 next $& if $4. empty? and $5 and $5[ 0 , 1 ] == ':'
111114
@@ -119,9 +122,8 @@ def handle text, code_object = nil, &block
119122 comment . format = $5. downcase
120123 next "#{ $1. strip } \n "
121124 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
125127
126128 if comment then
127129 comment . text = text
@@ -148,7 +150,7 @@ def handle text, code_object = nil, &block
148150 # When 1.8.7 support is ditched prefix can be defaulted to ''
149151
150152 def handle_directive prefix , directive , param , code_object = nil ,
151- encoding = nil
153+ encoding = nil , line = nil
152154 blankline = "#{ prefix . strip } \n "
153155 directive = directive . downcase
154156
@@ -220,11 +222,11 @@ def handle_directive prefix, directive, param, code_object = nil,
220222 # remove parameter &block
221223 code_object . params = code_object . params . sub ( /,?\s *&\w +/ , '' ) if code_object . params
222224
223- code_object . block_params = param
225+ code_object . block_params = param || ''
224226
225227 blankline
226228 else
227- result = yield directive , param if block_given?
229+ result = yield directive , param , line if block_given?
228230
229231 case result
230232 when nil then
0 commit comments