def self.parse_section_title(reader, document)
line1 = reader.read_line
sect_id = nil
sect_title = nil
sect_level = -1
sect_reftext = nil
single_line = true
first_char = line1.chr
if (first_char == '=' || (Compliance.markdown_syntax && first_char == '#')) &&
(match = AtxSectionRx.match(line1))
sect_level = single_line_section_level match[1]
sect_title = match[2]
if sect_title.end_with?(']]') && (anchor_match = InlineSectionAnchorRx.match(sect_title))
if anchor_match[2].nil?
sect_title = anchor_match[1]
sect_id = anchor_match[3]
sect_reftext = anchor_match[4]
end
end
elsif Compliance.underline_style_section_titles
if (line2 = reader.peek_line(true)) && SECTION_LEVELS.has_key?(line2.chr) && line2 =~ SetextSectionLineRx &&
(name_match = SetextSectionTitleRx.match(line1)) &&
(line_length(line1) - line_length(line2)).abs <= 1
sect_title = name_match[1]
if sect_title.end_with?(']]') && (anchor_match = InlineSectionAnchorRx.match(sect_title))
if anchor_match[2].nil?
sect_title = anchor_match[1]
sect_id = anchor_match[3]
sect_reftext = anchor_match[4]
end
end
sect_level = section_level line2
single_line = false
reader.advance
end
end
if sect_level >= 0
sect_level += document.attr('leveloffset', 0).to_i
end
[sect_id, sect_reftext, sect_title, sect_level, single_line]
end