4 # We store the lines we're working on as objects of class Line. These
5 # contain the text of the line, along with a flag indicating the line type,
6 # and an indentation level.
23 # The indentation nesting level
29 # A prefix or parameter. For LIST lines, this is
30 # the text that introduced the list item (the label)
33 # A flag. For list lines, this is the type of the list
36 # the number of leading spaces
37 attr_accessor :leading_spaces
39 # true if this line has been deleted from the list of lines
40 attr_accessor :deleted
47 1 while @text.gsub!(/\t+/) { ' ' * (8*$&.length - $`.length % 8)} && $~ #`
49 # Strip trailing whitespace
50 @text.sub!(/\s+$/, '')
52 # and look for leading whitespace
55 @leading_spaces = $1.length
57 @leading_spaces = INFINITY
61 # Return true if this line is blank
66 # stamp a line with a type, a level, a prefix, and a flag
67 def stamp(type, level, param="", flag=nil)
68 @type, @level, @param, @flag = type, level, param, flag
72 # Strip off the leading margin
74 def strip_leading(size)
83 "#@type#@level: #@text"
88 # A container for all the lines.
94 attr_reader :lines # :nodoc:
106 @lines.each do |line|
107 yield line unless line.deleted
121 res = @lines[@nextline]
122 @nextline += 1 if @nextline < @lines.size
123 end while res and res.deleted and @nextline < @lines.size
132 a_line.deleted = true
136 margin = @lines.collect{|l| l.leading_spaces}.min
137 margin = 0 if margin == :INFINITY
138 @lines.each {|line| line.strip_leading(margin) } if margin > 0
142 @lines.map {|l| l.text}.join("\n")
146 @lines.map {|l| l.type }