Class: Coradoc::CoreModel::Block

Inherits:
Base
  • Object
show all
Includes:
ChildrenContent
Defined in:
lib/coradoc/core_model/block.rb

Overview

Generic delimited block model

Represents all standard AsciiDoc delimited blocks including:

  • Example blocks (====)

  • Literal blocks (““)

  • Listing blocks (—-)

  • Open blocks (–)

  • Pass blocks (++++/++++)

  • Quote blocks (__)

  • Sidebar blocks (****)

  • Source blocks (—-)

  • Paragraphs (element_type: ‘paragraph’)

This is a schema-agnostic representation that captures the semantic structure without schema-specific interpretation.

Examples:

Creating a generic block

block = CoreModel::Block.new(
  delimiter_type: "====",
  delimiter_length: 4,
  content: "Example content here"
)

Creating a source block

block = CoreModel::Block.new(
  delimiter_type: "----",
  content: "puts 'Hello, World!'",
  attributes: [{ role: "source", language: "ruby" }]
)

Creating a paragraph with inline formatting

block = CoreModel::Block.new(
  element_type: "paragraph",
  children: [
    "Text with ",
    CoreModel::InlineElement.new(format_type: "bold", content: "bold"),
    " text"
  ]
)

Direct Known Subclasses

AnnotationBlock

Instance Attribute Summary collapse

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Method Summary

Methods included from ChildrenContent

#children=, #flat_text, included, #initialize, #renderable_content, #to_hash

Methods inherited from Base

#accept, #attr, #metadata, #semantically_equivalent?, #set_attr, #set_metadata

Instance Attribute Details

#contentString?

Returns the block’s text content (simple string) For mixed content with inline elements, use children instead.

Returns:

  • (String, nil)

    the block’s text content (simple string) For mixed content with inline elements, use children instead.



64
# File 'lib/coradoc/core_model/block.rb', line 64

attribute :content, :string

#delimiter_lengthInteger

Returns number of delimiter characters (default: 4).

Returns:

  • (Integer)

    number of delimiter characters (default: 4)



59
# File 'lib/coradoc/core_model/block.rb', line 59

attribute :delimiter_length, :integer, default: -> { 4 }

#delimiter_typeString?

Returns the delimiter character(s) used (e.g., ‘****’, ‘====’, ‘—-’).

Returns:

  • (String, nil)

    the delimiter character(s) used (e.g., ‘****’, ‘====’, ‘—-’)



55
# File 'lib/coradoc/core_model/block.rb', line 55

attribute :delimiter_type, :string

#element_typeString?

Returns the semantic type of the block (e.g., ‘paragraph’, ‘block’).

Returns:

  • (String, nil)

    the semantic type of the block (e.g., ‘paragraph’, ‘block’)



50
# File 'lib/coradoc/core_model/block.rb', line 50

attribute :element_type, :string

#languageString?

Returns language identifier for source code blocks.

Returns:

  • (String, nil)

    language identifier for source code blocks



72
# File 'lib/coradoc/core_model/block.rb', line 72

attribute :language, :string

#linesArray<String>?

Returns individual lines of content.

Returns:

  • (Array<String>, nil)

    individual lines of content



68
# File 'lib/coradoc/core_model/block.rb', line 68

attribute :lines, :string, collection: true