paru 0.2.5.12 → 0.3.0a1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/paru.rb +1 -1
- data/lib/paru/filter.rb +21 -23
- data/lib/paru/filter/cite.rb +2 -2
- data/lib/paru/filter/document.rb +1 -1
- data/lib/paru/pandoc.rb +26 -50
- data/lib/paru/pandoc_options_version_2.yaml +2 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d3f58592821c089eb71f929c5913f09c5235bf8
|
4
|
+
data.tar.gz: d9f6b513b294bc25d8ffba591915895397c5729a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 062e92c053c9b8dcfdfaaf30d18f9f3f8c88ce1618d7b6e5a0c9265ed4e80e7b43de6149d39b9a35a9c87adf33b9bb9688834ce65cfeab22c0f9817a337db033
|
7
|
+
data.tar.gz: a19be07f8af5978259da737e47f93b6cd0ae071e62c38dba9633d7331672d1698c1780337214ed3c6f59340150c3c0951217efe589e3c2c4a7b85b23694a5a5e
|
data/lib/paru.rb
CHANGED
data/lib/paru/filter.rb
CHANGED
@@ -226,6 +226,7 @@ module Paru
|
|
226
226
|
def initialize(input = $stdin, output = $stdout)
|
227
227
|
@input = input
|
228
228
|
@output = output
|
229
|
+
@running = false
|
229
230
|
end
|
230
231
|
|
231
232
|
# Run the filter specified by block. This is a convenience method that
|
@@ -277,22 +278,30 @@ module Paru
|
|
277
278
|
end
|
278
279
|
end
|
279
280
|
|
281
|
+
@running = true # used to be able to stop filtering immediately
|
280
282
|
@current_node = @document
|
281
283
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
284
|
+
while @running do
|
285
|
+
begin
|
286
|
+
if @current_node.has_been_replaced?
|
287
|
+
@current_node = @current_node.get_replacement
|
288
|
+
@filtered_nodes.pop
|
289
|
+
else
|
290
|
+
@current_node = nodes_to_filter.next
|
291
|
+
end
|
292
|
+
|
293
|
+
@filtered_nodes.push @current_node
|
291
294
|
|
292
|
-
|
295
|
+
instance_eval(&block) # run the actual filter code
|
296
|
+
rescue StopIteration
|
297
|
+
@running = false
|
298
|
+
end
|
293
299
|
end
|
300
|
+
|
301
|
+
@running = false
|
294
302
|
|
295
|
-
|
303
|
+
@document.meta = @metadata.to_meta
|
304
|
+
@output.write @document.to_JSON
|
296
305
|
end
|
297
306
|
|
298
307
|
# Specify what nodes to filter with a +selector+. If the +current_node+
|
@@ -309,15 +318,10 @@ module Paru
|
|
309
318
|
# This is a great timesaver for filters that only act on a small
|
310
319
|
# number of nodes in a large document, or when you only want to set
|
311
320
|
# the metadata.
|
312
|
-
#
|
313
|
-
# Note, stop will break off the filter immediately after outputting
|
314
|
-
# the document in its current state.
|
315
321
|
def stop!()
|
316
|
-
|
317
|
-
exit true
|
322
|
+
@running = false
|
318
323
|
end
|
319
324
|
|
320
|
-
|
321
325
|
private
|
322
326
|
|
323
327
|
# The Document node from JSON formatted pandoc document structure
|
@@ -328,12 +332,6 @@ module Paru
|
|
328
332
|
def read_document()
|
329
333
|
PandocFilter::Document.from_JSON @input.read
|
330
334
|
end
|
331
|
-
|
332
|
-
# Write the document being filtered to STDOUT
|
333
|
-
def write_document()
|
334
|
-
@document.meta = @metadata.to_meta
|
335
|
-
@output.write @document.to_JSON
|
336
|
-
end
|
337
335
|
end
|
338
336
|
|
339
337
|
# FilterError is thrown when there is an error during filtering
|
data/lib/paru/filter/cite.rb
CHANGED
data/lib/paru/filter/document.rb
CHANGED
@@ -36,7 +36,7 @@ module Paru
|
|
36
36
|
|
37
37
|
# The current pandoc type version
|
38
38
|
# @see https://hackage.haskell.org/package/pandoc-types
|
39
|
-
CURRENT_PANDOC_VERSION = [1, 17,
|
39
|
+
CURRENT_PANDOC_VERSION = [1, 17, 1]
|
40
40
|
|
41
41
|
# Each file that is being filtered by pandoc is represented by a root
|
42
42
|
# Document. It is the root node of the AST of the document in the file.
|
data/lib/paru/pandoc.rb
CHANGED
@@ -16,7 +16,6 @@
|
|
16
16
|
# You should have received a copy of the GNU General Public License
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
|
-
require "open3"
|
20
19
|
require "shellwords"
|
21
20
|
require "yaml"
|
22
21
|
|
@@ -79,10 +78,6 @@ module Paru
|
|
79
78
|
#
|
80
79
|
#
|
81
80
|
class Pandoc
|
82
|
-
|
83
|
-
# Use a readable option separator on Unix-like systems, but fall back
|
84
|
-
# to a space on Windows.
|
85
|
-
DEFAULT_OPTION_SEP = if Gem.win_platform? then " " else " \\\n\t" end
|
86
81
|
|
87
82
|
# Path to the pandoc executatble to use by paru.
|
88
83
|
PARU_PANDOC_PATH = "PARU_PANDOC_PATH"
|
@@ -154,7 +149,17 @@ module Paru
|
|
154
149
|
# @example Using <<
|
155
150
|
# output = converter << 'this is a *strong* word'
|
156
151
|
def convert(input)
|
157
|
-
|
152
|
+
begin
|
153
|
+
output = ''
|
154
|
+
IO.popen(to_command, 'r+') do |p|
|
155
|
+
p << input
|
156
|
+
p.close_write
|
157
|
+
output << p.read
|
158
|
+
end
|
159
|
+
output
|
160
|
+
rescue StandardError => err
|
161
|
+
throw Error.new "Error while running '#{to_command}' on input:\n\n#{input}\n\nPandoc responds: '#{err.message}'"
|
162
|
+
end
|
158
163
|
end
|
159
164
|
alias << convert
|
160
165
|
|
@@ -170,7 +175,17 @@ module Paru
|
|
170
175
|
# @example Using convert_file
|
171
176
|
# output = converter.convert_file 'files/document.md'
|
172
177
|
def convert_file(input_file)
|
173
|
-
|
178
|
+
command = "#{to_command} #{input_file}"
|
179
|
+
begin
|
180
|
+
output = ''
|
181
|
+
IO.popen(command, 'r+') do |p|
|
182
|
+
p.close_write
|
183
|
+
output << p.read
|
184
|
+
end
|
185
|
+
output
|
186
|
+
rescue StandardError => err
|
187
|
+
throw Error.new "Error while running '#{command}' on input:\n\n#{input}\n\nPandoc responds: '#{err.message}'"
|
188
|
+
end
|
174
189
|
end
|
175
190
|
|
176
191
|
# Create a string representation of this converter's pandoc command
|
@@ -178,8 +193,8 @@ module Paru
|
|
178
193
|
#
|
179
194
|
# @param option_sep [String] the string to separate options with
|
180
195
|
# @return [String] This converter's command line invocation string.
|
181
|
-
def to_command(option_sep =
|
182
|
-
"#{
|
196
|
+
def to_command(option_sep = " \\\n\t")
|
197
|
+
"#{@@pandoc_exec.shellescape}\t#{to_option_string option_sep}"
|
183
198
|
end
|
184
199
|
|
185
200
|
private
|
@@ -199,11 +214,11 @@ module Paru
|
|
199
214
|
when Array then
|
200
215
|
# This option can occur multiple times: list each with its value.
|
201
216
|
# For example: --css=main.css --css=print.css
|
202
|
-
options_arr.push value.map {|val| "#{option_string}=#{
|
217
|
+
options_arr.push value.map {|val| "#{option_string}=#{val.to_s.shellescape}"}.join(option_sep)
|
203
218
|
else
|
204
219
|
# All options that aren't flags and can occur only once have the
|
205
220
|
# same pattern: --option=value
|
206
|
-
options_arr.push "#{option_string}=#{
|
221
|
+
options_arr.push "#{option_string}=#{value.to_s.shellescape}"
|
207
222
|
end
|
208
223
|
end
|
209
224
|
options_arr.join(option_sep)
|
@@ -280,45 +295,6 @@ module Paru
|
|
280
295
|
end
|
281
296
|
end
|
282
297
|
|
283
|
-
private
|
284
|
-
|
285
|
-
def escape(str)
|
286
|
-
if Gem.win_platform?
|
287
|
-
escaped = str.gsub("\\", "\\\\")
|
288
|
-
"\"#{escaped}\""
|
289
|
-
else
|
290
|
-
str.shellescape
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
def run_converter(command, input = nil)
|
295
|
-
begin
|
296
|
-
output = ''
|
297
|
-
error = ''
|
298
|
-
status = 0
|
299
|
-
|
300
|
-
Open3.popen3(command) do |stdin, stdout, stderr, thread|
|
301
|
-
stdin << input unless input.nil?
|
302
|
-
stdin.close
|
303
|
-
output << stdout.read
|
304
|
-
error << stderr.read
|
305
|
-
status = thread.value.exitstatus
|
306
|
-
end
|
307
|
-
|
308
|
-
warn error unless error.empty?
|
309
|
-
|
310
|
-
if 0 < status
|
311
|
-
# pandoc exited with an error
|
312
|
-
raise Paru::Error.new "error while running:\n\n#{command}\n\nPandoc responded with:\n\n#{error}\n"
|
313
|
-
end
|
314
|
-
|
315
|
-
output
|
316
|
-
rescue Paru::Error => err
|
317
|
-
raise err
|
318
|
-
rescue StandardError => err
|
319
|
-
throw Error.new "Unable to run pandoc via command '#{command}': #{err.message}"
|
320
|
-
end
|
321
|
-
end
|
322
298
|
end
|
323
299
|
|
324
300
|
end
|
@@ -43,10 +43,8 @@ dpi: 96
|
|
43
43
|
eol: "native"
|
44
44
|
wrap: "auto"
|
45
45
|
columns: 78
|
46
|
-
strip-comments: true
|
47
46
|
toc: true
|
48
47
|
table_of_contents: true
|
49
|
-
toc_depth: 3
|
50
48
|
no_highlight: true
|
51
49
|
highlight_style: ""
|
52
50
|
syntax_definition: ""
|
@@ -78,8 +76,8 @@ epub_cover_image: ""
|
|
78
76
|
epub_metadata: ""
|
79
77
|
epub_embed_font: ""
|
80
78
|
epub_chapter_level: 1
|
81
|
-
|
82
|
-
|
79
|
+
latex_engine: ""
|
80
|
+
latex_engine_opt: ""
|
83
81
|
bibliography: ""
|
84
82
|
csl: ""
|
85
83
|
citation_abbreviation: ""
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0a1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huub de Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use Pandoc (http://www.pandoc.org) with ruby
|
14
14
|
email: Huub@heerdebeer.org
|
@@ -102,13 +102,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- - "
|
105
|
+
- - ">"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
107
|
+
version: 1.3.1
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
110
|
rubygems_version: 2.5.2
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
|
-
summary: Paru is a ruby wrapper around pandoc
|
113
|
+
summary: Paru is a ruby wrapper around pandoc (pandoc 2)
|
114
114
|
test_files: []
|