paru 1.5.0 → 1.5.1

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paru/error.rb +6 -4
  3. data/lib/paru/filter/ast_manipulation.rb +90 -91
  4. data/lib/paru/filter/attr.rb +75 -69
  5. data/lib/paru/filter/block.rb +15 -14
  6. data/lib/paru/filter/block_quote.rb +14 -12
  7. data/lib/paru/filter/bullet_list.rb +17 -16
  8. data/lib/paru/filter/caption.rb +50 -48
  9. data/lib/paru/filter/cell.rb +52 -50
  10. data/lib/paru/filter/citation.rb +53 -51
  11. data/lib/paru/filter/cite.rb +34 -33
  12. data/lib/paru/filter/code.rb +51 -49
  13. data/lib/paru/filter/code_block.rb +76 -76
  14. data/lib/paru/filter/col_spec.rb +58 -56
  15. data/lib/paru/filter/definition_list.rb +51 -52
  16. data/lib/paru/filter/definition_list_item.rb +45 -43
  17. data/lib/paru/filter/div.rb +37 -35
  18. data/lib/paru/filter/document.rb +112 -115
  19. data/lib/paru/filter/emph.rb +7 -5
  20. data/lib/paru/filter/empty_block.rb +17 -16
  21. data/lib/paru/filter/empty_inline.rb +23 -22
  22. data/lib/paru/filter/figure.rb +41 -39
  23. data/lib/paru/filter/header.rb +41 -39
  24. data/lib/paru/filter/horizontal_rule.rb +7 -5
  25. data/lib/paru/filter/image.rb +13 -12
  26. data/lib/paru/filter/inline.rb +27 -26
  27. data/lib/paru/filter/inner_markdown.rb +60 -62
  28. data/lib/paru/filter/int_value.rb +19 -18
  29. data/lib/paru/filter/line_block.rb +13 -11
  30. data/lib/paru/filter/line_break.rb +7 -5
  31. data/lib/paru/filter/link.rb +34 -33
  32. data/lib/paru/filter/list.rb +37 -37
  33. data/lib/paru/filter/list_attributes.rb +52 -51
  34. data/lib/paru/filter/math.rb +66 -64
  35. data/lib/paru/filter/meta.rb +40 -39
  36. data/lib/paru/filter/meta_blocks.rb +7 -5
  37. data/lib/paru/filter/meta_bool.rb +7 -5
  38. data/lib/paru/filter/meta_inlines.rb +9 -7
  39. data/lib/paru/filter/meta_list.rb +7 -5
  40. data/lib/paru/filter/meta_map.rb +50 -49
  41. data/lib/paru/filter/meta_string.rb +7 -6
  42. data/lib/paru/filter/meta_value.rb +26 -25
  43. data/lib/paru/filter/metadata.rb +150 -88
  44. data/lib/paru/filter/node.rb +400 -406
  45. data/lib/paru/filter/note.rb +29 -29
  46. data/lib/paru/filter/null.rb +7 -5
  47. data/lib/paru/filter/ordered_list.rb +50 -49
  48. data/lib/paru/filter/para.rb +21 -20
  49. data/lib/paru/filter/plain.rb +23 -21
  50. data/lib/paru/filter/quoted.rb +28 -26
  51. data/lib/paru/filter/short_caption.rb +7 -5
  52. data/lib/paru/filter/small_caps.rb +8 -7
  53. data/lib/paru/filter/soft_break.rb +7 -5
  54. data/lib/paru/filter/space.rb +7 -5
  55. data/lib/paru/filter/span.rb +29 -27
  56. data/lib/paru/filter/str.rb +33 -32
  57. data/lib/paru/filter/strikeout.rb +7 -6
  58. data/lib/paru/filter/strong.rb +7 -6
  59. data/lib/paru/filter/subscript.rb +7 -6
  60. data/lib/paru/filter/superscript.rb +7 -6
  61. data/lib/paru/filter/table.rb +201 -210
  62. data/lib/paru/filter/table_body.rb +67 -67
  63. data/lib/paru/filter/table_end.rb +53 -55
  64. data/lib/paru/filter/table_foot.rb +8 -7
  65. data/lib/paru/filter/table_head.rb +8 -7
  66. data/lib/paru/filter/target.rb +29 -27
  67. data/lib/paru/filter/underline.rb +7 -5
  68. data/lib/paru/filter/value.rb +74 -75
  69. data/lib/paru/filter/version.rb +23 -22
  70. data/lib/paru/filter.rb +355 -331
  71. data/lib/paru/filter_error.rb +7 -5
  72. data/lib/paru/info.rb +29 -30
  73. data/lib/paru/pandoc.rb +241 -248
  74. data/lib/paru/pandoc2yaml.rb +51 -42
  75. data/lib/paru/selector.rb +193 -184
  76. data/lib/paru.rb +3 -1
  77. metadata +4 -73
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,79 +18,79 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./inline.rb"
21
+ require_relative 'inline'
20
22
 
