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 2020 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,66 +18,62 @@
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 "csv"
20
- require_relative "./block.rb"
21
-
21
+ require 'csv'
22
+ require_relative 'block'
23
+
22
24
  module Paru
23
- module PandocFilter
25
+ module PandocFilter
26
+ # A TableEnd node is the base class for the TableHead and TableFoot
27
+ # nodes. It has attributes and one or more rows.
28
+ #
29
+ # @!attribute attr
30
+ # @return Attr
31
+ #
32
+ # @!attribute rows
33
+ # @return [Row]
34
+ class TableEnd < Block
35
+ attr_accessor :attr
24
36
 
25
- # A TableEnd node is the base class for the TableHead and TableFoot
26
- # nodes. It has attributes and one or more rows.
27
- #
28
- # @!attribute attr
29
- # @return Attr
30
- #
31
- # @!attribute rows
32
- # @return [Row]
33
- class TableEnd < Block
34
- attr_accessor :attr
37
+ # Create a new TableEnd based on the contents
38
+ #
39
+ # @param contents [Array]
40
+ def initialize(contents)
41
+ @attr = Attr.new contents[0]
42
+ super([])
43
+ contents[1].each do |row|
44
+ @children.push Row.new row
45
+ end
46
+ end
35
47
 
36
- # Create a new TableEnd based on the contents
37
- #
38
- # @param contents [Array]
39
- def initialize(contents)
40
- @attr = Attr.new contents[0]
41
- super []
42
- contents[1].each do |row|
43
- @children.push Row.new row
44
- end
45
- end
48
+ def rows
49
+ @children
50
+ end
46
51
 
47
- def rows()
48
- @children
49
- end
50
-
51
- # The AST contents of this Table node
52
- #
53
- # @return [Array]
54
- def ast_contents()
55
- [
56
- @attr.to_ast,
57
- @children.map {|row| row.to_ast},
58
- ]
59
- end
52
+ # The AST contents of this Table node
53
+ #
54
+ # @return [Array]
55
+ def ast_contents
56
+ [
57
+ @attr.to_ast,
58
+ @children.map(&:to_ast)
59
+ ]
60
+ end
60
61
 
61
- # Create an AST representation of this Node
62
- #
63
- # @return [Hash]
64
- def to_ast()
65
- ast_contents()
66
- end
67
-
68
- # Convert this table end to a 2D table of markdown strings for each
69
- # cell
70
- #
71
- # @return [String[][]] This Table as a 2D array of cells
72
- # represented by their markdown strings.
73
- def to_array()
74
- @children.map do |row|
75
- row.to_array
76
- end
77
- end
62
+ # Create an AST representation of this Node
63
+ #
64
+ # @return [Hash]
65
+ def to_ast
66
+ ast_contents
67
+ end
78
68
 
79
- end
69
+ # Convert this table end to a 2D table of markdown strings for each
70
+ # cell
71
+ #
72
+ # @return [String[][]] This Table as a 2D array of cells
73
+ # represented by their markdown strings.
74
+ def to_array
75
+ @children.map(&:to_array)
76
+ end
80
77
  end
78
+ end
81
79
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,13 +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 "./table_end.rb"
20
-
21
- module Paru
22
- module PandocFilter
21
+ require_relative 'table_end'
23
22
 
24
- # A TableFoot node represents the heading of a table.
25
- class TableFoot < TableEnd
26
- end
23
+ module Paru
24
+ module PandocFilter
25
+ # A TableFoot node represents the heading of a table.
26
+ class TableFoot < TableEnd
27
27
  end
28
+ end
28
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,13 +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 "./table_end.rb"
20
-
21
- module Paru
22
- module PandocFilter
21
+ require_relative 'table_end'
23
22
 
24
- # A TableHead node represents the heading of a table.
25
- class TableHead < TableEnd
26
- end
23
+ module Paru
24
+ module PandocFilter
25
+ # A TableHead node represents the heading of a table.
26
+ class TableHead < TableEnd
27
27
  end
28
+ end
28
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
  #
@@ -17,34 +19,34 @@
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Paru
20
- module PandocFilter
21
- # A Target represents the target of a link or image
22
- #
23
- # @!attribute url
24
- # @return [String] the target
25
- #
26
- # @!attribute title
27
- # @return [String] the title of the target
28
- class Target
29
- attr_accessor :url, :title
22
+ module PandocFilter
23
+ # A Target represents the target of a link or image
24
+ #
25
+ # @!attribute url
26
+ # @return [String] the target
27
+ #
28
+ # @!attribute title
29
+ # @return [String] the title of the target
30
+ class Target
31
+ attr_accessor :url, :title
30
32
 
31
- # Create a new Target based on the contents
32
- #
33
- # @param contents [Array]
34
- def initialize(contents)
35
- @url = contents[0]
36
- @title = contents[1]
37
- end
33
+ # Create a new Target based on the contents
34
+ #
35
+ # @param contents [Array]
36
+ def initialize(contents)
37
+ @url = contents[0]
38
+ @title = contents[1]
39
+ end
38
40
 
39
- # Create an AST representation of this Target
40
- #
41
- # @return [Array]
42
- def to_ast()
43
- [
44
- @url,
45
- @title
46
- ]
47
- end
48
- end
41
+ # Create an AST representation of this Target
42
+ #
43
+ # @return [Array]
44
+ def to_ast
45
+ [
46
+ @url,
47
+ @title
48
+ ]
49
+ end
49
50
  end
51
+ end
50
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2020 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 "./inline.rb"
21
+ require_relative 'inline'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # A Underline inline node
24
- class Underline < Inline
25
- end
24
+ module PandocFilter
25
+ # A Underline inline node
26
+ class Underline < Inline
26
27
  end
