Class: Jekyll::Converters::Textile

Inherits:
Converter
  • Object
show all
Defined in:
lib/jekyll/converters/textile.rb

Constant Summary collapse

DEFAULT_CONFIGURATION =
{
  'textile_ext' => 'textile',
  'redcloth' => {
    'hard_breaks' => true
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Textile

Returns a new instance of Textile.



16
17
18
19
# File 'lib/jekyll/converters/textile.rb', line 16

def initialize(config = {})
  @config = Jekyll::Utils.deep_merge_hashes(DEFAULT_CONFIGURATION, config)
  @setup = false
end

Instance Method Details

#convert(content) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jekyll/converters/textile.rb', line 43

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_listObject



31
32
33
# File 'lib/jekyll/converters/textile.rb', line 31

def extname_list
  @extname_list ||= @config['textile_ext'].split(',').map { |e| ".#{e}" }
end

#matches(ext) ⇒ Object



35
36
37
# File 'lib/jekyll/converters/textile.rb', line 35

def matches(ext)
  extname_list.include? ext.downcase
end

#output_ext(ext) ⇒ Object



39
40
41
# File 'lib/jekyll/converters/textile.rb', line 39

def output_ext(ext)
  ".html"
end

#setupObject



21
22
23
24
25
26
27
28
29
# File 'lib/jekyll/converters/textile.rb', line 21

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