21
23
  module Paru
22
- module PandocFilter
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
24
+ module PandocFilter
25
+ # A Math Inline node with the type of math node and the mathematical
26
+ # contents
27
+ #
28
+ # @!attribute math_type
29
+ # @return [Hash]
30
+ # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:MathType
31
+ #
32
+ # @!attribute string
33
+ # @return [String]
34
+ class Math < Inline
35
+ attr_accessor :math_type, :string
34
36
 
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
37
+ # Create a new Math node with contents
38
+ #
39
+ # @param contents [Array] an array with the type and contents
40
+ def initialize(contents)
41
+ @math_type, @string = contents
42
+ end
41
43
 
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
44
+ # Is this an inline node?
45
+ #
46
+ # @return [Boolean] true if math type is "InlineMath", false
47
+ # otherwise
48
+ def inline?
49
+ @math_type['t'] == 'InlineMath'
50
+ end
49
51
 
50
- # Convert this Math node's content to Inline
51
- def inline!()
52
- @math_type = {
53
- "t" => "InlineMath"
54
- }
55
- end
52
+ # Convert this Math node's content to Inline
53
+ def inline!
54
+ @math_type = {
55
+ 't' => 'InlineMath'
56
+ }
57
+ end
56
58
 
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
59
+ # Should this math be displayed as a block?
60
+ #
61
+ # @return [Boolean] true if type is "DisplayMath"
62
+ def display?
63
+ @math_type['t'] == 'DisplayMath'
64
+ end
63
65
 
64
- # Make this Math node's content display as a block
65
- def display!()
66
- @math_type = {
67
- "t" => "DisplayMath"
68
- }
69
- end
66
+ # Make this Math node's content display as a block
67
+ def display!
68
+ @math_type = {
69
+ 't' => 'DisplayMath'
70
+ }
71
+ end
70
72
 
71
- # Create an AST representation of this Math node
72
- def ast_contents()
73
- [
74
- @math_type,
75
- @string
76
- ]
77
- end
73
+ # Create an AST representation of this Math node
74
+ def ast_contents
75
+ [
76
+ @math_type,
77
+ @string
78
+ ]
79
+ end
78
80
 
79
- # Has this Math node string contents?
80
- #
81
- # @return [Boolean] true
82
- def has_string?()
83
- true
84
- end
81
+ # Has this Math node string contents?
82
+ #
83
+ # @return [Boolean] true
84
+ def has_string?
85
+ true
86
+ end
85
87
 
86
- # Has this Math node inline contents?
87
- #
88
- # @return [Boolean] false
89
- def has_inline?()
90
- false
91
- end
92
- end
88
+ # Has this Math node inline contents?
89
+ #
90
+ # @return [Boolean] false
91
+ def has_inline?
92
+ false
93
+ end
93
94
  end
95
+ end
94
96
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,48 +18,47 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./meta_map.rb"
20
-
21
- module Paru
22
- module PandocFilter
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
- # The type of a Meta is "meta"
29
- #
30
- # @return [String] "meta"
31
- def ast_type()
32
- "meta"
33
- end
21
+ require_relative 'meta_map'
34
22
 
35
- # Convert this Meta node to an AST representation
36
- def to_ast()
37
- ast_contents
38
- end
23
+ module Paru
24
+ module PandocFilter
25
+ # A Meta node represents the metadata of a document. It is a MetaMap
26
+ # node.
27
+ #
28
+ # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:Meta
29
+ class Meta < MetaMap
30
+ # The type of a Meta is "meta"
31
+ #
32
+ # @return [String] "meta"
33
+ def ast_type
34
+ 'meta'
35
+ end
39
36
 
