forked from fauno/jekyll-pandoc-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pandoc_markdown.rb
76 lines (67 loc) · 1.96 KB
/
pandoc_markdown.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
module Jekyll
module Converters
class Markdown < Converter
safe true
pygments_prefix "\n"
pygments_suffix "\n"
def setup
return if @setup
@parser = case @config['markdown']
when 'redcarpet'
RedcarpetParser.new @config
when 'kramdown'
KramdownParser.new @config
when 'rdiscount'
RDiscountParser.new @config
when 'maruku'
MarukuParser.new @config
when 'pandoc'
PandocParser.new @config
else
STDERR.puts "Invalid Markdown processor: #{@config['markdown']}"
STDERR.puts " Valid options are [ maruku | rdiscount | kramdown ]"
raise FatalException.new("Invalid Markdown process: #{@config['markdown']}")
end
@setup = true
end
def matches(ext)
rgx = '(' + @config['markdown_ext'].gsub(',','|') +')'
ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
end
def output_ext(ext)
".html"
end
def convert(content)
setup
@parser.convert(content)
end
end
end
end
module Jekyll
module Converters
class Markdown
class PandocParser
def initialize(config)
require 'pandoc-ruby'
@config = config
rescue LoadError
STDERR.puts 'You are missing a library required for Pandoc. Please run:'
STDERR.puts ' $ [sudo] gem install pandoc-ruby'
raise FatalException.new("Missing dependency: pandoc-ruby")
end
def convert(content)
extensions = config_option('extensions', [])
format = config_option('format', 'html5')
PandocRuby.new(content, *extensions).send("to_#{format}")
end
def config_option(key, default=nil)
case @config['pandoc']
when nil then default
else @config['pandoc'].fetch(key, default)
end
end
end
end
end
end