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

) and html5s (class on parent
). Per-table classes (.to-markdown, .no-markdown) override the global conversion mode.

Horizontal dlists ([horizontal]) render as a classless

inside a

, not as a
, so they're intercepted here rather than by DlPassthrough. They follow the DL conversion mode/overrides (not the table mode), converting each hdlist1/hdlist2 row to "**Term:** Description" instead of a Markdown table.

Instance Method Summary collapse

Constructor Details

#initializeTablePassthrough

Returns a new instance of TablePassthrough.



473
474
475
476
# File 'lib/sourcerer/mark_down_grade.rb', line 473

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

Instance Method Details

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



478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/sourcerer/mark_down_grade.rb', line 478

def convert node, state={}
  return convert_hdlist(node, state) if hdlist_table?(node)

  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