class RDoc::Context::Section

def extract_comment comment

def extract_comment comment
  case comment
  when nil
    RDoc::Comment.new ''
  when RDoc::Comment then
    if comment.text =~ /^#[ \t]*:section:.*\n/ then
      start = $`
      rest = $'
      comment.text = if start.empty? then
                       rest
                     else
                       rest.sub(/#{start.chomp}\Z/, '')
                     end
    end
    comment
  else
    raise TypeError, "unknown comment #{comment.inspect}"
  end
end