Module: RbbCode::BlockquoteNode

Includes:
RecursiveConversion
Defined in:
lib/rbbcode/node_extensions.rb

Instance Method Summary collapse

Methods included from RecursiveConversion

#recursively_convert

Instance Method Details

#to_html(options) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rbbcode/node_extensions.rb', line 73

def to_html(options)
  # Detect paragraph breaks and wrap the result in <blockquote> tags.

  paragraphs = []
  cur_para = ''
  lines.elements.each do |line|
    inner = recursively_convert(line, :to_html, options)
    unless inner.blank?
      cur_para << inner
      if line.post_breaks == 1
        cur_para << ' '
      elsif line.post_breaks >= 2
        paragraphs << cur_para
        cur_para = ''
      end
    end
  end
  unless cur_para.blank?
    paragraphs << cur_para
  end
  inner = paragraphs.map { |str| "<p>#{str}</p>" }.join("\n")
  "\n<blockquote>" + inner + "</blockquote>\n"
end

#to_markdown(options) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/rbbcode/node_extensions.rb', line 96

def to_markdown(options)
  # Add a > character per line, preserving linebreaks as they are in the source.

  # Then append two newlines.

  '> ' + lines.elements.inject('') do |output, line|
    inner_markdown = recursively_convert(line.contents, :to_markdown, options)
    output + inner_markdown + ("\n> " * line.post_breaks)
  end + "\n\n"
end