method
build_list
v1_9_3_125 -
Show latest stable
- Class:
RDoc::Markup::Parser
build_list(margin)public
Builds a List flush to margin
# File lib/rdoc/markup/parser.rb, line 106
def build_list margin
p :list_start => margin if @debug
list = RDoc::Markup::List.new
until @tokens.empty? do
type, data, column, = get
case type
when :BULLET, :LABEL, :LALPHA, :NOTE, :NUMBER, :UALPHA then
if column < margin || (list.type && list.type != type) then
unget
break
end
list.type = type
peek_type, _, column, = peek_token
case type
when :NOTE, :LABEL then
if peek_type == :NEWLINE then
# description not on the same line as LABEL/NOTE
# skip the trailing newline & any blank lines below
while peek_type == :NEWLINE
get
peek_type, _, column, = peek_token
end
# we may be:
# - at end of stream
# - at a column < margin:
# [text]
# blah blah blah
# - at the same column, but with a different type of list item
# [text]
# * blah blah
# - at the same column, with the same type of list item
# [one]
# [two]
# In all cases, we have an empty description.
# In the last case only, we continue.
if peek_type.nil? || column < margin then
empty = 1
elsif column == margin then
case peek_type
when type
empty = 2 # continue
when *LIST_TOKENS
empty = 1
else
empty = 0
end
else
empty = 0
end
if empty > 0 then
item = RDoc::Markup::ListItem.new(data)
item << RDoc::Markup::BlankLine.new
list << item
break if empty == 1
next
end
end
else
data = nil
end
list_item = RDoc::Markup::ListItem.new data
parse list_item, column
list << list_item
else
unget
break
end
end
p :list_end => margin if @debug
return nil if list.empty?
list
end Related methods
- Instance methods
- build_heading
- build_list
- build_paragraph
- build_verbatim
- get
- parse
- peek_token
- skip
- token_pos
- tokenize
- unget
- Class methods
- new
- parse
- tokenize