Class: ReverseMarkdown::Converters::Base

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

Direct Known Subclasses

A, Blockquote, Br, Bypass, Code, Del, Details, Div, Drop, Em, H, Hr, Ignore, Img, Li, Ol, P, PassThrough, Pre, Strong, Table, Td, Text, Tr

Instance Method Summary collapse

Instance Method Details

#escape_keychars(string) ⇒ Object


14
15
16
# File 'lib/reverse_markdown/converters/base.rb', line 14

def escape_keychars(string)
  string.gsub(/(?<!\\)[*_]/, '*' => '\*', '_' => '\_')
end

#extract_title(node) ⇒ Object


18
19
20
21
# File 'lib/reverse_markdown/converters/base.rb', line 18

def extract_title(node)
  title = escape_keychars(node['title'].to_s)
  title.empty? ? '' : %[ "#{title}"]
end

#treat(node, state) ⇒ Object


10
11
12
# File 'lib/reverse_markdown/converters/base.rb', line 10

def treat(node, state)
  ReverseMarkdown::Converters.lookup(node.name).convert(node, state)
end

#treat_children(node, state) ⇒ Object


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

def treat_children(node, state)
  node.children.inject('') do |memo, child|
    memo << treat(child, state)
  end
end