pandoc-ruby 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +19 -8
- data/VERSION +1 -1
- data/lib/pandoc-ruby.rb +12 -2
- data/pandoc-ruby.gemspec +2 -2
- data/test/test_pandoc-ruby.rb +12 -0
- metadata +2 -2
data/README.markdown
CHANGED
@@ -15,24 +15,24 @@ Next, install PandocRuby from [gemcutter](http://gemcutter.org/gems/pandoc-ruby)
|
|
15
15
|
## Usage
|
16
16
|
|
17
17
|
require 'pandoc-ruby'
|
18
|
-
@converter = PandocRuby.new('
|
18
|
+
@converter = PandocRuby.new('# Markdown Title', :from => :markdown, :to => :rst)
|
19
19
|
puts @converter.convert
|
20
20
|
|
21
|
-
This takes the Markdown formatted file and converts it to reStructuredText.
|
21
|
+
This takes the Markdown formatted file and converts it to reStructuredText.
|
22
22
|
|
23
23
|
You can also use the `#convert` class method:
|
24
24
|
|
25
|
-
puts PandocRuby.convert('
|
25
|
+
puts PandocRuby.convert('# Markdown Title', :from => :markdown, :to => :html)
|
26
26
|
|
27
27
|
When no options are passed, pandoc's default behavior converts markdown to html. To specify options, simply pass options as a hash to the initializer. Pandoc's wrapper executables can also be used by passing the executable name as the second argument. For example,
|
28
28
|
|
29
|
-
PandocRuby.new('
|
29
|
+
PandocRuby.new('<p>Some <em>HTML</em></p>', 'html2markdown')
|
30
30
|
|
31
31
|
will use Pandoc's `html2markdown` wrapper.
|
32
32
|
|
33
33
|
Other arguments are simply converted into command line options, accepting symbols or strings for options without arguments and hashes of strings or symbols for options with arguments.
|
34
34
|
|
35
|
-
PandocRuby.convert('
|
35
|
+
PandocRuby.convert('# Markdown Title', :s, {:f => :markdown, :to => :rst}, 'no-wrap', :table_of_contents)
|
36
36
|
|
37
37
|
is equivalent to
|
38
38
|
|
@@ -43,8 +43,8 @@ Also provided are `#to_[writer]` instance methods for each of the writers, and t
|
|
43
43
|
PandocRuby.new("# Some title").to_html(:no_wrap)
|
44
44
|
=> "<div id=\"some-title\"><h1>Some title</h1></div>"
|
45
45
|
# or
|
46
|
-
PandocRuby.new("# Some title").
|
47
|
-
=> "
|
46
|
+
PandocRuby.new("# Some title").to_rst
|
47
|
+
=> "Some title\n=========="
|
48
48
|
|
49
49
|
Similarly, there are class methods for each of the readers, so readers and writers can be specified like this:
|
50
50
|
|
@@ -54,14 +54,25 @@ Similarly, there are class methods for each of the readers, so readers and write
|
|
54
54
|
PandocRuby assumes the pandoc executables are in the path. If not, set their location
|
55
55
|
with `PandocRuby.bin_path = '/path/to/bin'`
|
56
56
|
|
57
|
+
Pandoc can also be set to take a file path as the first argument. For security reasons, this is disabled by default, but it can be enabled and used as follows
|
58
|
+
|
59
|
+
PandocRuby.allow_file_paths = true
|
60
|
+
PandocRuby.html('/some/file.html').to_markdown
|
61
|
+
|
57
62
|
Available format readers and writers are available in the `PandocRuby::READERS` and `PandocRuby::WRITERS` constants.
|
58
63
|
|
59
|
-
For more information on Pandoc, see the [Pandoc documentation](http://johnmacfarlane.net/pandoc/) or run `man pandoc
|
64
|
+
For more information on Pandoc, see the [Pandoc documentation](http://johnmacfarlane.net/pandoc/) or run `man pandoc` ([also available here](http://johnmacfarlane.net/pandoc/pandoc.1.html)).
|
60
65
|
|
61
66
|
If you'd prefer a pure-Ruby extended markdown interpreter that can output a few different formats, take a look at [Maruku](http://maruku.rubyforge.org/). If you want to use the full reStructuredText syntax from within Ruby, check out [RbST](http://rdoc.info/projects/autodata/rbst), a docutils wrapper.
|
62
67
|
|
63
68
|
This gem was inspired by [Albino](http://github.com/github/albino). For a slightly different approach to using Pandoc with Ruby, see [Pandoku](http://github.com/dahlia/pandoku).
|
64
69
|
|
70
|
+
## Pandoc Hint
|
71
|
+
|
72
|
+
If you are trying to generate a standalone file with full file headers rather than just a marked up fragment, remember to pass the `:standalone` option so the correct header and footer are added.
|
73
|
+
|
74
|
+
PandocRuby.new("# Some title", :standalone).to_rtf
|
75
|
+
|
65
76
|
## Caveats
|
66
77
|
|
67
78
|
* This has only been tested on \*nix systems.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/pandoc-ruby.rb
CHANGED
@@ -2,6 +2,8 @@ require 'open3'
|
|
2
2
|
|
3
3
|
class PandocRuby
|
4
4
|
@@bin_path = nil
|
5
|
+
@@allow_file_paths = false
|
6
|
+
|
5
7
|
EXECUTABLES = %W[
|
6
8
|
pandoc
|
7
9
|
markdown2pdf
|
@@ -34,14 +36,22 @@ class PandocRuby
|
|
34
36
|
def self.bin_path=(path)
|
35
37
|
@@bin_path = path
|
36
38
|
end
|
37
|
-
|
39
|
+
|
40
|
+
def self.allow_file_paths=(value)
|
41
|
+
@@allow_file_paths = value
|
42
|
+
end
|
43
|
+
|
38
44
|
def self.convert(*args)
|
39
45
|
new(*args).convert
|
40
46
|
end
|
41
47
|
|
42
48
|
def initialize(*args)
|
43
49
|
target = args.shift
|
44
|
-
@target
|
50
|
+
@target = if @@allow_file_paths && File.exists?(target)
|
51
|
+
File.read(target)
|
52
|
+
else
|
53
|
+
target rescue target
|
54
|
+
end
|
45
55
|
@executable = EXECUTABLES.include?(args[0]) ? args.shift : 'pandoc'
|
46
56
|
@options = args
|
47
57
|
end
|
data/pandoc-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pandoc-ruby}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["William Melody"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-10}
|
13
13
|
s.description = %q{Ruby wrapper for Pandoc}
|
14
14
|
s.email = %q{wmelody@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_pandoc-ruby.rb
CHANGED
@@ -9,6 +9,7 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
def teardown
|
11
11
|
PandocRuby.bin_path = nil
|
12
|
+
PandocRuby.allow_file_paths = false
|
12
13
|
end
|
13
14
|
|
14
15
|
should "call bare pandoc when passed no options" do
|
@@ -25,6 +26,16 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
25
26
|
assert converter.convert
|
26
27
|
end
|
27
28
|
|
29
|
+
should "treat file paths as strings by default" do
|
30
|
+
assert_equal "<p\n>#{@file}</p\n>", PandocRuby.new(@file).to_html
|
31
|
+
end
|
32
|
+
|
33
|
+
should "treat file paths as file paths when enabled" do
|
34
|
+
PandocRuby.allow_file_paths = true
|
35
|
+
assert PandocRuby.new(@file).to_html.match(%r{This is a Title})
|
36
|
+
end
|
37
|
+
|
38
|
+
|
28
39
|
should "accept short options" do
|
29
40
|
@converter.expects(:execute).with('pandoc -t rst').returns(true)
|
30
41
|
assert @converter.convert
|
@@ -128,5 +139,6 @@ class TestPandocRuby < Test::Unit::TestCase
|
|
128
139
|
's5' => 'S5 HTML and javascript slide show',
|
129
140
|
'rtf' => 'rich text format'
|
130
141
|
}
|
142
|
+
|
131
143
|
end
|
132
144
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandoc-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Melody
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-10 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|