Class: Moft::Converters::Markdown::RDiscountParser
- Inherits:
-
Object
- Object
- Moft::Converters::Markdown::RDiscountParser
- Defined in:
- lib/moft/converters/markdown/rdiscount_parser.rb
Instance Method Summary collapse
- #convert(content) ⇒ Object
-
#initialize(config) ⇒ RDiscountParser
constructor
A new instance of RDiscountParser.
Constructor Details
#initialize(config) ⇒ RDiscountParser
Returns a new instance of RDiscountParser.
5 6 7 8 9 10 11 12 13 |
# File 'lib/moft/converters/markdown/rdiscount_parser.rb', line 5 def initialize(config) require 'rdiscount' @config = config @rdiscount_extensions = @config['rdiscount']['extensions'].map { |e| e.to_sym } rescue LoadError STDERR.puts 'You are missing a library required for Markdown. Please run:' STDERR.puts ' $ [sudo] gem install rdiscount' raise FatalException.new("Missing dependency: rdiscount") end |
Instance Method Details
#convert(content) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/moft/converters/markdown/rdiscount_parser.rb', line 15 def convert(content) rd = RDiscount.new(content, *@rdiscount_extensions) html = rd.to_html if rd.generate_toc and html.include?(@config['rdiscount']['toc_token']) html.gsub!(@config['rdiscount']['toc_token'], rd.toc_content.force_encoding('utf-8')) end html end |