28
+ end
27
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
@@ -16,91 +18,88 @@
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 "../filter_error.rb"
21
+ require_relative 'node'
22
+ require_relative '../filter_error'
21
23
 
22
24
  module Paru
23
- module PandocFilter
24
-
25
- # Values without value are encoded in their type name.
26
- VALUE_ENCODED_IN_TYPE_NAME = :value_encoded_in_type_name
27
-
28
- # A Value node that represents some sort of metadata about block or
29
- # inline nodes
30
- class Value < Node
25
+ module PandocFilter
26
+ # Values without value are encoded in their type name.
27
+ VALUE_ENCODED_IN_TYPE_NAME = :value_encoded_in_type_name
31
28
 
32
- # Create a new Value with contents. Also indicate if this node has
33
- # inline children or block children.
34
- #
35
- # @param contents [Array<pandoc node in JSON> = []] the contents of
36
- # this node
37
- def initialize(contents)
38
- @type = contents['t']
29
+ # A Value node that represents some sort of metadata about block or
30
+ # inline nodes
31
+ class Value < Node
32
+ # Create a new Value with contents. Also indicate if this node has
33
+ # inline children or block children.
34
+ #
35
+ # @param contents [Array<pandoc node in JSON> = []] the contents of
36
+ # this node
37
+ def initialize(contents)
38
+ @type = contents['t']
39
39
 
40
- if contents.has_key? 'c' then
41
- @value = contents['c']
42
- else
43
- @value = VALUE_ENCODED_IN_TYPE_NAME
44
- end
45
- end
40
+ @value = if contents.key? 'c'
41
+ contents['c']
42
+ else
43
+ VALUE_ENCODED_IN_TYPE_NAME
44
+ end
45
+ end
46
46
 
47
- # Get the encoded value
48
- #
49
- # @return [Any]
50
- def value()
51
- if type_encodes_value? then
52
- @type
53
- else
54
- @value
55
- end
56
- end
47
+ # Get the encoded value
48
+ #
49
+ # @return [Any]
50
+ def value
51
+ if type_encodes_value?
52
+ @type
53
+ else
54
+ @value
55
+ end
56
+ end
57
57
 
58
- # Set the encoded value
59
- #
60
- # @param [Any] new_value
61
- def value=(new_value)
62
- if type_encodes_value? then
63
- @type = new_value
64
- else
65
- @value = new_value
66
- end
67
- end
58
+ # Set the encoded value
59
+ #
60
+ # @param [Any] new_value
61
+ def value=(new_value)
62
+ if type_encodes_value?
63
+ @type = new_value
64
+ else
65
+ @value = new_value
66
+ end
67
+ end
68
68
 
69
- # Is this node a block?
70
- #
71
- # @return [Boolean] false
72
- def is_block?
73
- false
74
- end
69
+ # Is this node a block?
70
+ #
71
+ # @return [Boolean] false
72
+ def is_block?
73
+ false
74
+ end
75
75
 
76
- # Is this node an inline node?
77
- #
78
- # @return [Boolean] false
79
- def is_inline?
80
- false
81
- end
76
+ # Is this node an inline node?
77
+ #
78
+ # @return [Boolean] false
79
+ def is_inline?
80
+ false
81
+ end
82
82
 
83
- # The AST type of this Node
84
- #
85
- # @return [String]
86
- def ast_type()
87
- @type
88
- end
83
+ # The AST type of this Node
84
+ #
85
+ # @return [String]
86
+ def ast_type
87
+ @type
88
+ end
89
89
 
90
- # Create an AST representation of this Node
91
- #
92
- # @return [Hash]
93
- def to_ast()
94
- return {
95
- "t" => ast_type,
96
- "c" => if type_encodes_value? then nil else @value end
97
- }
98
- end
90
+ # Create an AST representation of this Node
91
+ #
92
+ # @return [Hash]
93
+ def to_ast
94
+ {
95
+ 't' => ast_type,
96
+ 'c' => type_encodes_value? ? nil : @value
97
+ }
98
+ end
99
99
 
100
- @private
101
- def type_encodes_value?()
102
- return @value == VALUE_ENCODED_IN_TYPE_NAME
103
- end
104
- end
100
+ def type_encodes_value?
101
+ @value == VALUE_ENCODED_IN_TYPE_NAME
102
+ end
105
103
  end
104
+ end
106
105
  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,31 +18,30 @@
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
- # Version is a general Node containing the pandoc-api-version. It has
24
- # the format major.minor.revision.sub
25
- class Version < Node
26
-
27
- # Create a Version node based on contents
28
- #
29
- # @param contents [Array<Integer>] a list with api, major, minor,
30
- # revision number
31
- def initialize(contents)
32
- @api, @major, @minor, @revision = contents
33
- end
24
+ module PandocFilter
25
+ # Version is a general Node containing the pandoc-api-version. It has
26
+ # the format major.minor.revision.sub
27
+ class Version < Node
28
+ # Create a Version node based on contents
29
+ #
30
+ # @param contents [Array<Integer>] a list with api, major, minor,
31
+ # revision number
32
+ def initialize(contents)
33
+ @api, @major, @minor, @revision = contents
34
+ end
34
35
 
35
- # The AST type is "pandoc-api-version"
36
- def ast_type
37
- "pandoc-api-version"
38
- end
36
+ # The AST type is "pandoc-api-version"
37
+ def ast_type
38
+ 'pandoc-api-version'
39
+ end
39
40
 
40
- # Create an AST representation of this Version
41
- def to_ast()
42
- [@api, @major, @minor, @revision].select {|v| !v.nil?}
43
- end
44
- end
41
+ # Create an AST representation of this Version
42
+ def to_ast
43
+ [@api, @major, @minor, @revision].compact
44
+ end
45
45
  end
46
+ end
46
47
  end