class Jekyll::Converters::Textile

Public Instance Methods

convert(content) click to toggle source
# File lib/jekyll/converters/textile.rb, line 34
def convert(content)
  setup

  # Shortcut if config doesn't contain RedCloth section
  return RedCloth.new(content).to_html if @config['redcloth'].nil?

  # List of attributes defined on RedCloth
  # (from https://github.com/jgarber/redcloth/blob/master/lib/redcloth/textile_doc.rb)
  attrs = ['filter_classes', 'filter_html', 'filter_ids', 'filter_styles',
          'hard_breaks', 'lite_mode', 'no_span_caps', 'sanitize_html']

  r = RedCloth.new(content)

  # Set attributes in r if they are NOT nil in the config
  attrs.each do |attr|
    r.instance_variable_set("@#{attr}".to_sym, @config['redcloth'][attr]) unless @config['redcloth'][attr].nil?
  end

  r.to_html
end
extname_matches_regexp() click to toggle source
# File lib/jekyll/converters/textile.rb, line 19
def extname_matches_regexp
  @extname_matches_regexp ||= Regexp.new(
    '(' + @config['textile_ext'].gsub(',','|') +')$',
    Regexp::IGNORECASE
  )
end
matches(ext) click to toggle source
# File lib/jekyll/converters/textile.rb, line 26
def matches(ext)
  ext =~ extname_matches_regexp
end
output_ext(ext) click to toggle source
# File lib/jekyll/converters/textile.rb, line 30
def output_ext(ext)
  ".html"
end
setup() click to toggle source
# File lib/jekyll/converters/textile.rb, line 9
def setup
  return if @setup
  require 'redcloth'
  @setup = true
rescue LoadError
  STDERR.puts 'You are missing a library required for Textile. Please run:'
  STDERR.puts '  $ [sudo] gem install RedCloth'
  raise Errors::FatalException.new("Missing dependency: RedCloth")
end