method
markup_code
v1_9_3_125 -
Show latest stable
- Class:
RDoc::AnyMethod
markup_code()public
Turns the method’s token stream into HTML.
Prepends line numbers if add_line_numbers is true.
# File lib/rdoc/generator/markup.rb, line 111
def markup_code
return '' unless @token_stream
src = ""
@token_stream.each do |t|
next unless t
style = case t
when RDoc::RubyToken::TkCONSTANT then 'ruby-constant'
when RDoc::RubyToken::TkKW then 'ruby-keyword'
when RDoc::RubyToken::TkIVAR then 'ruby-ivar'
when RDoc::RubyToken::TkOp then 'ruby-operator'
when RDoc::RubyToken::TkId then 'ruby-identifier'
when RDoc::RubyToken::TkNode then 'ruby-node'
when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
when RDoc::RubyToken::TkSTRING then 'ruby-string'
when RDoc::RubyToken::TkVal then 'ruby-value'
end
text = CGI.escapeHTML t.text
if style then
src << "<span class=\"#{style}\">#{text}</span>"
else
src << text
end
end
# dedent the source
indent = src.length
lines = src.lines.to_a
lines.shift if src =~ /\A.*#\ *File/ # remove '# File' comment
lines.each do |line|
if line =~ /^ *(?=\S)/
n = $&.length
indent = n if n < indent
break if n == 0
end
end
src.gsub!(/^#{' ' * indent}/, '') if indent > 0
add_line_numbers(src) if self.class.add_line_numbers
src
end Related methods
- Instance methods
- add_alias
- add_line_numbers
- aref_prefix
- arglists
- markup_code
- marshal_dump
- marshal_load
- name
- param_list
- param_seq
- Class methods
- new