Class: Asciidoctor::Extensions::BlockProcessor
- Defined in:
- lib/asciidoctor/extensions.rb
Overview
BlockProcessors are used to handle delimited blocks and paragraphs that have a custom name.
When Asciidoctor encounters a delimited block or paragraph with an unrecognized name while parsing the document, it looks for a BlockProcessor registered to handle this name and, if found, invokes its Processor#process method to build a corresponding node in the document tree.
If the process method returns an instance of Block, the content model of that Block is :compound, and the Block contains at least one line, the parser will parse those lines into blocks and append them to the returned block.
If your custom block can be applied to a paragraph or delimited block, and you want to preserve the content model of the input, check whether the value of the cloaked-context attribute is :paragraph. If it is, set the content model of the returned block to :simple. Otherwise, set the content model to :compound.
AsciiDoc example:
[shout]
Get a move on.
Recognized options:
-
:named - The name of the block (required: true)
-
:contexts - The blocks contexts on which this style can be used (default: [:paragraph, :open]
-
:content_model - The structure of the content supported in this block (default: :compound)
-
:positional_attrs - A list of attribute names used to map positional attributes (default: nil)
-
:default_attrs - A hash of attribute names and values used to seed the attributes hash (default: nil)
-
…
BlockProcessor implementations must extend BlockProcessor.
Constant Summary collapse
- DSL =
BlockProcessorDsl
Instance Attribute Summary collapse
Attributes inherited from Processor
Instance Method Summary collapse
-
#initialize(name = nil, config = {}) ⇒ BlockProcessor
constructor
A new instance of BlockProcessor.
- #process(parent, reader, attributes) ⇒ Object
Methods inherited from Processor
config, #create_block, #create_image_block, #create_inline, #create_list, #create_list_item, #create_section, enable_dsl, option, #parse_attributes, #parse_content, #update_config
Constructor Details
#initialize(name = nil, config = {}) ⇒ BlockProcessor
Returns a new instance of BlockProcessor.
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/asciidoctor/extensions.rb', line 554 def initialize name = nil, config = {} super config @name = name || @config[:name] # assign fallbacks case @config[:contexts] when ::NilClass @config[:contexts] ||= ::Set[:open, :paragraph] when ::Symbol @config[:contexts] = ::Set[@config[:contexts]] when ::Array @config[:contexts] = ::Set.new @config[:contexts] end # QUESTION should the default content model be raw?? @config[:content_model] ||= :compound end |
Instance Attribute Details
#name ⇒ Object
552 553 554 |
# File 'lib/asciidoctor/extensions.rb', line 552 def name @name end |
Instance Method Details
#process(parent, reader, attributes) ⇒ Object
570 571 572 |
# File 'lib/asciidoctor/extensions.rb', line 570 def process parent, reader, attributes raise ::NotImplementedError, %(#{BlockProcessor} subclass #{self.class} must implement the ##{__method__} method) end |