paru 0.2.4.2 → 0.2.4.3

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paru.rb +8 -20
  3. data/lib/paru/error.rb +4 -6
  4. data/lib/paru/filter.rb +144 -110
  5. data/lib/paru/filter/ast_manipulation.rb +75 -39
  6. data/lib/paru/filter/attr.rb +72 -36
  7. data/lib/paru/filter/block.rb +14 -8
  8. data/lib/paru/filter/block_quote.rb +12 -9
  9. data/lib/paru/filter/bullet_list.rb +6 -6
  10. data/lib/paru/filter/citation.rb +51 -25
  11. data/lib/paru/filter/cite.rb +29 -20
  12. data/lib/paru/filter/code.rb +41 -24
  13. data/lib/paru/filter/code_block.rb +36 -21
  14. data/lib/paru/filter/definition_list.rb +19 -15
  15. data/lib/paru/filter/definition_list_item.rb +30 -17
  16. data/lib/paru/filter/div.rb +29 -21
  17. data/lib/paru/filter/document.rb +73 -46
  18. data/lib/paru/filter/emph.rb +6 -6
  19. data/lib/paru/filter/empty_block.rb +17 -13
  20. data/lib/paru/filter/empty_inline.rb +24 -17
  21. data/lib/paru/filter/header.rb +38 -23
  22. data/lib/paru/filter/image.rb +13 -11
  23. data/lib/paru/filter/inline.rb +21 -10
  24. data/lib/paru/filter/line_block.rb +6 -6
  25. data/lib/paru/filter/line_break.rb +6 -6
  26. data/lib/paru/filter/link.rb +33 -21
  27. data/lib/paru/filter/list.rb +26 -17
  28. data/lib/paru/filter/list_attributes.rb +53 -32
  29. data/lib/paru/filter/markdown.rb +102 -59
  30. data/lib/paru/filter/math.rb +65 -38
  31. data/lib/paru/filter/meta.rb +26 -16
  32. data/lib/paru/filter/meta_blocks.rb +12 -9
  33. data/lib/paru/filter/meta_bool.rb +6 -6
  34. data/lib/paru/filter/meta_inlines.rb +12 -9
  35. data/lib/paru/filter/meta_list.rb +6 -6
  36. data/lib/paru/filter/meta_map.rb +49 -33
  37. data/lib/paru/filter/meta_string.rb +6 -6
  38. data/lib/paru/filter/meta_value.rb +22 -14
  39. data/lib/paru/filter/node.rb +204 -129
  40. data/lib/paru/filter/note.rb +31 -20
  41. data/lib/paru/filter/null.rb +6 -6
  42. data/lib/paru/filter/ordered_list.rb +34 -18
  43. data/lib/paru/filter/para.rb +20 -13
  44. data/lib/paru/filter/plain.rb +21 -12
  45. data/lib/paru/filter/quoted.rb +27 -18
  46. data/lib/paru/filter/raw_block.rb +32 -19
  47. data/lib/paru/filter/raw_inline.rb +40 -22
  48. data/lib/paru/filter/small_caps.rb +7 -6
  49. data/lib/paru/filter/soft_break.rb +6 -6
  50. data/lib/paru/filter/space.rb +6 -6
  51. data/lib/paru/filter/span.rb +28 -18
  52. data/lib/paru/filter/str.rb +29 -18
  53. data/lib/paru/filter/strikeout.rb +6 -6
  54. data/lib/paru/filter/strong.rb +6 -6
  55. data/lib/paru/filter/subscript.rb +6 -6
  56. data/lib/paru/filter/superscript.rb +6 -6
  57. data/lib/paru/filter/table.rb +51 -29
  58. data/lib/paru/filter/table_row.rb +21 -14
  59. data/lib/paru/filter/target.rb +29 -15
  60. data/lib/paru/filter/version.rb +23 -14
  61. data/lib/paru/pandoc.rb +165 -111
  62. data/lib/paru/pandoc_options.yaml +3 -3
  63. data/lib/paru/selector.rb +176 -153
  64. metadata +2 -3
  65. data/lib/paru/filter/alignment.rb +0 -30
