class RDoc::Markup::PreProcess

def handle_directive prefix, directive, param, code_object = nil,

def handle_directive prefix, directive, param, code_object = nil,
                     encoding = nil, line = nil
  blankline = "#{prefix.strip}\n"
  directive = directive.downcase
  case directive
  when 'arg', 'args' then
    return "#{prefix}:#{directive}: #{param}\n" unless code_object && code_object.kind_of?(RDoc::AnyMethod)
    code_object.params = param
    blankline
  when 'category' then
    if RDoc::Context === code_object then
      section = code_object.add_section param
      code_object.temporary_section = section
    elsif RDoc::AnyMethod === code_object then
      code_object.section_title = param
    end
    blankline # ignore category if we're not on an RDoc::Context
  when 'doc' then
    return blankline unless code_object
    code_object.document_self = true
    code_object.force_documentation = true
    blankline
  when 'enddoc' then
    return blankline unless code_object
    code_object.done_documenting = true
    blankline
  when 'include' then
    filename = param.split(' ', 2).first
    include_file filename, prefix, encoding
  when 'main' then
    @options.main_page = param if @options.respond_to? :main_page
    warn <<~MSG
      The :main: directive is deprecated and will be removed in RDoc 7.
      You can use these options to specify the initial page displayed instead:
      - `--main=#{param}` via the command line
      - `rdoc.main = "#{param}"` if you use `RDoc::Task`
      - `main_page: #{param}` in your `.rdoc_options` file
    MSG
    blankline
  when 'nodoc' then
    return blankline unless code_object
    code_object.document_self = nil # notify nodoc
    code_object.document_children = param !~ /all/i
    blankline
  when 'notnew', 'not_new', 'not-new' then
    return blankline unless RDoc::AnyMethod === code_object
    code_object.dont_rename_initialize = true
    blankline
  when 'startdoc' then
    return blankline unless code_object
    code_object.start_doc
    code_object.force_documentation = true
    blankline
  when 'stopdoc' then
    return blankline unless code_object
    code_object.stop_doc
    blankline
  when 'title' then
    @options.default_title = param if @options.respond_to? :default_title=
    warn <<~MSG
      The :title: directive is deprecated and will be removed in RDoc 7.
      You can use these options to specify the title displayed instead:
      - `--title=#{param}` via the command line
      - `rdoc.title = "#{param}"` if you use `RDoc::Task`
      - `title: #{param}` in your `.rdoc_options` file
    MSG
    blankline
  when 'yield', 'yields' then
    return blankline unless code_object
    # remove parameter &block
    code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
    code_object.block_params = param || ''
    blankline
  else
    result = yield directive, param, line if block_given?
    case result
    when nil then
      code_object.metadata[directive] = param if code_object
      if RDoc::Markup::PreProcess.registered.include? directive then
        handler = RDoc::Markup::PreProcess.registered[directive]
        result = handler.call directive, param if handler
      else
        result = "#{prefix}:#{directive}: #{param}\n"
      end
    when false then
      result = "#{prefix}:#{directive}: #{param}\n"
    end
    result
  end
end