Module: JekyllPandocMultipleFormats::ConverterMethods

Defined in:
lib/jekyll-pandoc-multiple-formats-jekyll34/converter.rb

Overview

When included in the correspondant markdown class this module redefines the three needed Converter instance methods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jekyll-pandoc-multiple-formats-jekyll34/converter.rb', line 44

def self.included(base)
  base.class_eval do
    # Just return html5
    def convert(content)
      flags  = "#{@config['pandoc']['flags']} #{@config['pandoc']['site_flags']}"

      output = ''
      Dir::chdir(@config['source']) do
        Open3::popen3("pandoc -t html5 #{flags}") do |stdin, stdout, stderr, thread|
          stdin.puts content
          stdin.close

          output = stdout.read.strip
          STDERR.print stderr.read

          # Wait for the process to finish
          thread.value
        end
      end

      output
    end

    def matches(ext)
      rgx = '(' + @config['markdown_ext'].gsub(',','|') +')'
      ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
    end

    def output_ext(ext)
      '.html'
    end
  end
end