Class: Slamdown::Conversion::Rendering::Html
- Inherits:
-
Object
- Object
- Slamdown::Conversion::Rendering::Html
- Defined in:
- lib/slamdown/conversion/rendering/html.rb
Overview
Reconstructs canonical HTML islands solely from normalised nodes and post-policy attributes.
Constant Summary collapse
- SEMANTIC_TAGS =
{ :paragraph => "p", :blockquote => "blockquote", :ordered_list => "ol", :unordered_list => "ul", :list_item => "li", :definition_list => "dl", :definition_term => "dt", :definition_description => "dd", :horizontal_rule => "hr", :line_break => "br", :code_span => "code", :code_block => "pre", :link => "a", :image => "img", :emphasis => "em", :strong => "strong", :deletion => "del", :table => "table", :table_head => "thead", :table_body => "tbody", :table_foot => "tfoot", :table_row => "tr", :table_cell => "td", :table_caption => "caption", :table_colgroup => "colgroup", :table_column => "col" }.freeze
- BLOCK_TAGS =
%w[address article aside blockquote div dl fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hr li main nav ol p pre section table thead tbody tfoot tr td th ul].freeze
- VOID_TAGS =
%w[area base br col embed hr img input link meta param source track wbr].freeze
Instance Method Summary collapse
-
#initialize(configuration, entity_encoder) ⇒ Html
constructor
A new instance of Html.
- #render(node) ⇒ Object
- #render_inline(node) ⇒ Object
Constructor Details
#initialize(configuration, entity_encoder) ⇒ Html
Returns a new instance of Html.
40 41 42 43 44 |
# File 'lib/slamdown/conversion/rendering/html.rb', line 40 def initialize(configuration, entity_encoder) @indent = configuration.html_indent @inline = configuration.inline @entity_encoder = entity_encoder end |
Instance Method Details
#render(node) ⇒ Object
46 47 48 |
# File 'lib/slamdown/conversion/rendering/html.rb', line 46 def render(node) block_node?(node) ? render_block(node, 0) : render_inline(node) end |
#render_inline(node) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/slamdown/conversion/rendering/html.rb', line 50 def render_inline(node) return escape_text(node.value) if node.kind == :text return render_entity(node) if entity_leaf?(node) tag = tag_for(node) return node.children.map { |child| render_inline(child) }.join unless tag return start_tag(node, tag, true) if void_tag?(tag) return render_code_span(node, tag) if node.semantic_kind == :code_span "#{start_tag(node, tag)}#{node.children.map { |child| render_inline(child) }.join}</#{tag}>" end |