40
- # Convert this Meta node to an {MetaMap} node
41
- #
42
- # @return [MetaMap] a MetaMap representation of this metadata
43
- def to_meta_map()
44
- map = MetaMap.new
45
- map.children = @children
46
- map
47
- end
37
+ # Convert this Meta node to an AST representation
38
+ def to_ast
39
+ ast_contents
40
+ end
48
41
 
49
- # Convert a {MetaMap} node to a {Meta} node
50
- #
51
- # @param meta_map [MetaMap] the {MetaMap} node to convert to a
52
- # {Meta} node.
53
- #
54
- # @return [Meta]
55
- def self.from_meta_map(meta_map)
56
- meta = Meta.new {}
57
- meta.children = meta_map.children unless meta_map.children.nil? or meta_map.children.empty?
58
- meta
59
- end
42
+ # Convert this Meta node to an {MetaMap} node
43
+ #
44
+ # @return [MetaMap] a MetaMap representation of this metadata
45
+ def to_meta_map
46
+ map = MetaMap.new
47
+ map.children = @children
48
+ map
49
+ end
60
50
 
61
- end
51
+ # Convert a {MetaMap} node to a {Meta} node
52
+ #
53
+ # @param meta_map [MetaMap] the {MetaMap} node to convert to a
54
+ # {Meta} node.
55
+ #
56
+ # @return [Meta]
57
+ def self.from_meta_map(meta_map)
58
+ meta = Meta.new {}
59
+ meta.children = meta_map.children unless meta_map.children.nil? || meta_map.children.empty?
60
+ meta
61
+ end
62
62
  end
63
+ end
63
64
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,12 +18,12 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./node.rb"
21
+ require_relative 'node'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # A MetaBlocks Node contains a list of {Block} nodes
24
- class MetaBlocks < Node
25
- end
24
+ module PandocFilter
25
+ # A MetaBlocks Node contains a list of {Block} nodes
26
+ class MetaBlocks < Node
26
27
  end
28
+ end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,12 +18,12 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./meta_value.rb"
21
+ require_relative 'meta_value'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # A MetaBool Note representa a Boolean value
24
- class MetaBool < MetaValue
25
- end
24
+ module PandocFilter
25
+ # A MetaBool Note representa a Boolean value
26
+ class MetaBool < MetaValue
26
27
  end
28
+ end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,14 +18,14 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./node.rb"
20
- require_relative "./inner_markdown.rb"
21
+ require_relative 'node'
22
+ require_relative 'inner_markdown'
21
23
 
22
24
  module Paru
23
- module PandocFilter
24
- # A MetaInlines node contains a list of {Inline} nodes
25
- class MetaInlines < Node
26
- include InnerMarkdown
27
- end
25
+ module PandocFilter
26
+ # A MetaInlines node contains a list of {Inline} nodes
27
+ class MetaInlines < Node
28
+ include InnerMarkdown
28
29
  end
30
+ end
29
31
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,12 +18,12 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./node.rb"
21
+ require_relative 'node'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # A MetaList node contains a list of MetaValue nodes
24
- class MetaList < Node
25
- end
24
+ module PandocFilter
25
+ # A MetaList node contains a list of MetaValue nodes
26
+ class MetaList < Node
26
27
  end
28
+ end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,65 +18,64 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./node.rb"
21
+ require_relative 'node'
20
22
 
21
- require_relative "../pandoc.rb"
23
+ require_relative '../pandoc'
22
24
 
23
25
  module Paru
24
- module PandocFilter
25
- # A MetaMap Node is a map of String keys with MetaValue values
26
- class MetaMap < Node
27
- include Enumerable
26
+ module PandocFilter
27
+ # A MetaMap Node is a map of String keys with MetaValue values
28
+ class MetaMap < Node
29
+ include Enumerable
28
30
 
29
- # Create a new MetaMap based on the contents
30
- #
31
- # @param contents [Hash = {}] a list of key-value pairs, defaults
32
- # to an empty hash
33
- def initialize(contents = {})
34
- @children = Hash.new
31
+ # Create a new MetaMap based on the contents
32
+ #
33
+ # @param contents [Hash = {}] a list of key-value pairs, defaults
34
+ # to an empty hash
35
+ def initialize(contents = {})
36
+ @children = {}
35
37
 
