[ruby/rdoc] Pull up handle_tab_width to RDoc::Parser
To share with the duplicate code in RDoc::Parser::Ruby#initialize. https://github.com/ruby/rdoc/commit/27829ac119
This commit is contained in:
parent
d055c44b0c
commit
1b67c58f41
@ -266,6 +266,23 @@ class RDoc::Parser
|
|||||||
autoload :RubyTools, "#{__dir__}/parser/ruby_tools"
|
autoload :RubyTools, "#{__dir__}/parser/ruby_tools"
|
||||||
autoload :Text, "#{__dir__}/parser/text"
|
autoload :Text, "#{__dir__}/parser/text"
|
||||||
|
|
||||||
|
##
|
||||||
|
# Normalizes tabs in +body+
|
||||||
|
|
||||||
|
def handle_tab_width(body)
|
||||||
|
if /\t/ =~ body
|
||||||
|
tab_width = @options.tab_width
|
||||||
|
body.split(/\n/).map do |line|
|
||||||
|
1 while line.gsub!(/\t+/) do
|
||||||
|
b, e = $~.offset(0)
|
||||||
|
' ' * (tab_width * (e-b) - b % tab_width)
|
||||||
|
end
|
||||||
|
line
|
||||||
|
end.join "\n"
|
||||||
|
else
|
||||||
|
body
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# simple must come first in order to show up last in the parsers list
|
# simple must come first in order to show up last in the parsers list
|
||||||
|
@ -1057,23 +1057,6 @@ class RDoc::Parser::C < RDoc::Parser
|
|||||||
@singleton_classes[sclass_var] = class_name
|
@singleton_classes[sclass_var] = class_name
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
|
||||||
# Normalizes tabs in +body+
|
|
||||||
|
|
||||||
def handle_tab_width(body)
|
|
||||||
if /\t/ =~ body
|
|
||||||
tab_width = @options.tab_width
|
|
||||||
body.split(/\n/).map do |line|
|
|
||||||
1 while line.gsub!(/\t+/) do
|
|
||||||
' ' * (tab_width * $&.length - $`.length % tab_width)
|
|
||||||
end && $~
|
|
||||||
line
|
|
||||||
end.join "\n"
|
|
||||||
else
|
|
||||||
body
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Loads the variable map with the given +name+ from the RDoc::Store, if
|
# Loads the variable map with the given +name+ from the RDoc::Store, if
|
||||||
# present.
|
# present.
|
||||||
|
@ -164,15 +164,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||||||
def initialize(top_level, file_name, content, options, stats)
|
def initialize(top_level, file_name, content, options, stats)
|
||||||
super
|
super
|
||||||
|
|
||||||
if /\t/ =~ content then
|
content = handle_tab_width(content)
|
||||||
tab_width = @options.tab_width
|
|
||||||
content = content.split(/\n/).map do |line|
|
|
||||||
1 while line.gsub!(/\t+/) {
|
|
||||||
' ' * (tab_width*$&.length - $`.length % tab_width)
|
|
||||||
} && $~
|
|
||||||
line
|
|
||||||
end.join("\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
@size = 0
|
@size = 0
|
||||||
@token_listeners = nil
|
@token_listeners = nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user