lib/reverse_markdown.rb in reverse_markdown-0.4.7 vs lib/reverse_markdown.rb in reverse_markdown-0.5.0
- old
+ new
@@ -1,24 +1,56 @@
require 'digest'
+require 'nokogiri'
require 'reverse_markdown/version'
-require 'reverse_markdown/mapper'
require 'reverse_markdown/errors'
-require 'nokogiri'
+require 'reverse_markdown/cleaner'
+require 'reverse_markdown/config'
+require 'reverse_markdown/converters'
+require 'reverse_markdown/converters/base'
+require 'reverse_markdown/converters/a'
+require 'reverse_markdown/converters/blockquote'
+require 'reverse_markdown/converters/br'
+require 'reverse_markdown/converters/code'
+require 'reverse_markdown/converters/div'
+require 'reverse_markdown/converters/dump'
+require 'reverse_markdown/converters/em'
+require 'reverse_markdown/converters/h'
+require 'reverse_markdown/converters/hr'
+require 'reverse_markdown/converters/img'
+require 'reverse_markdown/converters/li'
+require 'reverse_markdown/converters/ol'
+require 'reverse_markdown/converters/p'
+require 'reverse_markdown/converters/pass_through'
+require 'reverse_markdown/converters/pre'
+require 'reverse_markdown/converters/strong'
+require 'reverse_markdown/converters/table'
+require 'reverse_markdown/converters/td'
+require 'reverse_markdown/converters/tr'
+require 'reverse_markdown/converters/text'
module ReverseMarkdown
- def self.parse(input, opts={})
+ def self.convert(input, options = {})
root = case input
when String then Nokogiri::HTML(input).root
when Nokogiri::XML::Document then input.root
when Nokogiri::XML::Node then input
end
- ReverseMarkdown::Mapper.new(opts).process_root(root)
+ root or return ''
+ config.apply(options)
+ result = ReverseMarkdown::Converters.lookup(root.name).convert(root)
+ config.reset
+ cleaner.tidy(result)
end
- # 2012/08/11 joe: possibly deprecate in favour of #parse
- class << self
- alias parse_string parse
- alias parse_element parse
+ def self.config
+ @config ||= Config.new
+ yield @config if block_given?
+ @config
end
+
+ def self.cleaner
+ @cleaner ||= Cleaner.new
+ end
+
end