36
- if contents.is_a? Hash
37
- contents.each_pair do |key, value|
38
- if not value.empty? and PandocFilter.const_defined? value["t"]
39
- @children[key] = PandocFilter.const_get(value["t"]).new value["c"]
40
- end
41
- end
42
- end
43
- end
38
+ return unless contents.is_a? Hash
44
39
 
45
- # Get the value belonging to key.
46
- #
47
- # @param key [String] the key
48
- #
49
- # @return [MetaValue] the value belonging to the key
50
- def [](key)
51
- @children[key]
52
- end
40
+ contents.each_pair do |key, value|
41
+ if !value.empty? && PandocFilter.const_defined?(value['t'])
42
+ @children[key] = PandocFilter.const_get(value['t']).new value['c']
43
+ end
44
+ end
45
+ end
53
46
 
54
- # Set a value with a key.
55
- #
56
- # @param key [String] the key to set
57
- # @param value [MetaBlocks|MetaBool|MetaInlines|MetaList|MetaMap|MetaString|MetaValue] the value to set
58
- def []=(key, value)
59
- @children[key] = value
60
- end
47
+ # Get the value belonging to key.
48
+ #
49
+ # @param key [String] the key
50
+ #
51
+ # @return [MetaValue] the value belonging to the key
52
+ def [](key)
53
+ @children[key]
54
+ end
61
55
 
62
- # Execute block for each key-value pair
63
- def each()
64
- @children.each do |key, value|
65
- yield(key, value)
66
- end
67
- end
56
+ # Set a value with a key.
57
+ #
58
+ # @param key [String] the key to set
59
+ # @param value [MetaBlocks|MetaBool|MetaInlines|MetaList|MetaMap|MetaString|MetaValue] the value to set
60
+ def []=(key, value)
61
+ @children[key] = value
62
+ end
68
63
 
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 if @children.is_a? Hash
75
- ast
76
- end
64
+ # Execute block for each key-value pair
65
+ def each(&block)
66
+ @children.each(&block)
67
+ end
77
68
 
69
+ # The AST contents
70
+ def ast_contents
71
+ ast = {}
72
+ if @children.is_a? Hash
73
+ @children.each_pair do |key, value|
74
+ ast[key] = value.to_ast
75
+ end
78
76
  end
77
+ ast
78
+ end
79
79
  end
80
+ end
80
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -17,12 +19,11 @@
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Paru
20
- module PandocFilter
21
-
22
- require_relative "./meta_value.rb"
22
+ module PandocFilter
23
+ require_relative 'meta_value'
23
24
 
24
- # A MetaString Node represents a String value
25
- class MetaString < MetaValue
26
- end
25
+ # A MetaString Node represents a String value
26
+ class MetaString < MetaValue
27
27
  end
28
+ end
28
29
  end
@@ -1,4 +1,6 @@
1
- #--
1
+ # frozen_string_literal: true
2
+
3
+ #--
2
4
  # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
4
6
  # This file is part of Paru
@@ -16,34 +18,33 @@
16
18
  # You should have received a copy of the GNU General Public License
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
- require_relative "./node.rb"
20
- require_relative "./inner_markdown.rb"
21
+ require_relative 'node'
22
+ require_relative 'inner_markdown'
21
23
 
22
24
  module Paru
23
- module PandocFilter
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|Boolean]
30
- class MetaValue < Node
31
- include InnerMarkdown
32
-
33
- attr_accessor :value
25
+ module PandocFilter
26
+ # A MetaValue Node is either a MetaMap, MetaList, MetaBool, MetaString, MetaInlines, or a MetaBlocks.
27
+ #
28
+ # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:MetaValue
29
+ #
30
+ # @!attribute value
31
+ # @return [String|Boolean]
32
+ class MetaValue < Node
33
+ include InnerMarkdown
34
34
 
35
- # Create a new MetaValue Node based on the value
36
- #
37
- # @param value [String]
38
- def initialize(value)
39
- @value = value
40
- end
35
+ attr_accessor :value
41
36
 
42
- # The AST contents
43
- def ast_contents()
44
- @value
45
- end
37
+ # Create a new MetaValue Node based on the value
38
+ #
39
+ # @param value [String]
40
+ def initialize(value)
41
+ @value = value
42
+ end
46
43
 
47
- end
44
+ # The AST contents
45
+ def ast_contents
46
+ @value
47
+ end
48
48
  end
49
+ end
49
50
  end