Sha256: 4b2fe73ed5f3d80aef423d22228172a4bab8f18d26cd4282f4cd0e4baf23176f

Contents?: true

Size: 1021 Bytes

Versions: 7

Compression:

Stored size: 1021 Bytes

Contents

require 'asciidoctor/html5s/version'
require 'asciidoctor/extensions' unless RUBY_PLATFORM == 'opal'

module Asciidoctor::Html5s

  # This extension moves every callout list immediately following listing block
  # to instance variable +@html5s_colist+ inside the listing block.
  # The aim is to render callout list as part of the corresponding listing.
  class AttachedColistTreeprocessor < ::Asciidoctor::Extensions::Treeprocessor

    def process(document)
      document.find_by(context: :colist) do |colist|
        blocks = colist.parent.blocks
        colist_idx = blocks.find_index(colist)
        prev_block = blocks[colist_idx - 1] if colist_idx

        if prev_block && prev_block.node_name == 'listing'
          prev_block.instance_variable_set(:@html5s_colist, colist)
          # XXX: This mutates node's blocks list!
          # :empty is our special block type that just outputs nothing.
          blocks[colist_idx] = create_block(colist.parent, :empty, '', {})
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
asciidoctor-html5s-0.3.0 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
asciidoctor-html5s-0.2.1 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
asciidoctor-html5s-0.2.0 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
asciidoctor-html5s-0.1.0 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
asciidoctor-html5s-0.1.0.beta.11 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
asciidoctor-html5s-0.1.0.beta.10 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb
asciidoctor-html5s-0.1.0.beta.9 lib/asciidoctor/html5s/attached_colist_treeprocessor.rb