Class: Sourcerer::MarkDownGrade::TablePassthrough

Inherits:
ReverseMarkdown::Converters::Base
  • Object
show all
Defined in:
lib/sourcerer/mark_down_grade.rb

Overview

Passthrough Tables: preserve HTML tables as-is (except admonition internals handled elsewhere). Tables with “to-markdown” class are converted via ReverseMarkdown instead. Supports both html5 (class on <table>) and html5s (class on parent <div class=“table-block”>). Per-table classes (.to-markdown, .no-markdown) override the global conversion mode.

Instance Method Summary collapse

Constructor Details

#initializeTablePassthrough

Returns a new instance of TablePassthrough.



430
431
432
433
# File 'lib/sourcerer/mark_down_grade.rb', line 430

def initialize
  super
  @markdown_converter = ReverseMarkdown::Converters::Table.new
end

Instance Method Details

#convert(node, state = {}) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/sourcerer/mark_down_grade.rb', line 435

def convert node, state={}
  global_mode = Thread.current[:sourcerer_table_conversion_mode] || false

  # Check for per-table classes (on table or parent wrapper)
  has_to_markdown = check_class_on_node(node, 'to-markdown')
  has_no_markdown = check_class_on_node(node, 'no-markdown')

  # Also check parent <div class="table-block"> wrapper (html5s backend)
  parent_div = node.parent
  if parent_div && parent_div.name == 'div'
    has_to_markdown ||= check_class_on_node(parent_div, 'to-markdown')
    has_no_markdown ||= check_class_on_node(parent_div, 'no-markdown')
  end

  # Determine whether to convert (per-table classes override global mode)
  should_convert = if has_no_markdown
                     false # .no-markdown always prevents conversion
                   elsif has_to_markdown
                     true  # .to-markdown always forces conversion
                   else
                     global_mode # Use global table conversion mode
                   end

  if should_convert
    @markdown_converter.convert(node, state)
  else
    "#{node.to_html}\n"
  end
end