class Md2Cnblog::BaseTranslator
Attributes
markdown[R]
options[R]
output[R]
render[RW]
Public Class Methods
new(str, options={}, render=nil)
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 6 def initialize(str, options={}, render=nil) @str ||= str if valide_str?(str) @options = default_options.merge(options) if valide_option?(options) @render = render || default_render @markdown = ::Redcarpet::Markdown.new(@render, @options) end
Public Instance Methods
default_options()
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 23 def default_options { no_intra_emphasis: true, autolink: true, space_after_headers: true, fenced_code_blocks: true } end
default_render()
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 30 def default_render Redcarpet::Render::HTML.new() end
echo()
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 43 def echo print @output end
start()
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 34 def start start_mute echo end
start_mute()
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 39 def start_mute @output = @markdown.render(@str) end
valide_option?(options)
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 18 def valide_option?(options) raise InvalidOptionsError unless options.is_a?(Hash) true end
valide_str?(str)
click to toggle source
# File lib/md2cnblog/base_translator.rb, line 13 def valide_str?(str) raise InvalidInputError unless str.is_a?(String) true end