Class: ReverseMarkdown::Converters::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/reverse_markdown/converters/text.rb

Instance Method Summary collapse

Methods inherited from Base

#escape_keychars, #extract_title, #treat, #treat_children

Instance Method Details

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



4
5
6
7
8
9
10
# File 'lib/reverse_markdown/converters/text.rb', line 4

def convert(node, options = {})
  if node.text.strip.empty?
    treat_empty(node)
  else
    treat_text(node)
  end
end

#treat_empty(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/reverse_markdown/converters/text.rb', line 12

def treat_empty(node)
  parent = node.parent.name.to_sym
  if [:ol, :ul].include?(parent)  # Otherwise the identation is broken
    ''
  elsif node.text == ' '          # Regular whitespace text node
    ' '
  else
    ''
  end
end

#treat_text(node) ⇒ Object



23
24
25
# File 'lib/reverse_markdown/converters/text.rb', line 23

def treat_text(node)
  escape_keychars node.text.tr("\n\t", '').squeeze(' ')
end