Sha256: a61fce67cbc40d22d14aa3c11ee3cb04ac523b363031b686b99189f9db0618a5

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

require 'rdoc/markup/formatter'
require 'rdoc/markup/fragments'
require 'rdoc/markup/inline'

require 'rdoc/markup'
require 'rdoc/markup/formatter'

##
# Convert SimpleMarkup to basic TexInfo format
#
# TODO: WTF is AttributeManager for?

class RDoc::Markup::ToTexInfo < RDoc::Markup::Formatter

  def format(text)
    text.txt.
      gsub(/@/, "@@").
      gsub(/\{/, "@{").
      gsub(/\}/, "@}").
      # gsub(/,/, "@,"). # technically only required in cross-refs
      gsub(/\+([\w]+)\+/, "@code{\\1}").
      gsub(/\<tt\>([^<]+)\<\/tt\>/, "@code{\\1}").
      gsub(/\*([\w]+)\*/, "@strong{\\1}").
      gsub(/\<b\>([^<]+)\<\/b\>/, "@strong{\\1}").
      gsub(/_([\w]+)_/, "@emph{\\1}").
      gsub(/\<em\>([^<]+)\<\/em\>/, "@emph{\\1}")
  end

  # :section: Visitor

  def start_accepting
    @text = []
  end

  def end_accepting
    @text.join("\n")
  end

  def accept_paragraph(attributes, text)
    @text << format(text)
  end

  def accept_verbatim(attributes, text)
    @text << "@verb{|#{format(text)}|}"
  end

  def accept_heading(attributes, text)
    heading = ['@majorheading', '@chapheading'][text.head_level - 1] || '@heading'
    @text << "#{heading} #{format(text)}"
  end

  def accept_list_start(attributes, text)
    @text << '@itemize @bullet'
  end

  def accept_list_end(attributes, text)
    @text << '@end itemize'
  end

  def accept_list_item(attributes, text)
    @text << "@item\n#{format(text)}"
  end

  def accept_blank_line(attributes, text)
    @text << "\n"
  end

  def accept_rule(attributes, text)
    @text << '-----'
  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
voloko-sdoc-0.1.3 rdoc/lib/rdoc/markup/to_texinfo.rb
voloko-sdoc-0.1.4 rdoc/lib/rdoc/markup/to_texinfo.rb
voloko-sdoc-0.1.5 rdoc/lib/rdoc/markup/to_texinfo.rb
voloko-sdoc-0.1.6 rdoc/lib/rdoc/markup/to_texinfo.rb
voloko-sdoc-0.1.7 rdoc/lib/rdoc/markup/to_texinfo.rb
rdoc-2.4.1 lib/rdoc/markup/to_texinfo.rb
rdoc-2.4.3 lib/rdoc/markup/to_texinfo.rb
rdoc-2.4.0 lib/rdoc/markup/to_texinfo.rb
rdoc-2.4.2 lib/rdoc/markup/to_texinfo.rb