Method deprecated or moved
This method is deprecated or moved on the latest stable version. The last existing version (v1_9_1_378) is shown here.
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.
# File lib/rdoc/markup.rb, line 157
def assign_types_to_lines(margin = 0, level = 0)
while line = @lines.next
if line.blank? then
line.stamp :BLANK, level
next
end
# if a line contains non-blanks before the margin, then it must belong
# to an outer level
text = line.text
for i in 0...margin
if text[i] != SPACE
@lines.unget
return
end
end
active_line = text[margin..-1]
# Rules (horizontal lines) look like
#
# --- (three or more hyphens)
#
# The more hyphens, the thicker the rule
#
if /^(---+)\s*$/ =~ active_line
line.stamp :RULE, level, $1.length-2
next
end
# Then look for list entries. First the ones that have to have
# text following them (* xxx, - xxx, and dd. xxx)
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
# Headings look like
# = Main heading
# == Second level
# === Third
#
# Headings reset the level to 0
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 the character's a space, then we have verbatim text,
# otherwise
if active_line[0] == SPACE
line.strip_leading(margin) if margin > 0
line.stamp :VERBATIM, level
else
line.stamp :PARAGRAPH, level
end
end
end Related methods
- Instance methods
- add_html
- add_special
- add_word_pair
- content
- convert
- get_line_types
- Class methods
- new
- Private methods
-
assign_types_to_lines -
group_lines -
handled_labeled_list