Class: Metanorma::Mirror::Output::HtmlRenderer

Constant Summary

Constants included from Metanorma::Mirror::Output::HtmlRenderers::TableRenderers

Metanorma::Mirror::Output::HtmlRenderers::TableRenderers::WRAPPER_TAGS

Constants included from Metanorma::Mirror::Output::HtmlRenderers::BlockRenderers

Metanorma::Mirror::Output::HtmlRenderers::BlockRenderers::ADMONITION_TITLES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Metanorma::Mirror::Output::HtmlRenderers::MarkRenderers

register

Methods included from Metanorma::Mirror::Output::HtmlRenderers::InlineRenderer

#apply_mark, register, #render_footnote_marker, #render_inline, #render_text_node

Methods included from Metanorma::Mirror::Output::HtmlRenderers::TableRenderers

register, #render_table, #render_table_section

Methods included from Metanorma::Mirror::Output::HtmlRenderers::ListRenderers

register, #render_bullet_list, #render_dd, #render_dl, #render_dt, #render_list_item, #render_ordered_list

Methods included from Metanorma::Mirror::Output::HtmlRenderers::BlockRenderers

register, #render_admonition, #render_example, #render_figure, #render_formula, #render_image, #render_note, #render_paragraph, #render_quote, #render_review, #render_sourcecode, #render_term

Methods included from Metanorma::Mirror::Output::HtmlRenderers::SectionRenderers

register, #render_annex, #render_clause, #render_content_section, #render_definitions, #render_floating_title, #render_heading, #render_references, #render_terms

Methods included from Metanorma::Mirror::Output::HtmlRenderers::StructuralRenderers

register, #render_bibliography, #render_doc, #render_footnotes, #render_preface, #render_sections, #render_soft_break

Constructor Details

#initialize(guide, numbering: {}) ⇒ HtmlRenderer

Returns a new instance of HtmlRenderer.



33
34
35
36
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 33

def initialize(guide, numbering: {})
  @content = extract_content(guide)
  @numbering = numbering
end

Class Method Details

.mark_handlersObject



20
21
22
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 20

def mark_handlers
  @mark_handlers ||= {}
end

.node_handlersObject



16
17
18
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 16

def node_handlers
  @node_handlers ||= {}
end

.register_mark_handler(mark_type, handler) ⇒ Object



28
29
30
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 28

def register_mark_handler(mark_type, handler)
  mark_handlers[mark_type] = handler
end

.register_node_handler(type, unbound_method) ⇒ Object



24
25
26
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 24

def register_node_handler(type, unbound_method)
  node_handlers[type] = unbound_method
end

Instance Method Details

#renderObject



38
39
40
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 38

def render
  render_nodes(@content)
end

#render_children(node, depth: 0) ⇒ Object



73
74
75
76
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 73

def render_children(node, depth: 0)
  children = node.is_a?(Model::Container) ? node.content : []
  render_nodes(children, depth:)
end

#render_generic(node, depth: 0) ⇒ Object



66
67
68
69
70
71
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 66

def render_generic(node, depth: 0)
  children = node.content if node.is_a?(Model::Container)
  return "" unless children && !children.empty?

  render_children(node, depth:)
end

#render_node(node, depth: 0) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 46

def render_node(node, depth: 0)
  case node
  when String
    HtmlRenderers.escape_text(node)
  when Model::Text
    render_text_node(node)
  when Model::Container, Model::Leaf, Model::SoftBreak
    render_typed_node(node, depth:)
  else
    ""
  end
end

#render_nodes(nodes, depth: 0) ⇒ Object



42
43
44
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 42

def render_nodes(nodes, depth: 0)
  nodes.filter_map { |node| render_node(node, depth:) }.join("\n")
end

#render_typed_node(node, depth: 0) ⇒ Object



59
60
61
62
63
64
# File 'lib/metanorma/mirror/output/html_renderer.rb', line 59

def render_typed_node(node, depth: 0)
  unbound = self.class.node_handlers[node.type]
  return unbound.bind_call(self, node, depth:) if unbound

  render_generic(node, depth:)
end