Class: Charming::Markdown::BlockRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/markdown/block_renderers.rb

Overview

BlockRenderer dispatches Kramdown block-level elements (paragraph, header, list, code block, etc.) to their individual rendering handlers. Handlers are built once at construction time as a frozen hash of element-type symbols to callables.

Instance Method Summary collapse

Constructor Details

#initialize(renderer:) ⇒ BlockRenderer

renderer is the parent Renderer (used to wrap text, render inlines, and look up styles).



10
11
12
13
# File 'lib/charming/presentation/markdown/block_renderers.rb', line 10

def initialize(renderer:)
  @renderer = renderer
  build_handlers
end

Instance Method Details

#render(element, context:) ⇒ Object

Renders element using the handler registered for ‘element.type`. Unknown types fall through to `render_unknown`.



17
18
19
20
# File 'lib/charming/presentation/markdown/block_renderers.rb', line 17

def render(element, context:)
  handler = @handlers[element.type] || method(:render_unknown)
  handler.call(element, context)
end