src/ruby-lib/asciidoctor-multipage.rb
# Process a Section. Each Section will either be split off into its own page
# or processed as normal by Html5Converter.
Process a Section. Each Section will either be split off into its own page
or processed as normal by Html5Converter.
Process a Section . Each Section will either be split off into its own page or processed as normal by Html5Converter .
def section(node)
    doc = node.document
    if doc.processed
      super
    else
      page = Asciidoctor::Document.new([],
                                       {:attributes => doc.attributes.clone,
                                        :doctype => doc.doctype,
                                        :header_footer => !doc.attr?(:embedded),
                                        :safe => doc.safe})
      page.set_attr('webfonts', doc.attr(:webfonts))
      if node.parent.respond_to?(:numbered) && node.parent.numbered
        page.sectnum = node.parent.sectnum
      end
      if node.mplevel == :branch
        chapters_list = Asciidoctor::List.new(node, :ulist)
        node.blocks.delete_if do |block|
          if block.context == :section
            chapter = block
            chapter.convert
            text = %(<<#{chapter.id},#{chapter.captioned_title}>>)
            if desc = block.attr('desc') then text << %( – #{desc}) end
            chapters_list << Asciidoctor::ListItem.new(chapters_list, text)
            true
          end
        end
        node << chapters_list
        reparent(node, page)
        page.blocks << node
      else 
        reparent(node, page)
        page.blocks << node
      end
      page.nav_links = node.nav_links
      add_nav_links(page)
      @pages << page
      page.id = node.id
      page.catalog = @catalog
      page.mplevel = node.mplevel
      page.processed = true
    end
  end
def section ( node ) doc = node . document if doc . processed super else page = Asciidoctor :: Document . new ( [ ] , { :attributes => doc . attributes . clone , :doctype => doc . doctype , :header_footer => ! doc . attr? ( :embedded ) , :safe => doc . safe } ) page . set_attr ( 'webfonts' , doc . attr ( :webfonts ) ) if node . parent . respond_to? ( :numbered ) && node . parent . numbered page . sectnum = node . parent . sectnum end if node . mplevel == :branch chapters_list = Asciidoctor :: List . new ( node , :ulist ) node . blocks . delete_if do | block | if block . context == :section chapter = block chapter . convert text = %(<<#{chapter.id},#{chapter.captioned_title}>>) if desc = block . attr ( 'desc' ) then text << %( – #{desc}) e d chapters_list << Asciidoctor :: ListItem . new ( chapters_list , text ) true end end node << chapters_list reparent ( node , page ) page . blocks << node else reparent ( node , page ) page . blocks << node end page . nav_links = node . nav_links add_nav_links ( page ) @pages << page page . id = node . id page . catalog = @catalog page . mplevel = node . mplevel page . processed = true end end
Process a Section.
Process a Section .
# This node can now be handled by Html5Converter. # This node is from the original document and has not yet been processed. # Create a new page for this section # Retain webfonts attribute (why is doc.attributes.clone not adequate?) # Save sectnum for use later (a Document object normally has no sectnum) # Process node according to mplevel # Retain any part intro blocks, delete others, and add a list # of sections for the part landing page. # NOTE, there is a non-breaking space (Unicode U+00A0) below. # Add chapters list to node, reparent node to new page, add # node to page, mark as processed, and add page to @pages. # :leaf # Reparent node to new page, add node to page, mark as # processed, and add page to @pages. # Add navigation links using saved HTML # Mark page as processed and add to collection of pages
node