src/ruby-lib/asciidoctor-multipage.rb
def generate_outline(node, opts = {})
    # This is the same as Html5Converter outline()
    return unless node.sections?
    sectnumlevels = opts[:sectnumlevels] || (node.document.attr 'sectnumlevels', 3).to_i
    toclevels = opts[:toclevels] || (node.document.attr 'toclevels', 2).to_i
    sections = node.sections
    result = [%(<ul class="sectlevel#{sections[0].level}">)]
    sections.each do |section|
      slevel = section.level
      if section.caption
        stitle = section.captioned_title
      elsif section.numbered && slevel <= sectnumlevels
        stitle = %(#{section.sectnum} #{section.title})
      else
        stitle = section.title
      end
      stitle = stitle.gsub DropAnchorRx, '' if stitle.include? '<a'

      # But add a special style for current page in TOC
      if section.id == opts[:page_id]
        stitle = %(<span class="toc-current">#{stitle}</span>)
      end

      # And we also need to find the parent page of the target node
      current = section
      until current.mplevel != :content
        current = current.parent
      end
      parent_chapter = current

      # If the target is the top-level section of the parent page, there is no
      # need to include the anchor.
      if parent_chapter.id == section.id
        link = %(#{parent_chapter.id}.html)
      else
        link = %(#{parent_chapter.id}.html##{section.id})
      end
      result << %(<li><a href="#{link}">#{stitle}</a>)

      # Finish in a manner similar to Html5Converter outline()
      if slevel < toclevels &&
         (child_toc_level = generate_outline section,
                                        :toclevels => toclevels,
                                        :secnumlevels => sectnumlevels,
                                        :page_id => opts[:page_id])
        result << child_toc_level
      end
      result << '</li>'
    end
    result << '</ul>'
    result.join LF
  end
# Generate the actual HTML outline for the TOC. This method is analogous to
# Html5Converter outline().
Generate the actual HTML outline for the TOC. This method is analogous to
Html5Converter outline().
Generate the actual HTML outline for the TOC . This method is analogous to Html5Converter outline () .
def generate_outline(node, opts = {})
    return unless node.sections?
    sectnumlevels = opts[:sectnumlevels] || (node.document.attr 'sectnumlevels', 3).to_i
    toclevels = opts[:toclevels] || (node.document.attr 'toclevels', 2).to_i
    sections = node.sections
    result = [%(<ul class="sectlevel#{sections[0].level}">)]
    sections.each do |section|
      slevel = section.level
      if section.caption
        stitle = section.captioned_title
      elsif section.numbered && slevel <= sectnumlevels
        stitle = %(#{section.sectnum} #{section.title})
      else
        stitle = section.title
      end
      stitle = stitle.gsub DropAnchorRx, '' if stitle.include? '<a'
      if section.id == opts[:page_id]
        stitle = %(<span class="toc-current">#{stitle}</span>)
      end
      current = section
      until current.mplevel != :content
        current = current.parent
      end
      parent_chapter = current
      if parent_chapter.id == section.id
        link = %(#{parent_chapter.id}.html)
      else
        link = %(#{parent_chapter.id}.html##{section.id})
      end
      result << %(<li><a href="#{link}">#{stitle}</a>)
      if slevel < toclevels &&
         (child_toc_level = generate_outline section,
                                        :toclevels => toclevels,
                                        :secnumlevels => sectnumlevels,
                                        :page_id => opts[:page_id])
        result << child_toc_level
      end
      result << '</li>'
    end
    result << '</ul>'
    result.join LF
  end
def generate_outline ( node , opts = { } ) return unless node . sections? sectnumlevels = opts [ :sectnumlevels ] || ( node . document . attr 'sectnumlevels' , 3 ) . to_i toclevels = opts [ :toclevels ] || ( node . document . attr 'toclevels' , 2 ) . to_i sections = node . sections result = [ %(<ul class="sectlevel#{sections[0].level}">) ] sections . each do | section | slevel = section . level if section . caption stitle = section . captioned_title elsif section . numbered && slevel <= sectnumlevels stitle = %(#{section.sectnum} #{section.title}) else stitle = section . title end stitle = stitle . gsub DropAnchorRx , '' if stitle . include? '<a' if section . id == opts [ :page_id ] stitle = %(<span class="toc-current">#{stitle}</span>) end current = section until current . mplevel != :content current = current . parent end parent_chapter = current if parent_chapter . id == section . id link = %(#{parent_chapter.id}.html) else link = %(#{parent_chapter.id}.html##{section.id}) end result << %(<li><a href="#{link}">#{stitle}</a>) if slevel < toclevels && ( child_toc_level = generate_outline section , :toclevels => toclevels , :secnumlevels => sectnumlevels , :page_id => opts [ :page_id ] ) result << child_toc_level end result << '</li>' end result << '</ul>' result . join LF end
Generate the actual HTML outline for the TOC.
Generate the actual HTML outline for the TOC .
# This is the same as Html5Converter outline() # But add a special style for current page in TOC # And we also need to find the parent page of the target node # If the target is the top-level section of the parent page, there is no # need to include the anchor. # Finish in a manner similar to Html5Converter outline()
node
opts