Class: DocsKit::MarkdownExport::Blocks

Inherits:
Object
  • Object
show all
Defined in:
lib/docs_kit/markdown_export/blocks.rb

Overview

The Nokogiri → GFM visitor. Splits into two passes over the bounded kit vocabulary: block-level elements (this class) produce Markdown lines separated by blank lines; inline elements (Inline) produce a single run of text. Unknown block elements recurse into their children (text survives, the wrapper is dropped), matching the issue's "recurse into children" rule.

Constant Summary collapse

HEADINGS =
{ "h1" => "#", "h2" => "##", "h3" => "###", "h4" => "####" }.freeze
LIST_TAGS =
%w[ul ol].freeze

Instance Method Summary collapse

Constructor Details

#initialize(export) ⇒ Blocks

Returns a new instance of Blocks.



14
15
16
17
# File 'lib/docs_kit/markdown_export/blocks.rb', line 14

def initialize(export)
  @export = export
  @inline = Inline.new(export)
end

Instance Method Details

#render(node) ⇒ Object

Render a container's block children, joined by blank lines. Blocks that yield nothing (whitespace-only text nodes) are dropped so no stray blank lines accumulate.



22
23
24
25
26
# File 'lib/docs_kit/markdown_export/blocks.rb', line 22

def render(node)
  node.children.filter_map { |child| block(child) }
               .reject(&:empty?)
      .join("\n\n")
end