paru 0.3.0a6 → 0.3.0a8
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/filter.rb +23 -21
- data/lib/paru/pandoc.rb +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfb62e841895598d6ee403719487470f82f8604f
|
4
|
+
data.tar.gz: 711cb74b424e87a6cd6879a751b9a2ee2d16009e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a62b675732dc9fadd6b616acb49ec08a899f76412e39984612fa050812b433814cf5f3fec0e677f495c492a7f5e36a937561134276664d817979430dc0bb2e
|
7
|
+
data.tar.gz: df08aa23b5e1ae0610f9b92cb73f504377fb46c5814063a576b393a76d00feff04608d9354bba546fcd9ee6572f6bc3352914b515dd5e2c3d1904186b35b45f2
|
data/lib/paru/filter.rb
CHANGED
@@ -226,7 +226,6 @@ module Paru
|
|
226
226
|
def initialize(input = $stdin, output = $stdout)
|
227
227
|
@input = input
|
228
228
|
@output = output
|
229
|
-
@running = false
|
230
229
|
end
|
231
230
|
|
232
231
|
# Run the filter specified by block. This is a convenience method that
|
@@ -278,30 +277,22 @@ module Paru
|
|
278
277
|
end
|
279
278
|
end
|
280
279
|
|
281
|
-
@running = true # used to be able to stop filtering immediately
|
282
280
|
@current_node = @document
|
283
281
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
@current_node = nodes_to_filter.next
|
291
|
-
end
|
292
|
-
|
293
|
-
@filtered_nodes.push @current_node
|
294
|
-
|
295
|
-
instance_eval(&block) # run the actual filter code
|
296
|
-
rescue StopIteration
|
297
|
-
@running = false
|
282
|
+
nodes_to_filter.each do |node|
|
283
|
+
if @current_node.has_been_replaced?
|
284
|
+
@current_node = @current_node.get_replacement
|
285
|
+
@filtered_nodes.pop
|
286
|
+
else
|
287
|
+
@current_node = node
|
298
288
|
end
|
289
|
+
|
290
|
+
@filtered_nodes.push @current_node
|
291
|
+
|
292
|
+
instance_eval(&block) # run the actual filter code
|
299
293
|
end
|
300
|
-
|
301
|
-
@running = false
|
302
294
|
|
303
|
-
|
304
|
-
@output.write @document.to_JSON
|
295
|
+
write_document
|
305
296
|
end
|
306
297
|
|
307
298
|
# Specify what nodes to filter with a +selector+. If the +current_node+
|
@@ -318,10 +309,15 @@ module Paru
|
|
318
309
|
# This is a great timesaver for filters that only act on a small
|
319
310
|
# number of nodes in a large document, or when you only want to set
|
320
311
|
# the metadata.
|
312
|
+
#
|
313
|
+
# Note, stop will break off the filter immediately after outputting
|
314
|
+
# the document in its current state.
|
321
315
|
def stop!()
|
322
|
-
|
316
|
+
write_document
|
317
|
+
exit true
|
323
318
|
end
|
324
319
|
|
320
|
+
|
325
321
|
private
|
326
322
|
|
327
323
|
# The Document node from JSON formatted pandoc document structure
|
@@ -332,6 +328,12 @@ module Paru
|
|
332
328
|
def read_document()
|
333
329
|
PandocFilter::Document.from_JSON @input.read
|
334
330
|
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
|
335
337
|
end
|
336
338
|
|
337
339
|
# FilterError is thrown when there is an error during filtering
|
data/lib/paru/pandoc.rb
CHANGED
@@ -179,7 +179,7 @@ module Paru
|
|
179
179
|
# @param option_sep [String] the string to separate options with
|
180
180
|
# @return [String] This converter's command line invocation string.
|
181
181
|
def to_command(option_sep = DEFAULT_OPTION_SEP)
|
182
|
-
"#{@@pandoc_exec
|
182
|
+
"#{escape(@@pandoc_exec)}\t#{to_option_string option_sep}"
|
183
183
|
end
|
184
184
|
|
185
185
|
private
|
@@ -199,11 +199,11 @@ module Paru
|
|
199
199
|
when Array then
|
200
200
|
# This option can occur multiple times: list each with its value.
|
201
201
|
# For example: --css=main.css --css=print.css
|
202
|
-
options_arr.push value.map {|val| "#{option_string}=#{val.to_s
|
202
|
+
options_arr.push value.map {|val| "#{option_string}=#{escape(val.to_s)}"}.join(option_sep)
|
203
203
|
else
|
204
204
|
# All options that aren't flags and can occur only once have the
|
205
205
|
# same pattern: --option=value
|
206
|
-
options_arr.push "#{option_string}=#{value.to_s
|
206
|
+
options_arr.push "#{option_string}=#{escape(value.to_s)}"
|
207
207
|
end
|
208
208
|
end
|
209
209
|
options_arr.join(option_sep)
|
@@ -282,6 +282,15 @@ module Paru
|
|
282
282
|
|
283
283
|
private
|
284
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
|
+
|
285
294
|
def run_converter(command, input = nil)
|
286
295
|
begin
|
287
296
|
output = ''
|
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.3.
|
4
|
+
version: 0.3.0a8
|
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-26 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
|