Skip to content

Commit

Permalink
resolves asciidoctor#1261 set correct level for special sections in p…
Browse files Browse the repository at this point in the history
…arser

- coerce level to 1 for special sections defined at level 0
- skip unnecessary level logic in parser and converter as a result
  • Loading branch information
mojavelinux committed Jun 3, 2017
1 parent 326cd7d commit 5dca529
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
13 changes: 4 additions & 9 deletions lib/asciidoctor/converter/html5.rb
Expand Up @@ -303,14 +303,11 @@ def outline node, opts = {}
toclevels = opts[:toclevels] || (node.document.attr 'toclevels', 2).to_i
result = []
sections = node.sections
# FIXME the level for special sections should be set correctly in the model
# slevel will only be 0 if we have a book doctype with parts
slevel = (first_section = sections[0]).level
slevel = 1 if slevel == 0 && first_section.special
result << %(<ul class="sectlevel#{slevel}">)
# FIXME special sections grouped with parts throw off this calculation
result << %(<ul class="sectlevel#{slevel = sections[0].level}">)
sections.each do |section|
section_num = (section.numbered && !section.caption && section.level <= sectnumlevels) ? %(#{section.sectnum} ) : nil
if section.level < toclevels && (child_toc_level = outline section, :toclevels => toclevels, :secnumlevels => sectnumlevels)
section_num = section.numbered && !section.caption && slevel <= sectnumlevels ? %(#{section.sectnum} ) : nil
if slevel < toclevels && (child_toc_level = outline section, :toclevels => toclevels, :secnumlevels => sectnumlevels)
result << %(<li><a href="##{section.id}">#{section_num}#{section.captioned_title}</a>)
result << child_toc_level
result << '</li>'
Expand All @@ -324,8 +321,6 @@ def outline node, opts = {}

def section node
slevel = node.level
# QUESTION should the check for slevel be done in section?
slevel = 1 if slevel == 0 && node.special
htag = %(h#{slevel + 1})
id_attr = anchor = link_start = link_end = nil
if node.id
Expand Down
7 changes: 2 additions & 5 deletions lib/asciidoctor/converter/manpage.rb
Expand Up @@ -160,13 +160,10 @@ def embedded node
end

def section node
slevel = node.level
# QUESTION should the check for slevel be done in section?
slevel = 1 if slevel == 0 && node.special
result = []
if slevel > 1
if node.level > 1
macro = 'SS'
# QUESTION why captioned title? why not for slevel == 1?
# QUESTION why captioned title? why not when level == 1?
stitle = node.captioned_title
else
macro = 'SH'
Expand Down
18 changes: 4 additions & 14 deletions lib/asciidoctor/parser.rb
Expand Up @@ -283,21 +283,10 @@ def self.next_section reader, parent, attributes = {}
else
doctype = (document = parent.document).doctype
section = initialize_section reader, parent, attributes
# clear attributes, except for title which carries over
# section title to next block of content
# clear attributes except for title, which carries section title to next block of content
attributes = (title = attributes['title']) ? { 'title' => title } : {}
if (current_level = section.level) == 0 && doctype == 'book'
if (part = (sectname = section.sectname) == 'part')
expected_next_levels = [1]
# subsections in preface & appendix in multipart books start at level 2
elsif section.special && (sectname == 'preface' || sectname == 'appendix')
expected_next_levels = [2]
else
expected_next_levels = [1]
end
else
expected_next_levels = [current_level + 1]
end
part = section.sectname == 'part'
expected_next_levels = [(current_level = section.level) + 1]
end

reader.skip_blank_lines
Expand Down Expand Up @@ -1577,6 +1566,7 @@ def self.initialize_section reader, parent, attributes = {}
sect_name, sect_level = 'chapter', 1
else
sect_name, sect_special = style, true
sect_level = 1 if sect_level == 0
sect_numbered_force = style == 'appendix'
end
else
Expand Down

0 comments on commit 5dca529

Please sign in to comment.