Sha256: 197db367e3631047bc29d194029eb7fd500704c32344d82afda12a9ea31ddc7b

Contents?: true

Size: 1.24 KB

Versions: 16

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

class Asciidoctor::Document
  # promote preface block (i.e., preamble block with title in book doctype) to preface section
  # FIXME: this should be handled by core
  def promote_preface_block
    if doctype == 'book' && (blk0 = blocks[0])&.context == :preamble && blk0.title? && !blk0.title.nil_or_empty? &&
        blk0.blocks[0]&.style != 'abstract' && (blk1 = blocks[1])&.context == :section
      preface = Asciidoctor::Section.new self, blk1.level, false, attributes: { 1 => 'preface', 'style' => 'preface' }
      preface.special = true
      preface.sectname = 'preface'
      preface.title = blk0.instance_variable_get :@title
      preface.id = preface.generate_id
      if (first_child = blk0.blocks[0])&.option? 'notitle'
        preface.set_option 'notitle'
        first_child.set_attr 'role', 'lead' if first_child.context == :paragraph && !first_child.role?
      end
      preface.blocks.replace (blk0.blocks.map do |b|
        b.parent = preface
        b
      end)
      blocks[0] = preface
    end
    nil
  end

  # Internal: Returns whether the specified attribute has never been set and is not locked.
  def attr_unspecified? name
    !((attribute_locked? name) || (@attributes_modified.include? name))
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.3.19 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.18 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.17 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.16 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.15 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.14 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.13 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.12 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.11 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.10 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.9 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.8 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.7 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.6 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.5 lib/asciidoctor/pdf/ext/asciidoctor/document.rb
asciidoctor-pdf-2.3.4 lib/asciidoctor/pdf/ext/asciidoctor/document.rb