class Asciidoctor::Extensions::Processor

AST nodes, such as Block and Inline, and for parsing child content.
Instances of the Processor class provide convenience methods for creating
the configuration is accessed using the {Processor#config} instance variable.
Hash can be passed to the initializer. Once the processor is initialized,
and is only consulted inside the initializer. An overriding configuration
style of default configuration is specific to the native Ruby environment
configuration options defined using the {Processor.option} method. This
This class provides access to a class-level Hash for holding default
Public: An abstract base class for document and syntax processors.

def config

Returns a configuration [Hash]

Public: Get the static configuration for this processor class.
def config
  @config ||= {}
end

def create_block parent, context, source, attrs, opts = {}

def create_block parent, context, source, attrs, opts = {}
  Block.new parent, context, { source: source, attributes: attrs }.merge(opts)
end

def create_image_block parent, attrs, opts = {}

Returns a [Block] node with all properties properly initialized.

opts - An optional Hash of options (default: {})
Use the alt attribute to specify an alternative text for the image.
Use the target attribute to set the source of the image.
attrs - A Hash of attributes to control how the image block is built.
parent - The parent Block (Block, Section, or Document) of this new image block.

Public: Creates an image block node and links it to the specified parent.
def create_image_block parent, attrs, opts = {}
  unless (target = attrs['target'])
    raise ::ArgumentError, 'Unable to create an image block, target attribute is required'
  end
  attrs['alt'] ||= (attrs['default-alt'] = Helpers.basename(target, true).tr('_-', ' '))
  title = (attrs.key? 'title') ? (attrs.delete 'title') : nil
  block = create_block parent, :image, nil, attrs, opts
  if title
    block.title = title
    block.assign_caption (attrs.delete 'caption'), 'figure'
  end
  block
end

def create_inline parent, context, text, opts = {}

def create_inline parent, context, text, opts = {}
  Inline.new parent, context, text, context == :quoted ? ({ type: :unquoted }.merge opts) : opts
end

def create_list parent, context, attrs = nil

Returns a [List] node with all properties properly initialized.

attrs - A Hash of attributes to set on this list block
context - The list context (e.g., :ulist, :olist, :colist, :dlist)
parent - The parent Block (Block, Section, or Document) of this new list block.

Public: Creates a list node and links it to the specified parent.
def create_list parent, context, attrs = nil
  list = List.new parent, context
  list.update_attributes attrs if attrs
  list
end

def create_list_item parent, text = nil

Returns a [ListItem] node with all properties properly initialized.

text - The text of the list item.
parent - The parent List of this new list item block.

Public: Creates a list item node and links it to the specified parent.
def create_list_item parent, text = nil
  ListItem.new parent, text
end

def create_section parent, title, attrs, opts = {}

Returns a [Section] node with all properties properly initialized.

state of the sectnums document attribute (optional).
:numbered - [Boolean] A flag to force numbering, which falls back to the
one greater than the parent level (optional).
:level - [Integer] The level to assign to this section; defaults to
opts - An optional Hash of options (default: {}):
disable automatic ID generation (when sectids document attribute is set).
Use the id attribute to assign an explicit ID or set the value to false to
Use the style attribute to set the name of a special section (ex. appendix).
attrs - A Hash of attributes to control how the section is built.
title - The String title of the new Section.
parent - The parent Section (or Document) of this new Section.

Creates a Section node in the same manner as the parser.

Public: Creates a new Section node.
def create_section parent, title, attrs, opts = {}
  doc = parent.document
  book = (doctype = doc.doctype) == 'book'
  level = opts[:level] || parent.level + 1
  if (style = attrs.delete 'style')
    if book && style == 'abstract'
      sectname, level = 'chapter', 1
    else
      sectname, special = style, true
      level = 1 if level == 0
    end
  elsif book
    sectname = level == 0 ? 'part' : (level > 1 ? 'section' : 'chapter')
  elsif doctype == 'manpage' && (title.casecmp 'synopsis') == 0
    sectname, special = 'synopsis', true
  else
    sectname = 'section'
  end
  sect = Section.new parent, level
  sect.title, sect.sectname = title, sectname
  if special
    sect.special = true
    if opts.fetch :numbered, (style == 'appendix')
      sect.numbered = true
    elsif !(opts.key? :numbered) && (doc.attr? 'sectnums', 'all')
      sect.numbered = (book && level == 1 ? :chapter : true)
    end
  elsif level > 0
    if opts.fetch :numbered, (doc.attr? 'sectnums')
      sect.numbered = sect.special ? parent.numbered && true : true
    end
  elsif opts.fetch :numbered, (book && (doc.attr? 'partnums'))
    sect.numbered = true
  end
  if (id = attrs['id']) == false
    attrs.delete 'id'
  else
    sect.id = attrs['id'] = id || ((doc.attr? 'sectids') ? (Section.generate_id sect.title, doc) : nil)
  end
  sect.update_attributes attrs
  sect
end

def enable_dsl

Returns self

NOTE Inspiration for this DSL design comes from https://corcoran.io/2013/09/04/simple-pattern-ruby-dsl/

This method automatically detects whether to use the include or extend keyword to mix in the module.

Mixes the DSL class for this processor into this processor class or instance.
def enable_dsl
  if const_defined? :DSL
    if singleton_class?
      include const_get :DSL
    else
      extend const_get :DSL
    end
  end
end

def initialize config = {}

def initialize config = {}
  @config = self.class.config.merge config
end

def option key, default_value

Returns nothing

option :contexts, [:open, :paragraph]

Examples

applied to all instances of this processor.
Public: Assigns a default value for the specified option that gets
def option key, default_value
  config[key] = default_value
end

def parse_attributes block, attrlist, opts = {}

Returns a Hash of parsed attributes

:sub_attributes - enables attribute substitution on the attrlist argument (optional, default: false)
:positional_attributes - an Array of attribute names to map positional arguments to (optional, default: false)
opts - an optional Hash of options to control processing:
attrlist - the list of attributes as a String
block - the current AbstractBlock or the parent AbstractBlock if there is no current block (used for applying subs)

Public: Parses the attrlist String into a Hash of attributes
def parse_attributes block, attrlist, opts = {}
  return {} if attrlist ? attrlist.empty? : true
  attrlist = block.sub_attributes attrlist if opts[:sub_attributes] && (attrlist.include? ATTR_REF_HEAD)
  (AttributeList.new attrlist).parse opts[:positional_attributes] || []
end

def parse_content parent, content, attributes = nil

QUESTION is parse_content the right method name? should we wrap in open block automatically?
--
Returns The parent node into which the blocks are parsed.

Public: Parses blocks in the content and attaches the block to the parent.
def parse_content parent, content, attributes = nil
  reader = Reader === content ? content : (Reader.new content)
  Parser.parse_blocks reader, parent, attributes
  parent
end

def process *args

def process *args
  raise ::NotImplementedError, %(#{Processor} subclass #{self.class} must implement the ##{__method__} method)
end

def update_config config

def update_config config
  @config.update config
end