paru 0.2.4.6 → 0.2.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paru.rb +3 -2
- data/lib/paru/filter.rb +5 -1
- data/lib/paru/filter/document.rb +35 -6
- data/lib/paru/filter/meta_value.rb +1 -1
- data/lib/paru/filter_error.rb +24 -0
- data/lib/paru/pandoc2yaml.rb +30 -11
- data/lib/paru/selector.rb +0 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1332fd988cbb97b8dd7cd1c45c20a90706cfb537
|
4
|
+
data.tar.gz: 168c0c5db7710ac7ae6e7abe4f5219c6a77ea248
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fd6c4f49fa011d4001151202e5c974f3ed7f972c6b1ed922ef6ca60adfc1821a8b2a773c04fdb6a3462d62ee6cb2d8b6fe8039835ec7f0a531e884a1127e87b
|
7
|
+
data.tar.gz: 61e852b82fc8844a5b1cb58f1a2ee599aef73fcc06d265bd3f4e924e3a75e5f0a560e6e0e0fff9fe8ceb224ff78c54dc1e38a96067d80986b22a4e7ea914d52a
|
data/lib/paru.rb
CHANGED
@@ -18,10 +18,11 @@
|
|
18
18
|
#++
|
19
19
|
module Paru
|
20
20
|
require "paru/pandoc"
|
21
|
-
require "paru/error"
|
22
21
|
require "paru/filter"
|
22
|
+
require "paru/filter_error"
|
23
|
+
require "paru/error"
|
23
24
|
require "paru/pandoc2yaml"
|
24
25
|
|
25
26
|
# Paru's current version
|
26
|
-
VERSION = [0, 2, 4,
|
27
|
+
VERSION = [0, 2, 4, 7]
|
27
28
|
end
|
data/lib/paru/filter.rb
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
module Paru
|
20
20
|
|
21
21
|
require_relative "./selector"
|
22
|
-
require_relative "filter/document"
|
22
|
+
require_relative "./filter/document"
|
23
23
|
|
24
24
|
# Paru filter is a wrapper around pandoc's JSON api, which is based on
|
25
25
|
# {pandoc-types}[https://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html].
|
@@ -298,4 +298,8 @@ module Paru
|
|
298
298
|
end
|
299
299
|
|
300
300
|
end
|
301
|
+
|
302
|
+
# FilterError is thrown when there is an error during fitlering
|
303
|
+
class FilterError < Error
|
304
|
+
end
|
301
305
|
end
|
data/lib/paru/filter/document.rb
CHANGED
@@ -20,10 +20,11 @@ module Paru
|
|
20
20
|
module PandocFilter
|
21
21
|
|
22
22
|
require "json"
|
23
|
-
require_relative "./node"
|
24
|
-
require_relative "./plain"
|
25
|
-
require_relative "./meta"
|
26
|
-
require_relative "./version"
|
23
|
+
require_relative "./node.rb"
|
24
|
+
require_relative "./plain.rb"
|
25
|
+
require_relative "./meta.rb"
|
26
|
+
require_relative "./version.rb"
|
27
|
+
require_relative "../filter_error.rb"
|
27
28
|
|
28
29
|
# Pandoc type version key
|
29
30
|
VERSION = "pandoc-api-version"
|
@@ -49,9 +50,37 @@ module Paru
|
|
49
50
|
#
|
50
51
|
# @param json [String] a JSON string representation of the AST of a document
|
51
52
|
# @return [Document] the newly created document
|
53
|
+
#
|
54
|
+
# @raise [ParuFilterError] when parsing JSON AST from pandoc fails
|
55
|
+
# or the parsed results do not make sense.
|
52
56
|
def self.from_JSON(json)
|
53
|
-
|
54
|
-
|
57
|
+
begin
|
58
|
+
doc = JSON.parse json
|
59
|
+
version, metadata, contents = doc.values_at(VERSION, META, BLOCKS)
|
60
|
+
rescue Exception => e
|
61
|
+
raise FilterError.new <<~WARNING
|
62
|
+
Unable to read document.
|
63
|
+
|
64
|
+
Most likely cause: Paru expects a pandoc installation that has been
|
65
|
+
compiled with pandoc-types >= #{CURRENT_PANDOC_VERSION.join('.')}. You can
|
66
|
+
check which pandoc-types have been compiled with your pandoc installation by
|
67
|
+
running `pandoc -v`.
|
68
|
+
|
69
|
+
Original error message: #{e.message}
|
70
|
+
WARNING
|
71
|
+
end
|
72
|
+
|
73
|
+
if -1 == (version <=> CURRENT_PANDOC_VERSION)
|
74
|
+
if metadata.has_key?('_debug')
|
75
|
+
warn <<~WARNING
|
76
|
+
pandoc-types API version used in document (version = #{version.join('.')}) is
|
77
|
+
smaller than the version of pandoc-types used by paru
|
78
|
+
(#{CURRENT_PANDOC_VERSION.join('.')}. If you experience unexpected results,
|
79
|
+
please try updating pandoc or downgrading paru.
|
80
|
+
WARNING
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
55
84
|
PandocFilter::Document.new version, metadata, contents
|
56
85
|
end
|
57
86
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
|
+
#
|
4
|
+
# This file is part of Paru
|
5
|
+
#
|
6
|
+
# Paru is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Paru is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
19
|
+
require_relative "./error.rb"
|
20
|
+
module Paru
|
21
|
+
# A FilterError raised when there is an error while running a filter.
|
22
|
+
class FilterError < Error
|
23
|
+
end
|
24
|
+
end
|
data/lib/paru/pandoc2yaml.rb
CHANGED
@@ -1,29 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# pandoc2yaml.rb extracts the metadata from a pandoc markdown file and prints
|
4
|
-
# that metadata out again as a pandoc markdown file with nothing in it but that
|
5
|
-
# metadata
|
1
|
+
#--
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
6
3
|
#
|
7
|
-
#
|
4
|
+
# This file is part of Paru
|
8
5
|
#
|
9
|
-
#
|
6
|
+
# Paru is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
10
|
#
|
11
|
-
|
11
|
+
# Paru is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#++
|
12
19
|
module Paru
|
13
|
-
|
14
|
-
|
15
|
-
require_relative "./pandoc.rb"
|
20
|
+
require "json"
|
21
|
+
require_relative "./pandoc.rb"
|
16
22
|
|
23
|
+
# Utility class to extract YAML metadata form a markdown file in pandoc's
|
24
|
+
# own markdown format.
|
25
|
+
class Pandoc2Yaml
|
17
26
|
# Paru converters:
|
18
27
|
# Note. When converting metadata back to the pandoc markdown format, you have
|
19
28
|
# to use the option "standalone", otherwise the metadata is skipped
|
29
|
+
|
30
|
+
# Converter from pandoc's markdown to pandoc's AST JSON
|
20
31
|
PANDOC_2_JSON = Paru::Pandoc.new {from "markdown"; to "json"}
|
32
|
+
|
33
|
+
# Converter from pandoc's AST JSON back to pandoc. Note the
|
34
|
+
# 'standalone' property, which is needed to output the metadata as
|
35
|
+
# well.
|
21
36
|
JSON_2_PANDOC = Paru::Pandoc.new {from "json"; to "markdown"; standalone}
|
22
37
|
|
23
38
|
# When converting a pandoc document to JSON, or vice versa, the JSON object
|
24
39
|
# has the following three properties:
|
40
|
+
|
41
|
+
# Pandoc-type API version key
|
25
42
|
VERSION = "pandoc-api-version"
|
43
|
+
# Meta block key
|
26
44
|
META = "meta"
|
45
|
+
# Content's blocks key
|
27
46
|
BLOCKS = "blocks"
|
28
47
|
|
29
48
|
# Extract the YAML metadata from input document
|
data/lib/paru/selector.rb
CHANGED
@@ -25,7 +25,6 @@ module Paru
|
|
25
25
|
class SelectorParseError < Error
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
28
|
# A Selector models a relationship between Pandoc AST nodes, such as
|
30
29
|
# parent-child or sibling. Selectors in paru are like CSS selectors, but
|
31
30
|
# more limited because the Pandoc AST is quite simple.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.4.
|
4
|
+
version: 0.2.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Huub de Beer
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/paru/filter/table_row.rb
|
81
81
|
- lib/paru/filter/target.rb
|
82
82
|
- lib/paru/filter/version.rb
|
83
|
+
- lib/paru/filter_error.rb
|
83
84
|
- lib/paru/pandoc.rb
|
84
85
|
- lib/paru/pandoc2yaml.rb
|
85
86
|
- lib/paru/pandoc_options.yaml
|