PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/benchmark/app/rdoc-2.4.3/lib/rdoc/markup/to_texinfo.rb

http://github.com/rubinius/rubinius
Ruby | 73 lines | 50 code | 17 blank | 6 comment | 1 complexity | c0c5e6b7d8440a95f291ee9e2b6dc4c6 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, 0BSD, GPL-2.0, LGPL-2.1
  1. require 'rdoc/markup/formatter'
  2. require 'rdoc/markup/fragments'
  3. require 'rdoc/markup/inline'
  4. require 'rdoc/markup'
  5. require 'rdoc/markup/formatter'
  6. ##
  7. # Convert SimpleMarkup to basic TexInfo format
  8. #
  9. # TODO: WTF is AttributeManager for?
  10. class RDoc::Markup::ToTexInfo < RDoc::Markup::Formatter
  11. def format(text)
  12. text.txt.
  13. gsub(/@/, "@@").
  14. gsub(/\{/, "@{").
  15. gsub(/\}/, "@}").
  16. # gsub(/,/, "@,"). # technically only required in cross-refs
  17. gsub(/\+([\w]+)\+/, "@code{\\1}").
  18. gsub(/\<tt\>([^<]+)\<\/tt\>/, "@code{\\1}").
  19. gsub(/\*([\w]+)\*/, "@strong{\\1}").
  20. gsub(/\<b\>([^<]+)\<\/b\>/, "@strong{\\1}").
  21. gsub(/_([\w]+)_/, "@emph{\\1}").
  22. gsub(/\<em\>([^<]+)\<\/em\>/, "@emph{\\1}")
  23. end
  24. # :section: Visitor
  25. def start_accepting
  26. @text = []
  27. end
  28. def end_accepting
  29. @text.join("\n")
  30. end
  31. def accept_paragraph(attributes, text)
  32. @text << format(text)
  33. end
  34. def accept_verbatim(attributes, text)
  35. @text << "@verb{|#{format(text)}|}"
  36. end
  37. def accept_heading(attributes, text)
  38. heading = ['@majorheading', '@chapheading'][text.head_level - 1] || '@heading'
  39. @text << "#{heading} #{format(text)}"
  40. end
  41. def accept_list_start(attributes, text)
  42. @text << '@itemize @bullet'
  43. end
  44. def accept_list_end(attributes, text)
  45. @text << '@end itemize'
  46. end
  47. def accept_list_item(attributes, text)
  48. @text << "@item\n#{format(text)}"
  49. end
  50. def accept_blank_line(attributes, text)
  51. @text << "\n"
  52. end
  53. def accept_rule(attributes, text)
  54. @text << '-----'
  55. end
  56. end