paru 0.2.4.2 → 0.2.4.3
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 +8 -20
- data/lib/paru/error.rb +4 -6
- data/lib/paru/filter.rb +144 -110
- data/lib/paru/filter/ast_manipulation.rb +75 -39
- data/lib/paru/filter/attr.rb +72 -36
- data/lib/paru/filter/block.rb +14 -8
- data/lib/paru/filter/block_quote.rb +12 -9
- data/lib/paru/filter/bullet_list.rb +6 -6
- data/lib/paru/filter/citation.rb +51 -25
- data/lib/paru/filter/cite.rb +29 -20
- data/lib/paru/filter/code.rb +41 -24
- data/lib/paru/filter/code_block.rb +36 -21
- data/lib/paru/filter/definition_list.rb +19 -15
- data/lib/paru/filter/definition_list_item.rb +30 -17
- data/lib/paru/filter/div.rb +29 -21
- data/lib/paru/filter/document.rb +73 -46
- data/lib/paru/filter/emph.rb +6 -6
- data/lib/paru/filter/empty_block.rb +17 -13
- data/lib/paru/filter/empty_inline.rb +24 -17
- data/lib/paru/filter/header.rb +38 -23
- data/lib/paru/filter/image.rb +13 -11
- data/lib/paru/filter/inline.rb +21 -10
- data/lib/paru/filter/line_block.rb +6 -6
- data/lib/paru/filter/line_break.rb +6 -6
- data/lib/paru/filter/link.rb +33 -21
- data/lib/paru/filter/list.rb +26 -17
- data/lib/paru/filter/list_attributes.rb +53 -32
- data/lib/paru/filter/markdown.rb +102 -59
- data/lib/paru/filter/math.rb +65 -38
- data/lib/paru/filter/meta.rb +26 -16
- data/lib/paru/filter/meta_blocks.rb +12 -9
- data/lib/paru/filter/meta_bool.rb +6 -6
- data/lib/paru/filter/meta_inlines.rb +12 -9
- data/lib/paru/filter/meta_list.rb +6 -6
- data/lib/paru/filter/meta_map.rb +49 -33
- data/lib/paru/filter/meta_string.rb +6 -6
- data/lib/paru/filter/meta_value.rb +22 -14
- data/lib/paru/filter/node.rb +204 -129
- data/lib/paru/filter/note.rb +31 -20
- data/lib/paru/filter/null.rb +6 -6
- data/lib/paru/filter/ordered_list.rb +34 -18
- data/lib/paru/filter/para.rb +20 -13
- data/lib/paru/filter/plain.rb +21 -12
- data/lib/paru/filter/quoted.rb +27 -18
- data/lib/paru/filter/raw_block.rb +32 -19
- data/lib/paru/filter/raw_inline.rb +40 -22
- data/lib/paru/filter/small_caps.rb +7 -6
- data/lib/paru/filter/soft_break.rb +6 -6
- data/lib/paru/filter/space.rb +6 -6
- data/lib/paru/filter/span.rb +28 -18
- data/lib/paru/filter/str.rb +29 -18
- data/lib/paru/filter/strikeout.rb +6 -6
- data/lib/paru/filter/strong.rb +6 -6
- data/lib/paru/filter/subscript.rb +6 -6
- data/lib/paru/filter/superscript.rb +6 -6
- data/lib/paru/filter/table.rb +51 -29
- data/lib/paru/filter/table_row.rb +21 -14
- data/lib/paru/filter/target.rb +29 -15
- data/lib/paru/filter/version.rb +23 -14
- data/lib/paru/pandoc.rb +165 -111
- data/lib/paru/pandoc_options.yaml +3 -3
- data/lib/paru/selector.rb +176 -153
- metadata +2 -3
- data/lib/paru/filter/alignment.rb +0 -30
data/lib/paru/filter/math.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,51 +17,78 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# A Math Inline node with the type of math node and the mathematical
|
24
|
+
# contents
|
25
|
+
#
|
26
|
+
# @!attribute math_type
|
27
|
+
# @return [Hash]
|
28
|
+
# @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:MathType
|
29
|
+
#
|
30
|
+
# @!attribute string
|
31
|
+
# @return [String]
|
32
|
+
class Math < Inline
|
33
|
+
attr_accessor :math_type, :string
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
# Create a new Math node with contents
|
36
|
+
#
|
37
|
+
# @param contents [Array] an array with the type and contents
|
38
|
+
def initialize(contents)
|
39
|
+
@math_type, @string = contents
|
40
|
+
end
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
42
|
+
# Is this an inline node?
|
43
|
+
#
|
44
|
+
# @return [Boolean] true if math type is "InlineMath", false
|
45
|
+
# otherwise
|
46
|
+
def inline?()
|
47
|
+
"InlineMath" == @math_type[t]
|
48
|
+
end
|
34
49
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
50
|
+
# Convert this Math node's content to Inline
|
51
|
+
def inline!()
|
52
|
+
@math_type = {
|
53
|
+
"t" => "InlineMath"
|
54
|
+
}
|
55
|
+
end
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
|
57
|
+
# Should this math be displayed as a block?
|
58
|
+
#
|
59
|
+
# @return [Boolean] true if type is "DisplayMath"
|
60
|
+
def display?()
|
61
|
+
"DisplayMath" == @math_type[t]
|
62
|
+
end
|
44
63
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
64
|
+
# Make this Math node's content display as a block
|
65
|
+
def display!()
|
66
|
+
@math_type = {
|
67
|
+
"t" => "DisplayMath"
|
68
|
+
}
|
69
|
+
end
|
50
70
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
71
|
+
# Create an AST representation of this Math node
|
72
|
+
def ast_contents()
|
73
|
+
[
|
74
|
+
@math_type,
|
75
|
+
@string
|
76
|
+
]
|
77
|
+
end
|
57
78
|
|
58
|
-
|
59
|
-
|
60
|
-
|
79
|
+
# Has this Math node string contents?
|
80
|
+
#
|
81
|
+
# @return [Boolean] true
|
82
|
+
def has_string?()
|
83
|
+
true
|
84
|
+
end
|
61
85
|
|
62
|
-
|
63
|
-
|
64
|
-
|
86
|
+
# Has this Math node inline contents?
|
87
|
+
#
|
88
|
+
# @return [Boolean] false
|
89
|
+
def has_inline?()
|
90
|
+
false
|
91
|
+
end
|
92
|
+
end
|
65
93
|
end
|
66
|
-
end
|
67
94
|
end
|
data/lib/paru/filter/meta.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,25 +17,35 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./meta_map"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# A Meta node represents the metadata of a document. It is a MetaMap
|
24
|
+
# node.
|
25
|
+
#
|
26
|
+
# @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:Meta
|
27
|
+
class Meta < MetaMap
|
28
|
+
include Enumerable
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
# Create a new Meta node based on the contents
|
31
|
+
#
|
32
|
+
# @param value [String]
|
33
|
+
def initialize(value)
|
34
|
+
super value
|
35
|
+
end
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
# The type of a Meta is "meta"
|
38
|
+
#
|
39
|
+
# @return [String] "meta"
|
40
|
+
def ast_type()
|
41
|
+
"meta"
|
42
|
+
end
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
# Convert this Meta node to an AST representation
|
45
|
+
def to_ast()
|
46
|
+
ast_contents
|
47
|
+
end
|
38
48
|
|
49
|
+
end
|
39
50
|
end
|
40
|
-
end
|
41
51
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,16 +17,19 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./node"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# A MetaBlocks Node contains a list of Blocks
|
25
|
+
class MetaBlocks < Node
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
# Create a MetaBlocks node based on the contents
|
28
|
+
#
|
29
|
+
# @param value [String] the contents of the MetaBlocks
|
30
|
+
def initialize(value)
|
31
|
+
super value
|
32
|
+
end
|
33
|
+
end
|
30
34
|
end
|
31
|
-
end
|
32
35
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./meta_value"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# A MetaBool Note representa a Boolean value
|
25
|
+
class MetaBool < MetaValue
|
26
|
+
end
|
26
27
|
end
|
27
|
-
end
|
28
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,16 +17,19 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./node"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# A MetaInlines node contains a list of Inline nodes
|
25
|
+
class MetaInlines < Node
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
# Create a new MetaInlines Node based on the contents
|
28
|
+
#
|
29
|
+
# @param value [String] the contents of this MetaInlines node
|
30
|
+
def initialize(value)
|
31
|
+
super value
|
32
|
+
end
|
33
|
+
end
|
30
34
|
end
|
31
|
-
end
|
32
35
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./node"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# A MetaList node contains a list of MetaValue nodes
|
25
|
+
class MetaList < Node
|
26
|
+
end
|
26
27
|
end
|
27
|
-
end
|
28
28
|
end
|
data/lib/paru/filter/meta_map.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,47 +17,63 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./node"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# A MetaMap Node is a map of String keys with MetaValue values
|
25
|
+
class MetaMap < Node
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# Create a new MetaMap based on the contents
|
28
|
+
#
|
29
|
+
# @param contents [Array] a list of key-value pairs
|
30
|
+
def initialize(contents)
|
31
|
+
@children = Hash.new
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
if contents.is_a? Hash
|
34
|
+
contents.each_pair do |key, value|
|
35
|
+
if not value.empty? and PandocFilter.const_defined? value["t"]
|
36
|
+
@children[key] = PandocFilter.const_get(value["t"]).new value["c"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
34
40
|
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
# Get the value belonging to key
|
43
|
+
#
|
44
|
+
# @param key [String] the key
|
45
|
+
#
|
46
|
+
# @return [MetaValue] the value belonging to the key
|
47
|
+
def [](key)
|
48
|
+
if @children.key_exists?
|
49
|
+
@children[key]
|
50
|
+
end
|
51
|
+
end
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
# Does this MetaMap node have key?
|
54
|
+
#
|
55
|
+
# @param key [String] the key to find
|
56
|
+
#
|
57
|
+
# @return [Boolean] true if this MetaMap node contains this key
|
58
|
+
def has_key?(key)
|
59
|
+
@children.has_key? key
|
60
|
+
end
|
48
61
|
|
49
|
-
|
50
|
-
|
51
|
-
|
62
|
+
# Delete the key-value pair from this MetaMap
|
63
|
+
#
|
64
|
+
# @param key [String] the key to delete
|
65
|
+
def delete(key)
|
66
|
+
@children.delete key
|
67
|
+
end
|
52
68
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
69
|
+
# The AST contents
|
70
|
+
def ast_contents()
|
71
|
+
ast = Hash.new
|
72
|
+
@children.each_pair do |key, value|
|
73
|
+
ast[key] = value.to_ast
|
74
|
+
end
|
75
|
+
ast
|
76
|
+
end
|
57
77
|
end
|
58
|
-
ast
|
59
|
-
end
|
60
|
-
|
61
78
|
end
|
62
|
-
end
|
63
79
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,12 +17,12 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./meta_value"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
# A MetaString Node represents a String value
|
25
|
+
class MetaString < MetaValue
|
26
|
+
end
|
26
27
|
end
|
27
|
-
end
|
28
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
|
2
|
+
# Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
|
3
3
|
#
|
4
4
|
# This file is part of Paru
|
5
5
|
#
|
@@ -17,24 +17,32 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
22
|
+
require_relative "./node"
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# A MetaValue Node is either a MetaMap, MetaList, MetaBool, MetaString, MetaInlines, or a MetaBlocks.
|
25
|
+
#
|
26
|
+
# @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:MetaValue
|
27
|
+
#
|
28
|
+
# @!attribute value
|
29
|
+
# @return [String]
|
30
|
+
class MetaValue < Node
|
27
31
|
|
28
|
-
|
32
|
+
attr_accessor :value
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
# Create a new MetaValue Node based on the value
|
35
|
+
#
|
36
|
+
# @param value [String]
|
37
|
+
def initialize(value)
|
38
|
+
@value = value
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
# The AST contents
|
42
|
+
def ast_contents()
|
43
|
+
@value
|
44
|
+
end
|
37
45
|
|
46
|
+
end
|
38
47
|
end
|
39
|
-
end
|
40
48
|
end
|