class Kramdown::Converter::PlainText
Converts tree to plain text. Removes all formatting and attributes. This converter can be used to generate clean text for use in meta tags, plain text emails, etc.
Public Class Methods
new(root, options)
click to toggle source
Calls superclass method
# File lib/liquid_markdown/converter/plain_text.rb, line 29 def initialize(root, options) super @plain_text = '' # bin for plain text end
Public Instance Methods
convert(el)
click to toggle source
# File lib/liquid_markdown/converter/plain_text.rb, line 34 def convert(el) type = el.type category = ::Kramdown::Element.category(el) @plain_text << convert_type(type, el) if TEXT_TYPES.include?(type) @plain_text << "\n" if category == :block el.children.each { |e| convert(e) } @plain_text.strip if type == :root end
convert_entity(el)
click to toggle source
# File lib/liquid_markdown/converter/plain_text.rb, line 54 def convert_entity(el) el.value.char end
convert_smart_quote(el)
click to toggle source
# File lib/liquid_markdown/converter/plain_text.rb, line 58 def convert_smart_quote(el) smart_quote_entity(el).char end
convert_text(el)
click to toggle source
# File lib/liquid_markdown/converter/plain_text.rb, line 50 def convert_text(el) el.value end
convert_type(type, el)
click to toggle source
# File lib/liquid_markdown/converter/plain_text.rb, line 46 def convert_type(type, el) send("convert_#{type}", el) end
convert_typographic_sym(el)
click to toggle source
# File lib/liquid_markdown/converter/plain_text.rb, line 62 def convert_typographic_sym(el) ::Kramdown::Converter::Html::TYPOGRAPHIC_SYMS[el.value] .map(&:char) .join('') end