@@ -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,154 +17,229 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
21
-
22
- require_relative "./ast_manipulation"
23
- require_relative "./markdown"
24
- require_relative "../pandoc"
25
- require_relative "./document"
26
-
27
- class Node
28
- include Enumerable
29
- include ASTManipulation
30
- include Markdown
31
-
32
- attr_accessor :parent
33
-
34
- # require all pandoc types
35
- Dir[File.dirname(__FILE__) + '/*.rb'].each do |file|
36
- require_relative file
37
- end
38
-
39
- def initialize contents, inline_children = false
40
- @children = []
41
- @parent = nil
42
-
43
- if contents.is_a? Array
44
- contents.each do |elt|
45
- if PandocFilter.const_defined? elt["t"]
46
- child = PandocFilter.const_get(elt["t"]).new elt["c"]
47
- else
48
- if inline_children
49
- child = PandocFilter::Inline.new elt["c"]
50
- else
51
- child = PandocFilter::Plain.new elt["c"]
52
- end
53
- end
54
-
55
- child.parent = self
56
- @children.push child
57
- end
58
- end
59
- end
60
-
61
-
62
- def each
63
- @children.each do |child|
64
- yield child
65
- end
66
- end
20
+ # PandocFilter is a module containig the paru's Filter functionality
21
+ module PandocFilter
22
+
23
+ require_relative "./ast_manipulation"
24
+ require_relative "./markdown"
25
+ require_relative "../pandoc"
26
+ require_relative "./document"
27
+
28
+ # Every node in a Pandoc AST is mapped to Node. Filters are all about
29
+ # manipulating Nodes.
30
+ #
31
+ # @!attribute parent
32
+ # @return [Node] the parent node, if any.
33
+ class Node
34
+ include Enumerable
35
+ include ASTManipulation
36
+ include Markdown
37
+
38
+ attr_accessor :parent
39
+
40
+ Dir[File.dirname(__FILE__) + '/*.rb'].each do |file|
41
+ require_relative file
42
+ end
67
43
 
68
- def has_children?
69
- defined? @children and @children.size > 0
70
- end
44
+ # Create a new Node with contents. Also indicate if this node has
45
+ # inline children or block children.
46
+ #
47
+ # @param contents [Array<pandoc node in JSON>] the contents of
48
+ # this node
49
+ # @param inline_children [Boolean] does this node have
50
+ # inline children (true) or block children (false).
51
+ def initialize(contents, inline_children = false)
52
+ @children = []
53
+ @parent = nil
54
+
55
+ if contents.is_a? Array
56
+ contents.each do |elt|
57
+ if PandocFilter.const_defined? elt["t"]
58
+ child = PandocFilter.const_get(elt["t"]).new elt["c"]
59
+ else
60
+ if inline_children
61
+ child = PandocFilter::Inline.new elt["c"]
62
+ else
63
+ child = PandocFilter::Plain.new elt["c"]
64
+ end
65
+ end
66
+
67
+ child.parent = self
68
+ @children.push child
69
+ end
70
+ end
71
+ end
71
72
 
72
- def children
73
- if has_children?
74
- @children
75
- else
76
- []
77
- end
78
- end
73
+ # For each child of this Node, yield the child
74
+ #
75
+ # @yield [Node]
76
+ def each()
77
+ @children.each do |child|
78
+ yield child
79
+ end
80
+ end
79
81
 
80
- def children= list
81
- @children = list
82
- end
82
+ # Does this node have any children?
83
+ #
84
+ # @return [Boolean] True if this node has any children, false
85
+ # otherwise.
86
+ def has_children?()
87
+ defined? @children and @children.size > 0
88
+ end
83
89
 
84
- def has_parent?
85
- not @parent.nil?
86
- end
90
+ # Get this node's children,
91
+ #
92
+ # @return [Array<Node>] this node's children as an Array.
93
+ def children()
94
+ if has_children?
95
+ @children
96
+ else
97
+ []
98
+ end
99
+ end
87
100
 
88
- def is_root?
89
- not has_parent?
90
- end
101
+ # Set this node's children
102
+ #
103
+ # @param list [Array<Node>] a list with nodes
104
+ def children=(list)
105
+ @children = list
106
+ end
91
107
 
92
- def is_node?
93
- not is_leaf
94
- end
108
+ # Does this node have a parent?
109
+ #
110
+ # @return [Boolean] True if this node has a parent, false
111
+ # otherwise.
112
+ def has_parent?()
113
+ not @parent.nil?
114
+ end
95
115
 
96
- def is_leaf?
97
- not has_children?
98
- end
116
+ # Is this a root node?
117
+ #
118
+ # @return [Boolean] True if this node has a no parent, false
119
+ # otherwise
120
+ def is_root?()
121
+ not has_parent?
122
+ end
99
123
 
124
+ # Is this Node a Node or a leaf? See #is_leaf?
125
+ #
126
+ # @return [Boolean] A node is a node if it is not a leaf.
127
+ def is_node?()
128
+ not is_leaf
129
+ end
100
130
 
101
- def has_string?
102
- false
103
- end
131
+ # Is this Node a leaf? See also #is_node?
132
+ #
133
+ # @return [Boolean] A node is a leaf when it has no children
134
+ # false otherwise
135
+ def is_leaf?()
136
+ not has_children?
137
+ end
138
+
139
+ # Does this node has a string value?
140
+ #
141
+ # @return [Boolean] true if this node has a string value, false
142
+ # otherwise
143
+ def has_string?()
144
+ false
145
+ end
104
146
 
105
- def has_inline?
106
- false
107
- end
147
+ # Does this node have Inline contents?
148
+ #
149
+ # @return [Boolean] true if this node has Inline contents, false
150
+ # otherwise
151
+ def has_inline?()
152
+ false
153
+ end
108
154
 
