Class: Markbridge::AST::Code

Inherits:
Element show all
Defined in:
lib/markbridge/ast/code.rb

Overview

Represents an inline or block code element.

Examples:

Inline code

code = AST::Code.new
code << AST::Text.new("puts 'hello'")

Code with language for syntax highlighting

code = AST::Code.new(language: "ruby")
code << AST::Text.new("def hello\n  puts 'world'\nend")

Constant Summary

Constants inherited from Node

Node::DESCENDANTS

Instance Attribute Summary collapse

Attributes inherited from Element

#children

Instance Method Summary collapse

Methods inherited from Element

#<<, #descendants, #each_descendant, #replace_child, #replace_children

Methods inherited from Node

ast_chain, descendants, inherited

Constructor Details

#initialize(language: nil, block: nil) ⇒ Code

Create a new code element.

Parameters:

  • language (String, nil) (defaults to: nil)

    optional language identifier for syntax highlighting

  • block (Boolean, nil) (defaults to: nil)

    true when the source construct is a code block by definition (e.g. <pre>), even with single-line content



27
28
29
30
31
# File 'lib/markbridge/ast/code.rb', line 27

def initialize(language: nil, block: nil)
  super()
  @language = language
  @block = block
end

Instance Attribute Details

#blockBoolean? (readonly)

Returns true forces a fenced block; anything else leaves the block-or-inline decision to the renderer.

Returns:

  • (Boolean, nil)

    true forces a fenced block; anything else leaves the block-or-inline decision to the renderer



20
21
22
# File 'lib/markbridge/ast/code.rb', line 20

def block
  @block
end

#languageString? (readonly)

Returns the programming language for syntax highlighting.

Returns:

  • (String, nil)

    the programming language for syntax highlighting



16
17
18
# File 'lib/markbridge/ast/code.rb', line 16

def language
  @language
end