rd.rb 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ##
  2. # RDoc::RD implements the RD format from the rdtool gem.
  3. #
  4. # = LICENSE
  5. #
  6. # The grammar that produces RDoc::RD::BlockParser and RDoc::RD::InlineParser
  7. # is included in RDoc under the Ruby License.
  8. #
  9. # You can find the original source for rdtool at
  10. # https://github.com/uwabami/rdtool/
  11. #
  12. # You can use, re-distribute or change these files under Ruby's License or GPL.
  13. #
  14. # 1. You may make and give away verbatim copies of the source form of the
  15. # software without restriction, provided that you duplicate all of the
  16. # original copyright notices and associated disclaimers.
  17. #
  18. # 2. You may modify your copy of the software in any way, provided that
  19. # you do at least ONE of the following:
  20. #
  21. # a. place your modifications in the Public Domain or otherwise
  22. # make them Freely Available, such as by posting said
  23. # modifications to Usenet or an equivalent medium, or by allowing
  24. # the author to include your modifications in the software.
  25. #
  26. # b. use the modified software only within your corporation or
  27. # organization.
  28. #
  29. # c. give non-standard binaries non-standard names, with
  30. # instructions on where to get the original software distribution.
  31. #
  32. # d. make other distribution arrangements with the author.
  33. #
  34. # 3. You may distribute the software in object code or binary form,
  35. # provided that you do at least ONE of the following:
  36. #
  37. # a. distribute the binaries and library files of the software,
  38. # together with instructions (in the manual page or equivalent)
  39. # on where to get the original distribution.
  40. #
  41. # b. accompany the distribution with the machine-readable source of
  42. # the software.
  43. #
  44. # c. give non-standard binaries non-standard names, with
  45. # instructions on where to get the original software distribution.
  46. #
  47. # d. make other distribution arrangements with the author.
  48. #
  49. # 4. You may modify and include the part of the software into any other
  50. # software (possibly commercial). But some files in the distribution
  51. # are not written by the author, so that they are not under these terms.
  52. #
  53. # For the list of those files and their copying conditions, see the
  54. # file LEGAL.
  55. #
  56. # 5. The scripts and library files supplied as input to or produced as
  57. # output from the software do not automatically fall under the
  58. # copyright of the software, but belong to whomever generated them,
  59. # and may be sold commercially, and may be aggregated with this
  60. # software.
  61. #
  62. # 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  63. # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  64. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  65. # PURPOSE.
  66. class RDoc::RD
  67. ##
  68. # Parses +rd+ source and returns an RDoc::Markup::Document. If the
  69. # <tt>=begin</tt> or <tt>=end</tt> lines are missing they will be added.
  70. def self.parse rd
  71. rd = rd.lines.to_a
  72. if rd.find { |i| /\S/ === i } and !rd.find{|i| /^=begin\b/ === i } then
  73. rd.unshift("=begin\n").push("=end\n")
  74. end
  75. parser = RDoc::RD::BlockParser.new
  76. document = parser.parse rd
  77. # isn't this always true?
  78. document.parts.shift if RDoc::Markup::BlankLine === document.parts.first
  79. document.parts.pop if RDoc::Markup::BlankLine === document.parts.last
  80. document
  81. end
  82. autoload :BlockParser, 'rdoc/rd/block_parser'
  83. autoload :InlineParser, 'rdoc/rd/inline_parser'
  84. autoload :Inline, 'rdoc/rd/inline'
  85. end