pandoc-ruby 2.0.1 → 2.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +3 -2
- data/Gemfile.lock +40 -11
- data/README.md +71 -45
- data/Rakefile +33 -4
- data/lib/pandoc-ruby.rb +171 -85
- data/pandoc-ruby.gemspec +8 -31
- data/test/benchmark.rb +4 -4
- data/test/files/Test File 2.md +1 -0
- data/test/helper.rb +3 -3
- data/test/test_conversions.rb +52 -1
- data/test/test_pandoc_ruby.rb +328 -70
- metadata +12 -93
- /data/test/files/{test.md → Test File 1.md} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8e8ca5b1e67ee24b1ce6da71e7d66b79c01de59784bca75862c37463c8b7c149
|
4
|
+
data.tar.gz: f6beef0283cf065db5f496449230fbf70fee63e699ebc8b5e3002440c707df78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5389c2016eee54a1fd8d4238b0579c10ffc7ee35ee97a362eb90a44e6798aa9196674af80cb9abc3228db19aadd4e93e1ecf02d6229fd4231bd9bc947755b78
|
7
|
+
data.tar.gz: 2039942ca2d81756b3ce3077bcf1eb8c64347fe256d0c1ced34406f55028e84f788f289de484eb3c3350184a014c42c9b5ff54aed660ea74b0ef549398d8662b
|
data/Gemfile
CHANGED
@@ -6,8 +6,9 @@ source 'http://rubygems.org'
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development, :test do
|
9
|
-
gem 'minitest'
|
10
|
-
gem 'mocha'
|
9
|
+
gem 'minitest'
|
10
|
+
gem 'mocha'
|
11
11
|
gem 'rake'
|
12
12
|
gem 'rdoc'
|
13
|
+
gem 'rubocop'
|
13
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,52 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
ast (2.4.2)
|
5
|
+
json (2.6.3)
|
6
|
+
language_server-protocol (3.17.0.3)
|
7
|
+
minitest (5.20.0)
|
8
|
+
mocha (2.1.0)
|
9
|
+
ruby2_keywords (>= 0.0.5)
|
10
|
+
parallel (1.23.0)
|
11
|
+
parser (3.2.2.4)
|
12
|
+
ast (~> 2.4.1)
|
13
|
+
racc
|
14
|
+
psych (5.1.1.1)
|
15
|
+
stringio
|
16
|
+
racc (1.7.3)
|
17
|
+
rainbow (3.1.1)
|
18
|
+
rake (13.1.0)
|
19
|
+
rdoc (6.6.0)
|
20
|
+
psych (>= 4.0.0)
|
21
|
+
regexp_parser (2.8.2)
|
22
|
+
rexml (3.2.6)
|
23
|
+
rubocop (1.57.2)
|
24
|
+
json (~> 2.3)
|
25
|
+
language_server-protocol (>= 3.17.0)
|
26
|
+
parallel (~> 1.10)
|
27
|
+
parser (>= 3.2.2.4)
|
28
|
+
rainbow (>= 2.2.2, < 4.0)
|
29
|
+
regexp_parser (>= 1.8, < 3.0)
|
30
|
+
rexml (>= 3.2.5, < 4.0)
|
31
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
34
|
+
rubocop-ast (1.30.0)
|
35
|
+
parser (>= 3.2.1.0)
|
36
|
+
ruby-progressbar (1.13.0)
|
37
|
+
ruby2_keywords (0.0.5)
|
38
|
+
stringio (3.0.9)
|
39
|
+
unicode-display_width (2.5.0)
|
12
40
|
|
13
41
|
PLATFORMS
|
14
42
|
ruby
|
15
43
|
|
16
44
|
DEPENDENCIES
|
17
|
-
minitest
|
18
|
-
mocha
|
45
|
+
minitest
|
46
|
+
mocha
|
19
47
|
rake
|
20
48
|
rdoc
|
49
|
+
rubocop
|
21
50
|
|
22
51
|
BUNDLED WITH
|
23
|
-
|
52
|
+
2.2.28
|
data/README.md
CHANGED
@@ -1,74 +1,77 @@
|
|
1
1
|
# PandocRuby
|
2
2
|
|
3
|
+
[![Build Status](https://img.shields.io/github/actions/workflow/status/xwmx/pandoc-ruby/tests.yml?branch=master)](https://github.com/xwmx/pandoc-ruby/actions)
|
4
|
+
[![Gem Version](https://img.shields.io/gem/v/pandoc-ruby)](http://rubygems.org/gems/pandoc-ruby)
|
5
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/pandoc-ruby)](http://rubygems.org/gems/pandoc-ruby)
|
6
|
+
|
3
7
|
PandocRuby is a wrapper for [Pandoc](http://johnmacfarlane.net/pandoc/), a
|
4
8
|
Haskell library with command line tools for converting one markup format to
|
5
9
|
another.
|
6
10
|
|
7
|
-
Pandoc can convert documents
|
8
|
-
DocBook, LaTeX,
|
9
|
-
|
10
|
-
OpenDocument XML, ODT, GNU Texinfo, MediaWiki
|
11
|
-
HTML slide shows, EPUB,
|
12
|
-
|
13
|
-
*This documentation is for version 2 and higher. For version 1 documentation
|
14
|
-
[see here](https://github.com/alphabetum/pandoc-ruby/blob/v1.0.0/README.markdown).*
|
11
|
+
Pandoc can convert documents from a variety of formats including markdown,
|
12
|
+
reStructuredText, textile, HTML, DocBook, LaTeX, and MediaWiki markup to a
|
13
|
+
variety of other formats, including markdown, reStructuredText, HTML, LaTeX,
|
14
|
+
ConTeXt, PDF, RTF, DocBook XML, OpenDocument XML, ODT, GNU Texinfo, MediaWiki
|
15
|
+
markup, groff man pages, HTML slide shows, EPUB, Microsoft Word docx, and more.
|
15
16
|
|
16
17
|
## Installation
|
17
18
|
|
18
|
-
First,
|
19
|
-
[install Pandoc](http://johnmacfarlane.net/pandoc/installing.html).
|
19
|
+
First, [install Pandoc](http://johnmacfarlane.net/pandoc/installing.html).
|
20
20
|
|
21
|
-
|
21
|
+
PandocRuby is available on [RubyGems](http://rubygems.org/gems/pandoc-ruby):
|
22
22
|
|
23
|
-
```
|
24
|
-
gem
|
23
|
+
```bash
|
24
|
+
gem install pandoc-ruby
|
25
25
|
```
|
26
26
|
|
27
|
-
|
27
|
+
To install with [Bundler](https://bundler.io/), add the following to your
|
28
|
+
Gemfile:
|
28
29
|
|
29
|
-
```
|
30
|
-
gem
|
30
|
+
```ruby
|
31
|
+
gem 'pandoc-ruby'
|
31
32
|
```
|
32
33
|
|
34
|
+
Then run `bundle install`
|
35
|
+
|
33
36
|
## Usage
|
34
37
|
|
35
38
|
```ruby
|
36
39
|
require 'pandoc-ruby'
|
37
|
-
@converter = PandocRuby.new('# Markdown Title', :
|
40
|
+
@converter = PandocRuby.new('# Markdown Title', from: :markdown, to: :rst)
|
38
41
|
puts @converter.convert
|
39
42
|
```
|
40
43
|
|
41
|
-
This takes the Markdown formatted
|
44
|
+
This takes the Markdown formatted string and converts it to reStructuredText.
|
42
45
|
|
43
46
|
You can also use the `#convert` class method:
|
44
47
|
|
45
48
|
```ruby
|
46
|
-
puts PandocRuby.convert('# Markdown Title', :
|
49
|
+
puts PandocRuby.convert('# Markdown Title', from: :markdown, to: :html)
|
47
50
|
```
|
48
51
|
|
49
52
|
Other arguments are simply converted into command line options, accepting
|
50
|
-
symbols
|
51
|
-
symbols for options with arguments.
|
53
|
+
symbols and strings for options and hashes for options with arguments.
|
52
54
|
|
53
55
|
```ruby
|
54
|
-
PandocRuby.convert('# Markdown Title', :s, {:
|
56
|
+
PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, '--wrap=none', :table_of_contents)
|
55
57
|
```
|
56
58
|
|
57
59
|
is equivalent to
|
58
60
|
|
59
61
|
```bash
|
60
|
-
echo "# Markdown Title" | pandoc -s -f markdown --to=rst --
|
62
|
+
echo "# Markdown Title" | pandoc -s -f markdown --to=rst --wrap=none --table-of-contents
|
61
63
|
```
|
62
64
|
|
63
65
|
Also provided are `#to_[writer]` instance methods for each of the writers,
|
64
66
|
and these can also accept options:
|
65
67
|
|
66
68
|
```ruby
|
67
|
-
PandocRuby.new(
|
68
|
-
# => "<
|
69
|
+
PandocRuby.new('# Example').to_html(:ascii)
|
70
|
+
# => "<h1 id="example">Example</h1>"
|
69
71
|
# or
|
70
|
-
PandocRuby.new("#
|
71
|
-
# => "
|
72
|
+
PandocRuby.new("# Example").to_rst
|
73
|
+
# => "Example
|
74
|
+
# ======="
|
72
75
|
```
|
73
76
|
|
74
77
|
Similarly, there are class methods for each of the readers, so readers
|
@@ -79,23 +82,55 @@ PandocRuby.html("<h1>hello</h1>").to_latex
|
|
79
82
|
# => "\\section{hello}"
|
80
83
|
```
|
81
84
|
|
82
|
-
|
85
|
+
Available readers and writers are can be found in the following
|
86
|
+
variables:
|
87
|
+
- [`PandocRuby::READERS`](lib/pandoc-ruby.rb#L10)
|
88
|
+
- [`PandocRuby::STRING_WRITERS`](lib/pandoc-ruby.rb#L48)
|
89
|
+
- [`PandocRuby::BINARY_WRITERS`](lib/pandoc-ruby.rb#L104)
|
90
|
+
- [`PandocRuby::WRITERS`](lib/pandoc-ruby.rb#L113)
|
91
|
+
|
92
|
+
PandocRuby assumes the `pandoc` executable is in your environment's `$PATH`
|
83
93
|
variable. If you'd like to set an explicit path to the `pandoc` executable,
|
84
94
|
you can do so with `PandocRuby.pandoc_path = '/path/to/pandoc'`
|
85
95
|
|
96
|
+
### Converting Files
|
97
|
+
|
86
98
|
PandocRuby can also take an array of one or more file paths as the first
|
87
99
|
argument. The files will be concatenated together with a blank line between
|
88
100
|
each and used as input.
|
89
101
|
|
90
102
|
```ruby
|
91
103
|
# One file path as a single-element array.
|
92
|
-
PandocRuby.
|
104
|
+
PandocRuby.new(['/path/to/file1.docx'], from: 'docx').to_html
|
93
105
|
# Multiple file paths as an array.
|
94
|
-
PandocRuby.
|
106
|
+
PandocRuby.new(['/path/to/file1.docx', '/path/to/file1.docx'], from: 'docx').to_html
|
107
|
+
```
|
108
|
+
|
109
|
+
If you are trying to generate a standalone file with full file headers rather
|
110
|
+
than just a marked up fragment, remember to pass the `:standalone` option so
|
111
|
+
the correct header and footer are added.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
PandocRuby.new("# Some title", :standalone).to_rtf
|
115
|
+
```
|
116
|
+
|
117
|
+
### Extensions
|
118
|
+
|
119
|
+
Pandoc [extensions](https://pandoc.org/MANUAL.html#extensions) can be
|
120
|
+
used to modify the behavior of readers and writers. To use an extension,
|
121
|
+
add the extension with a `+` or `-` after the reader or writer name:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# Without extension:
|
125
|
+
PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict').to_html
|
126
|
+
# => "<p>Line 1</p>\n<h1>Heading</h1>\n"
|
127
|
+
|
128
|
+
# With `+blank_before_header` extension:
|
129
|
+
PandocRuby.new("Line 1\n# Heading", from: 'markdown_strict+blank_before_header').to_html
|
130
|
+
# => "<p>Line 1 # Heading</p>\n
|
95
131
|
```
|
96
132
|
|
97
|
-
|
98
|
-
and `PandocRuby::WRITERS` constants.
|
133
|
+
### More Information
|
99
134
|
|
100
135
|
For more information on Pandoc, see the
|
101
136
|
[Pandoc documentation](http://johnmacfarlane.net/pandoc/)
|
@@ -103,24 +138,15 @@ or run `man pandoc`
|
|
103
138
|
([also available here](http://johnmacfarlane.net/pandoc/pandoc.1.html)).
|
104
139
|
|
105
140
|
If you'd prefer a pure-Ruby extended markdown interpreter that can output a
|
106
|
-
few different formats, take a look at
|
107
|
-
If you want to use the full
|
108
|
-
|
141
|
+
few different formats, take a look at
|
142
|
+
[kramdown](https://kramdown.gettalong.org/). If you want to use the full
|
143
|
+
reStructuredText syntax from within Ruby, check out
|
144
|
+
[RbST](https://github.com/xwmx/rbst), a docutils wrapper.
|
109
145
|
|
110
146
|
This gem was inspired by [Albino](http://github.com/github/albino). For a
|
111
147
|
slightly different approach to using Pandoc with Ruby, see
|
112
148
|
[Pandoku](http://github.com/dahlia/pandoku).
|
113
149
|
|
114
|
-
## Additional Notes
|
115
|
-
|
116
|
-
If you are trying to generate a standalone file with full file headers rather
|
117
|
-
than just a marked up fragment, remember to pass the `:standalone` option so
|
118
|
-
the correct header and footer are added.
|
119
|
-
|
120
|
-
```ruby
|
121
|
-
PandocRuby.new("# Some title", :standalone).to_rtf
|
122
|
-
```
|
123
|
-
|
124
150
|
## Note on Patches/Pull Requests
|
125
151
|
|
126
152
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
2
|
require 'bundler'
|
5
3
|
begin
|
6
4
|
Bundler.setup(:default, :development)
|
7
5
|
rescue Bundler::BundlerError => e
|
8
|
-
|
9
|
-
|
6
|
+
warn e.message
|
7
|
+
warn 'Run `bundle install` to install missing gems'
|
10
8
|
exit e.status_code
|
11
9
|
end
|
12
10
|
require 'rake'
|
@@ -29,3 +27,34 @@ Rake::RDocTask.new do |rdoc|
|
|
29
27
|
rdoc.rdoc_files.include('README*')
|
30
28
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
29
|
end
|
30
|
+
|
31
|
+
require './lib/pandoc-ruby.rb'
|
32
|
+
desc <<HEREDOC
|
33
|
+
Regenerate test files in existing formats.
|
34
|
+
HEREDOC
|
35
|
+
task :regenerate_files do
|
36
|
+
extensions = []
|
37
|
+
files_dir = File.join(File.dirname(__FILE__), 'test', 'files')
|
38
|
+
|
39
|
+
Dir.glob(File.join(files_dir, 'format*')) do |f|
|
40
|
+
extensions << f.match(/format\.(\w+)\Z/)[1]
|
41
|
+
end
|
42
|
+
|
43
|
+
from_content = File.read(File.join(files_dir, 'format.markdown'))
|
44
|
+
|
45
|
+
extensions.each do |to|
|
46
|
+
next if to == 'markdown'
|
47
|
+
|
48
|
+
to_file = File.join(files_dir, "format.#{to}")
|
49
|
+
|
50
|
+
converted_content = PandocRuby.convert(
|
51
|
+
from_content,
|
52
|
+
:from => 'markdown',
|
53
|
+
:to => to
|
54
|
+
)
|
55
|
+
|
56
|
+
File.open(to_file, 'w') do |file|
|
57
|
+
file.write(converted_content)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|