src/ruby-lib/asciidoctor-multipage.rb
def document(node)
    if node.processed
      # This node can now be handled by Html5Converter.
      super
    else
      # This node is the original full document which has not yet been
      # processed; this is the entry point for the extension.

      # Turn off extensions to avoid running them twice.
      # FIXME: DocinfoProcessor, InlineMacroProcessor, and Postprocessor
      # extensions should be retained. Is this possible with the API?
      #Asciidoctor::Extensions.unregister_all

      # Check toclevels and multipage-level attributes
      mplevel = node.document.attr('multipage-level', 1).to_i
      toclevels = node.document.attr('toclevels', 2).to_i
      if toclevels < mplevel
        logger.warn 'toclevels attribute should be >= multipage-level'
      end
      if mplevel < 0
        logger.warn 'multipage-level attribute must be >= 0'
        mplevel = 0
      end
      node.document.set_attribute('multipage-level', mplevel.to_s)

      # Set multipage chunk types
      set_multipage_attrs(node)

      # Set the "id" attribute for the Document, using the "docname", which is
      # based on the file name. Then register the document ID using the
      # document title. This allows cross-references to refer to (1) the
      # top-level document itself or (2) anchors in top-level content (blocks
      # that are specified before any sections).
      node.id = node.attributes['docname']
      node.register(:refs, [node.id,
                            (Inline.new(parent = node,
                                        context = :anchor,
                                        text = node.doctitle,
                                        opts = {:type => :ref,
                                                :id => node.id})),
                            node.doctitle])

      # Generate navigation links for all pages
      generate_nav_links(node)

      # Create and save a skeleton document for generating the TOC lists.
      @@full_outline = new_outline_doc(node)
      # Save the document catalog to use for each part/chapter page.
      @catalog = node.catalog

      # Retain any book intro blocks, delete others, and add a list of sections
      # for the book landing page.
      parts_list = Asciidoctor::List.new(node, :ulist)
      node.blocks.delete_if do |block|
        if block.context == :section
          part = block
          part.convert
          text = %(<<#{part.id},#{part.captioned_title}>>)
          if desc = block.attr('desc') then text << %( – #{desc}) end
          parts_list << Asciidoctor::ListItem.new(parts_list, text)
        end
      end
      node << parts_list

      # Add navigation links
      add_nav_links(node)

      # Mark page as processed and return converted result
      node.processed = true
      node.convert
    end
  end
# Process Document (either the original full document or a processed page)
Process Document (either the original full document or a processed page)
Process Document ( either the original full document or a processed page )
def document(node)
    if node.processed
      super
    else
      mplevel = node.document.attr('multipage-level', 1).to_i
      toclevels = node.document.attr('toclevels', 2).to_i
      if toclevels < mplevel
        logger.warn 'toclevels attribute should be >= multipage-level'
      end
      if mplevel < 0
        logger.warn 'multipage-level attribute must be >= 0'
        mplevel = 0
      end
      node.document.set_attribute('multipage-level', mplevel.to_s)
      set_multipage_attrs(node)
      node.id = node.attributes['docname']
      node.register(:refs, [node.id,
                            (Inline.new(parent = node,
                                        context = :anchor,
                                        text = node.doctitle,
                                        opts = {:type => :ref,
                                                :id => node.id})),
                            node.doctitle])
      generate_nav_links(node)
      @@full_outline = new_outline_doc(node)
      @catalog = node.catalog
      parts_list = Asciidoctor::List.new(node, :ulist)
      node.blocks.delete_if do |block|
        if block.context == :section
          part = block
          part.convert
          text = %(<<#{part.id},#{part.captioned_title}>>)
          if desc = block.attr('desc') then text << %( – #{desc}) end
          parts_list << Asciidoctor::ListItem.new(parts_list, text)
        end
      end
      node << parts_list
      add_nav_links(node)
      node.processed = true
      node.convert
    end
  end
def document ( node ) if node . processed super else mplevel = node . document . attr ( 'multipage-level' , 1 ) . to_i toclevels = node . document . attr ( 'toclevels' , 2 ) . to_i if toclevels < mplevel logger . warn 'toclevels attribute should be >= multipage-level' end if mplevel < 0 logger . warn 'multipage-level attribute must be >= 0' mplevel = 0 end node . document . set_attribute ( 'multipage-level' , mplevel . to_s ) set_multipage_attrs ( node ) node . id = node . attributes [ 'docname' ] node . register ( :refs , [ node . id , ( Inline . new ( parent = node , context = :anchor , text = node . doctitle , opts = { :type => :ref , :id => node . id } ) ) , node . doctitle ] ) generate_nav_links ( node ) @@full_outline = new_outline_doc ( node ) @catalog = node . catalog parts_list = Asciidoctor :: List . new ( node , :ulist ) node . blocks . delete_if do | block | if block . context == :section part = block part . convert text = %(<<#{part.id},#{part.captioned_title}>>) if desc = block . attr ( 'desc' ) then text << %( – #{desc}) e d parts_list << Asciidoctor :: ListItem . new ( parts_list , text ) end end node << parts_list add_nav_links ( node ) node . processed = true node . convert end end
Process Document (either the original full document or a processed page)
Process Document ( either the original full document or a processed page )
# This node can now be handled by Html5Converter. # This node is the original full document which has not yet been # processed; this is the entry point for the extension. # Turn off extensions to avoid running them twice. # FIXME: DocinfoProcessor, InlineMacroProcessor, and Postprocessor # extensions should be retained. Is this possible with the API? #Asciidoctor::Extensions.unregister_all # Check toclevels and multipage-level attributes # Set multipage chunk types # Set the "id" attribute for the Document, using the "docname", which is # based on the file name. Then register the document ID using the # document title. This allows cross-references to refer to (1) the # top-level document itself or (2) anchors in top-level content (blocks # that are specified before any sections). # Generate navigation links for all pages # Create and save a skeleton document for generating the TOC lists. # Save the document catalog to use for each part/chapter page. # Retain any book intro blocks, delete others, and add a list of sections # for the book landing page. # Add navigation links # Mark page as processed and return converted result
node