Class: Sourcerer::MarkDownGrade::DlPassthrough

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

Overview

Definition list passthrough/converter: converts DL blocks to Markdown by default. DL blocks with .to-markdown class (or a parent div with that class) are converted to Markdown. Supports global conversion via convert_dls_to_markdown config or dls-to-markdown frontmatter key. Per-node .to-markdown and .no-markdown classes override the global mode. In AsciiDoc html5 output, [.to-markdown] on a dlist places the class on the outer

.

Instance Method Summary collapse

Instance Method Details

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



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/sourcerer/mark_down_grade.rb', line 150

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

  has_to_markdown = check_class_on_node(node, 'to-markdown')
  has_no_markdown = check_class_on_node(node, 'no-markdown')

  # Also check parent <div> wrapper (html5 backend wraps dl in <div class="dlist ...">)
  parent = node.parent
  if parent && parent.name == 'div'
    has_to_markdown ||= check_class_on_node(parent, 'to-markdown')
    has_no_markdown ||= check_class_on_node(parent, 'no-markdown')
  end

  should_convert = if has_no_markdown
                     false
                   elsif has_to_markdown
                     true
                   else
                     global_mode
                   end

  if should_convert
    body = node.children.map { |child| treat(child, state) }.join.strip
    "#{body}\n"
  else
    "#{node.to_html}\n"
  end
end