assign_types_to_lines(margin = 0, level = 0)
private
Look through the text at line indentation. We flag each line as being
Blank, a paragraph, a list element, or verbatim text.
Show source
def assign_types_to_lines(margin = 0, level = 0)
while line = @lines.next
if line.blank? then
line.stamp :BLANK, level
next
end
text = line.text
for i in 0...margin
if text[i] != SPACE
@lines.unget
return
end
end
active_line = text[margin..-1]
if /^(---+)\s*$/ =~ active_line
line.stamp :RULE, level, $1.length-2
next
end
if SIMPLE_LIST_RE =~ active_line
offset = margin + $1.length
prefix = $2
prefix_length = prefix.length
flag = case prefix
when "*","-" then :BULLET
when /^\d/ then :NUMBER
when /^[A-Z]/ then :UPPERALPHA
when /^[a-z]/ then :LOWERALPHA
else raise "Invalid List Type: #{self.inspect}"
end
line.stamp :LIST, level+1, prefix, flag
text[margin, prefix_length] = " " * prefix_length
assign_types_to_lines(offset, level + 1)
next
end
if LABEL_LIST_RE =~ active_line
offset = margin + $1.length
prefix = $2
prefix_length = prefix.length
next if handled_labeled_list(line, level, margin, offset, prefix)
end
if active_line[0] == == and active_line =~ /^(=+)\s*(.*)/
prefix_length = $1.length
prefix_length = 6 if prefix_length > 6
line.stamp :HEADING, 0, prefix_length
line.strip_leading(margin + prefix_length)
next
end
if active_line[0] == SPACE
line.strip_leading(margin) if margin > 0
line.stamp :VERBATIM, level
else
line.stamp :PARAGRAPH, level
end
end
end