Class: Docco::Parser::Renderer

Inherits:
Kramdown::Converter::Html
  • Object
show all
Defined in:
lib/docco/parser.rb

Overview

Subclasses Kramdown’s HTML converter so we can capture each top-level child’s rendered HTML during a single top-down walk. Overriding only convert_root lets Kramdown drive the recursion normally (so @stack, @footnotes, @used_ids, etc. behave as designed); we just replace the root-level concatenation step with a per-child capture into a hash keyed by Kramdown element identity.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, options) ⇒ Renderer

Returns a new instance of Renderer.



16
17
18
19
# File 'lib/docco/parser.rb', line 16

def initialize(root, options)
  super
  @per_element_html = {}
end

Instance Attribute Details

#per_element_htmlObject (readonly)

Returns the value of attribute per_element_html.



14
15
16
# File 'lib/docco/parser.rb', line 14

def per_element_html
  @per_element_html
end

Instance Method Details

#convert_root(el, indent) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/docco/parser.rb', line 21

def convert_root(el, indent)
  @stack.push(el)
  indent += @indent
  el.children.each do |child|
    @per_element_html[child] = send(@dispatcher[child.type], child, indent)
  end
  @stack.pop
  ''
end