Class: TipTap::Markdown::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/tip_tap/markdown_renderable.rb

Overview

Rendering context for markdown serialization. Tracks indentation for nested blocks and whether we are currently inside a fenced code block so nodes can adjust formatting.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indent: 0, within_code_block: false) ⇒ Context

Returns a new instance of Context.



11
12
13
14
# File 'lib/tip_tap/markdown_renderable.rb', line 11

def initialize(indent: 0, within_code_block: false)
  @indent = indent
  @within_code_block = within_code_block
end

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



9
10
11
# File 'lib/tip_tap/markdown_renderable.rb', line 9

def indent
  @indent
end

#within_code_blockObject (readonly)

Returns the value of attribute within_code_block.



9
10
11
# File 'lib/tip_tap/markdown_renderable.rb', line 9

def within_code_block
  @within_code_block
end

Class Method Details

.rootObject



16
17
18
# File 'lib/tip_tap/markdown_renderable.rb', line 16

def self.root
  new
end

Instance Method Details

#increase_indent(amount) ⇒ Object



24
25
26
# File 'lib/tip_tap/markdown_renderable.rb', line 24

def increase_indent(amount)
  self.class.new(indent: indent + amount, within_code_block: within_code_block)
end

#indentationObject



20
21
22
# File 'lib/tip_tap/markdown_renderable.rb', line 20

def indentation
  " " * indent
end

#with_code_blockObject



28
29
30
# File 'lib/tip_tap/markdown_renderable.rb', line 28

def with_code_block
  self.class.new(indent: indent, within_code_block: true)
end

#within_code_block?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/tip_tap/markdown_renderable.rb', line 32

def within_code_block?
  within_code_block
end