Class: Charming::Presentation::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).



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

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`.



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

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