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")

Instance Attribute Summary collapse

Attributes inherited from Element

#children

Instance Method Summary collapse

Methods inherited from Element

#<<

Constructor Details

#initialize(language: nil) ⇒ Code

Create a new code element.

Parameters:

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

    optional language identifier for syntax highlighting



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

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

Instance Attribute Details

#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