def maintain_mode_stack(line)
pop_mode if (mode_is_heading? current_mode or
current_mode == :paragraph or
current_mode == :horizontal_rule or
current_mode == :inline_example or
current_mode == :raw_text)
if line.end_block? and @mode_stack.include? line.paragraph_type
pop_mode until current_mode == line.paragraph_type
end
if ((not line.paragraph_type == :blank) or
@output_type == :blank)
while ((not @list_indent_stack.empty?) and
@list_indent_stack.last >= line.indent and
(not mode_is_block? current_mode))
if (@list_indent_stack.last == line.indent and
line.major_mode == current_mode)
break
else
pop_mode
end
end
end
pop_mode if line.end_block? and line.paragraph_type == current_mode
unless line.paragraph_type == :blank
if (@list_indent_stack.empty? or
@list_indent_stack.last <= line.indent or
mode_is_block? current_mode)
if @list_indent_stack.last != line.indent or mode_is_block? current_mode
push_mode(line.major_mode, line.indent) if line.major_mode
end
push_mode(line.paragraph_type, line.indent) unless line.end_block?
end
end
end