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