Class: Sourcerer::MarkDownGrade::DdConverter

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

Overview

Definition description converter: indents definition content by 3 spaces for Markdown. Block-level elements (lists, code blocks, etc.) within a definition are indented as-is, preserving their internal structure while still visually nesting under the term.

Instance Method Summary collapse

Instance Method Details

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



198
199
200
201
202
203
204
205
# File 'lib/sourcerer/mark_down_grade.rb', line 198

def convert node, state={}
  content = treat_children(node, state).strip
  # Indent non-blank lines of the definition by 3 spaces (works for both inline and
  # block content); blank lines are left empty so they stay collapsible as paragraph
  # breaks instead of becoming whitespace-only lines that pile up under nesting.
  indented = content.split("\n").map { |line| line.strip.empty? ? '' : "   #{line}" }.join("\n")
  "#{indented}\n\n"
end