Module: ReverseMarkdown

Defined in:
lib/reverse_markdown.rb,
lib/reverse_markdown/config.rb,
lib/reverse_markdown/errors.rb,
lib/reverse_markdown/cleaner.rb,
lib/reverse_markdown/version.rb,
lib/reverse_markdown/converters.rb,
lib/reverse_markdown/converters/a.rb,
lib/reverse_markdown/converters/h.rb,
lib/reverse_markdown/converters/p.rb,
lib/reverse_markdown/converters/br.rb,
lib/reverse_markdown/converters/em.rb,
lib/reverse_markdown/converters/hr.rb,
lib/reverse_markdown/converters/li.rb,
lib/reverse_markdown/converters/ol.rb,
lib/reverse_markdown/converters/td.rb,
lib/reverse_markdown/converters/tr.rb,
lib/reverse_markdown/converters/del.rb,
lib/reverse_markdown/converters/div.rb,
lib/reverse_markdown/converters/img.rb,
lib/reverse_markdown/converters/pre.rb,
lib/reverse_markdown/converters/base.rb,
lib/reverse_markdown/converters/code.rb,
lib/reverse_markdown/converters/drop.rb,
lib/reverse_markdown/converters/text.rb,
lib/reverse_markdown/converters/table.rb,
lib/reverse_markdown/converters/bypass.rb,
lib/reverse_markdown/converters/ignore.rb,
lib/reverse_markdown/converters/strong.rb,
lib/reverse_markdown/converters/details.rb,
lib/reverse_markdown/converters/blockquote.rb,
lib/reverse_markdown/converters/pass_through.rb

Defined Under Namespace

Modules: Converters Classes: Cleaner, Config, Error, InvalidConfigurationError, UnknownTagError

Constant Summary collapse

VERSION =
'2.0.0'

Class Method Summary collapse

Class Method Details

.cleanerObject


58
59
60
# File 'lib/reverse_markdown.rb', line 58

def self.cleaner
  @cleaner ||= Cleaner.new
end

.config {|@config| ... } ⇒ Object

Yields:


52
53
54
55
56
# File 'lib/reverse_markdown.rb', line 52

def self.config
  @config ||= Config.new
  yield @config if block_given?
  @config
end

.convert(input, options = {}) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/reverse_markdown.rb', line 35

def self.convert(input, options = {})
  config.with(options) do
    input = cleaner.force_encoding(input.to_s)

    root = case input
      when String                  then Nokogiri::HTML(input).root
      when Nokogiri::XML::Document then input.root
      when Nokogiri::XML::Node     then input
    end

    root or return ''

    result = ReverseMarkdown::Converters.lookup(root.name).convert(root)
    cleaner.tidy(result)
  end
end