109
- def has_block?
110
- false
111
- end
155
+ # Does this node have Block contents?
156
+ #
157
+ # @return [Boolean] true if this node has Block contents, false
158
+ # otherwise
159
+ def has_block?()
160
+ false
161
+ end
112
162
 
113
- def is_block?
114
- false
115
- end
163
+ # Is this node a Block level node?
164
+ #
165
+ # @return [Boolean] true if this node is a block level node, false
166
+ # otherwise
167
+ def is_block?()
168
+ false
169
+ end
116
170
 
117
- def can_act_as_both_block_and_inline?
118
- false
119
- end
171
+ # Can this node act both as a block and inline node? Some nodes
172
+ # are hybrids in this regard, like Math or Image
173
+ #
174
+ # @return [Boolean]
175
+ def can_act_as_both_block_and_inline?()
176
+ false
177
+ end
120
178
 
121
- def is_inline?
122
- false
123
- end
179
+ # Is this an Inline level node?
180
+ #
181
+ # @return [Boolean] true if this node is an inline level node,
182
+ # false otherwise
183
+ def is_inline?()
184
+ false
185
+ end
124
186
 
125
- def has_class? name
126
- if not @attr.nil?
127
- @attr.has_class? name
128
- else
129
- false
130
- end
131
- end
187
+ # If this node has attributes with classes, is name among them?
188
+ #
189
+ # @param name [String] the class name to search for
190
+ #
191
+ # @return [Boolean] true if this node has attributes with classes
192
+ # and name is among them, false otherwise
193
+ def has_class?(name)
194
+ if not @attr.nil?
195
+ @attr.has_class? name
196
+ else
197
+ false
198
+ end
199
+ end
132
200
 
133
- def to_s
134
- self.class.name
135
- end
201
+ # A String representation of this Node
202
+ #
203
+ # @return [String]
204
+ def to_s()
205
+ self.class.name
206
+ end
136
207
 
137
- def type
138
- ast_type
139
- end
208
+ # The pandoc type of this Node
209
+ #
210
+ # @return [String]
211
+ def type()
212
+ ast_type
213
+ end
140
214
 
141
- def ast_type
142
- self.class.name.split("::").last
143
- end
215
+ # The AST type of this Node
216
+ #
217
+ # @return [String]
218
+ def ast_type()
219
+ self.class.name.split("::").last
220
+ end
144
221
 
145
- def ast_contents
146
- if has_children?
147
- @children.map {|child| child.to_ast}
148
- else
149
- []
150
- end
151
- end
222
+ # An AST representation of the contents of this node
223
+ #
224
+ # @return [Array]
225
+ def ast_contents()
226
+ if has_children?
227
+ @children.map {|child| child.to_ast}
228
+ else
229
+ []
230
+ end
231
+ end
232
+
233
+ # Create an AST representation of this Node
234
+ #
235
+ # @return [Hash]
236
+ def to_ast()
237
+ {
238
+ "t" => ast_type,
239
+ "c" => ast_contents
240
+ }
241
+ end
152
242
 
153
- def ast_markdown_contents
154
- if has_children?
155
- @children.map {|child| child.to_ast}
156
- else
157
- []
158
243
  end
159
- end
160
-
161
- def to_ast
162
- {
163
- "t" => ast_type,
164
- "c" => ast_contents
165
- }
166
- end
167
-
168
244
  end
169
- end
170
245
  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,27 +17,38 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./inline"
23
- require_relative "./block"
22
+ require_relative "./inline"
23
+ require_relative "./block"
24
24
 
25
- # Note [Block]
26
- class Note < Inline
27
- def has_block?
28
- true
29
- end
25
+ # A Note node like a foot note or end note. It is a special node in
26
+ # the sense that itself is an Inline level node, but its contents are
27
+ # Block level.
28
+ class Note < Inline
30
29
 
31
- def has_inline?
32
- false
33
- end
34
-
35
- # Although Note is defined to be inline, often it will act like a block
36
- # element.
37
- def can_act_as_both_block_and_inline?
38
- true
39
- end
40
-
30
+ # Has this Note block contents?
31
+ #
32
+ # @return [Boolean] true
33
+ def has_block?
34
+ true
35
+ end
36
+
37
+ # Has this Note inline contents?
38
+ #
39
+ # @return [Boolean] false
40
+ def has_inline?
41
+ false
42
+ end
43
+
44
+ # Although Note is defined to be inline, often it will act like a block
45
+ # element.
46
+ #
47
+ # @return [Boolean] true
48
+ def can_act_as_both_block_and_inline?
49
+ true
50
+ end
51
+
52
+ end
41
53
  end
42
- end
43
54
  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,11 +17,11 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
21
- require_relative "./empty_block"
20
+ module PandocFilter
21
+ require_relative "./empty_block"
22
22
 
23
- # Null
24
- class Null < EmptyBlock
23
+ # A Null node is an EmptyBlock node
24
+ class Null < EmptyBlock
25
+ end
25
26
  end
26
- end
27
27
  end