Sha256: b1a959225965d7171bc9f987f8e10c05e6fd9d378300a151e631ef0e8a4672eb

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

module Jekyll
  module Converters
    class Textile < Converter
      safe true

      highlighter_prefix '<notextile>'
      highlighter_suffix '</notextile>'

      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

      def extname_matches_regexp
        @extname_matches_regexp ||= Regexp.new(
          '(' + @config['textile_ext'].gsub(',','|') +')$',
          Regexp::IGNORECASE
        )
      end

      def matches(ext)
        ext =~ extname_matches_regexp
      end

      def output_ext(ext)
        ".html"
      end

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-2.5.3 lib/jekyll/converters/textile.rb
jekyll-2.5.2 lib/jekyll/converters/textile.rb
jekyll-2.5.1 lib/jekyll/converters/textile.rb
jekyll-2.5.0 lib/jekyll/converters/textile.rb