Class: Coradoc::Markdown::Math

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/markdown/model/math.rb

Overview

Represents a math block (block or inline)

Block math syntax: $$…$$ on its own lines Inline math syntax: $$…$$ within text

Examples:

$$\lambda_\alpha > 5$$
$$1 + 1$$

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#serialize_content, #to_h, visit, #visit

Class Method Details

.block(content) ⇒ Math

Create a block math element

Parameters:

  • content (String)

    The math content

Returns:



35
36
37
# File 'lib/coradoc/markdown/model/math.rb', line 35

def self.block(content)
  new(content: content, inline: false)
end

.inline(content) ⇒ Math

Create an inline math element

Parameters:

  • content (String)

    The math content

Returns:



28
29
30
# File 'lib/coradoc/markdown/model/math.rb', line 28

def self.inline(content)
  new(content: content, inline: true)
end

Instance Method Details

#inline?Boolean

Check if this is inline math

Returns:

  • (Boolean)


21
22
23
# File 'lib/coradoc/markdown/model/math.rb', line 21

def inline?
  inline == true
end

#to_mdString

Convert to Markdown

Returns:

  • (String)


41
42
43
44
45
46
47
# File 'lib/coradoc/markdown/model/math.rb', line 41

def to_md
  if inline?
    "$$#{content}$$"
  else
    "$$\n#{content}\n$$"
  end
end