def self.parse_section_title(reader, document)
sect_id = sect_reftext = nil
line1 = reader.read_line
if Compliance.markdown_syntax ? ((line1.start_with? '=', '#') && ExtAtxSectionTitleRx =~ line1) :
((line1.start_with? '=') && AtxSectionTitleRx =~ line1)
sect_level, sect_title, atx = $1.length - 1, $2, true
if sect_title.end_with?(']]') && InlineSectionAnchorRx =~ sect_title && !$1
sect_title, sect_id, sect_reftext = (sect_title.slice 0, sect_title.length - $&.length), $2, $3
end
elsif Compliance.underline_style_section_titles && (line2 = reader.peek_line(true)) &&
(sect_level = SETEXT_SECTION_LEVELS[line2_ch1 = line2.chr]) &&
line2_ch1 * (line2_len = line2.length) == line2 && (sect_title = SetextSectionTitleRx =~ line1 && $1) &&
(line_length(line1) - line2_len).abs < 2
atx = false
if sect_title.end_with?(']]') && InlineSectionAnchorRx =~ sect_title && !$1
sect_title, sect_id, sect_reftext = (sect_title.slice 0, sect_title.length - $&.length), $2, $3
end
reader.shift
else
raise %(Unrecognized section at #{reader.prev_line_info})
end
sect_level += document.attr('leveloffset').to_i if document.attr?('leveloffset')
[sect_id, sect_reftext, sect_title, sect_level, atx]
end