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,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2020, 2023 Huub de Beer <Huub@heerdebeer.org>
4
+ # Copyright 2020--2025 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
4
6
  # This file is part of Paru
5
7
  #
@@ -16,60 +18,60 @@
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 "./block.rb"
20
- require_relative "./value.rb"
21
- require_relative "./int_value.rb"
21
+ require_relative 'block'
22
+ require_relative 'value'
23
+ require_relative 'int_value'
22
24
 
23
25
  module Paru
24
- module PandocFilter
25
- # A Cell node represents a cell in a table's head, body, or foot.
26
- #
27
- # @!attribute attr
28
- # @return Attr
29
- #
30
- # @!attribute alignment
31
- # @return Value containing a String, one of AlignRight, AlignLeft,
32
- # AlignCenter, or AlignDefault.
33
- #
34
- # @!attribute rowspan
35
- # @return Value containing an Integer
36
- #
37
- # @!attribute colspan
38
- # @return Value containing an Integer
39
- class Cell < Block
40
- attr_accessor :attr, :alignment, :rowspan, :colspan
26
+ module PandocFilter
27
+ # A Cell node represents a cell in a table's head, body, or foot.
28
+ #
29
+ # @!attribute attr
30
+ # @return Attr
31
+ #
32
+ # @!attribute alignment
33
+ # @return Value containing a String, one of AlignRight, AlignLeft,
34
+ # AlignCenter, or AlignDefault.
35
+ #
36
+ # @!attribute rowspan
37
+ # @return Value containing an Integer
38
+ #
39
+ # @!attribute colspan
40
+ # @return Value containing an Integer
41
+ class Cell < Block
42
+ attr_accessor :attr, :alignment, :rowspan, :colspan
41
43
 
42
- # Create a new Cell based on the row_data
43
- #
44
- # @param contents [Array]
45
- def initialize(contents)
46
- @attr = Attr.new contents[0]
47
- @alignment = Value.new contents[1]
48
- @rowspan = IntValue.new contents[2]
49
- @colspan = IntValue.new contents[3]
44
+ # Create a new Cell based on the row_data
45
+ #
46
+ # @param contents [Array]
47
+ def initialize(contents)
48
+ @attr = Attr.new contents[0]
49
+ @alignment = Value.new contents[1]
50
+ @rowspan = IntValue.new contents[2]
51
+ @colspan = IntValue.new contents[3]
50
52
 
51
- super contents[4]
52
- end
53
+ super(contents[4])
54
+ end
53
55
 
54
- # The AST contents of this Cell
55
- #
56
- # @return [Array]
57
- def ast_contents
58
- [
59
- @attr.to_ast,
60
- @alignment.to_ast,
61
- @rowspan.to_ast,
62
- @colspan.to_ast,
63
- @children.map {|child| child.to_ast}
64
- ]
65
- end
56
+ # The AST contents of this Cell
57
+ #
58
+ # @return [Array]
59
+ def ast_contents
60
+ [
61
+ @attr.to_ast,
62
+ @alignment.to_ast,
63
+ @rowspan.to_ast,
64
+ @colspan.to_ast,
65
+ @children.map(&:to_ast)
66
+ ]
67
+ end
66
68
 
67
- # Create an AST representation of this Node
68
- #
69
- # @return [Hash]
70
- def to_ast()
71
- ast_contents()
72
- end
73
- end
69
+ # Create an AST representation of this Node
70
+ #
71
+ # @return [Hash]
72
+ def to_ast
73
+ ast_contents
74
+ end
74
75
  end
76
+ end
75
77
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
4
+ # Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
4
6
  # This file is part of Paru
5
7
  #
@@ -16,58 +18,58 @@
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"
20
-
21
+ require_relative 'inline'
22
+
21
23
  module Paru
22
- module PandocFilter
23
- # A Citation consists of an id, a prefix, a suffix, a mode, a note
24
- # number, and integer hash. All of which are optional.
25
- #
26
- # @see https://hackage.haskell.org/package/pandoc-types-1.17.0.5/docs/Text-Pandoc-Definition.html#t:Citation
27
- #
28
- # @!attribute id
29
- # @return [String]
30
- #
31
- # @!attribute prefix
32
- # @return [Array<Inline>]
33
- #
34
- # @!attribute suffix
35
- # @return [Array<Inline>]
36
- #
37
- # @!attribute mode
38
- # @return [String]
39
- #
40
- # @!attribute note_num
41
- # @return [Integer]
42
- #
43
- # @!attribute hash
44
- # @return [Integer]
45
- class Citation
46
- attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash
24
+ module PandocFilter
25
+ # A Citation consists of an id, a prefix, a suffix, a mode, a note
26
+ # number, and integer hash. All of which are optional.
27
+ #
28
+ # @see https://hackage.haskell.org/package/pandoc-types-1.17.0.5/docs/Text-Pandoc-Definition.html#t:Citation
29
+ #
30
+ # @!attribute id
31
+ # @return [String]
32
+ #
33
+ # @!attribute prefix
34
+ # @return [Array<Inline>]
35
+ #
36
+ # @!attribute suffix
37
+ # @return [Array<Inline>]
38
+ #
39
+ # @!attribute mode
40
+ # @return [String]
41
+ #
42
+ # @!attribute note_num
43
+ # @return [Integer]
44
+ #
45
+ # @!attribute hash
46
+ # @return [Integer]
47
+ class Citation
48
+ attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash
47
49
 
48
- # Create a new Citation node base on an AST specification
49
- #
50
- # @param spec [Hash] the specification of this citation
51
- def initialize(spec)
52
- @id = spec["citationId"] if spec.has_key? "citationId"
53
- @prefix = Inline.new spec["citationPrefix"] if spec.has_key? "citationPrefix"
54
- @suffix = Inline.new spec["citationSuffix"] if spec.has_key? "citationSuffix"
55
- @mode = spec["citationMode"] if spec.has_key? "citationMode"
56
- @note_num = spec["citationNoteNum"] if spec.has_key? "citationNoteNum"
57
- @hash = spec["citationHash"] if spec.has_key? "citationHash"
58
- end
50
+ # Create a new Citation node base on an AST specification
51
+ #
52
+ # @param spec [Hash] the specification of this citation
53
+ def initialize(spec)
54
+ @id = spec['citationId'] if spec.key? 'citationId'
55
+ @prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
56
+ @suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
57
+ @mode = spec['citationMode'] if spec.key? 'citationMode'
58
+ @note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
59
+ @hash = spec['citationHash'] if spec.key? 'citationHash'
60
+ end
59
61
 
60
- # Convert this Citation to an AST representation
61
- def to_ast()
62
- citation = Hash.new
63
- citation["citationId"] = @id if not @id.nil?
64
- citation["citationPrefix"] = @prefix.ast_contents if not @prefix.nil?
65
- citation["citationSuffix"] = @suffix.ast_contents if not @suffix.nil?
66
- citation["citationMode"] = @mode if not @mode.nil?
67
- citation["citationNoteNum"] = @note_num if not @note_num.nil?
68
- citation["citationHash"] = @hash if not @hash.nil?
69
- citation
70
- end
71
- end
62
+ # Convert this Citation to an AST representation
63
+ def to_ast
64
+ citation = {}
65
+ citation['citationId'] = @id unless @id.nil?
66
+ citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
67
+ citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
68
+ citation['citationMode'] = @mode unless @mode.nil?
69
+ citation['citationNoteNum'] = @note_num unless @note_num.nil?
70
+ citation['citationHash'] = @hash unless @hash.nil?
71
+ citation
72
+ end
72
73
  end
74
+ end
73
75
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
4
+ # Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
4
6
  # This file is part of Paru
5
7
  #
@@ -16,42 +18,41 @@
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"
20
- require_relative "./citation.rb"
21
+ require_relative 'inline'
22
+ require_relative 'citation'
21
23
 
22
24
  module Paru
23
- module PandocFilter
24
- # A Cite node, consisting of a list of Citation nodes, and a list of
25
- # Inline nodes
26
- #
27
- # @!attribute citations
28
- # @return [Array<Citation>]
29
- class Cite < Inline
30
- attr_accessor :citations
25
+ module PandocFilter
26
+ # A Cite node, consisting of a list of Citation nodes, and a list of
27
+ # Inline nodes
28
+ #
29
+ # @!attribute citations
30
+ # @return [Array<Citation>]
31
+ class Cite < Inline
32
+ attr_accessor :citations
31
33
 
32
- # Create a new Cite node
33
- #
34
- # @param contents [Array] an array containing a list of citations
35
- # and a list of inline nodes
36
- def initialize(contents)
37
- super contents[1]
38
- @citations = []
39
- contents[0].each do |citation|
40
- @citations.push Citation.new(citation)
41
- end
42
- end
34
+ # Create a new Cite node
35
+ #
36
+ # @param contents [Array] an array containing a list of citations
37
+ # and a list of inline nodes
38
+ def initialize(contents)
39
+ super(contents[1])
40
+ @citations = []
41
+ contents[0].each do |citation|
42
+ @citations.push Citation.new(citation)
43
+ end
44
+ end
43
45
 
44
- # Create an AST representation of this Cite node.
45
- def ast_contents()
46
- [
47
- @citations.map {|citation| citation.to_ast},
48
- super
49
- ]
50
- end
46
+ # Create an AST representation of this Cite node.
47
+ def ast_contents
48
+ [
49
+ @citations.map(&:to_ast),
50
+ super
51
+ ]
52
+ end
51
53
 
52
- #undef_method :inner_markdown
53
- #undef_method :inner_markdown=
54
- end
54
+ # undef_method :inner_markdown
55
+ # undef_method :inner_markdown=
55
56
  end
57
+ end
56
58
  end
57
-
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
4
+ # Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
4
6
  # This file is part of Paru
5
7
  #
@@ -16,59 +18,59 @@
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"
20
- require_relative "./attr.rb"
21
+ require_relative 'inline'
22
+ require_relative 'attr'
21
23
 
22
24
  module Paru
23
- module PandocFilter
24
- # A Code node, with an attribute object and the code itself as a
25
- # string.
26
- #
27
- # @!attribute attr
28
- # @return [Attr]
29
- #
30
- # @!attribute string
31
- # @return [String]
32
- class Code < Inline
33
- attr_accessor :attr, :string
25
+ module PandocFilter
26
+ # A Code node, with an attribute object and the code itself as a
27
+ # string.
28
+ #
29
+ # @!attribute attr
30
+ # @return [Attr]
31
+ #
32
+ # @!attribute string
33
+ # @return [String]
34
+ class Code < Inline
35
+ attr_accessor :attr, :string
36
+
37
+ # Create a new Code node
38
+ #
39
+ # @param contents [Array] an array of the attribute and the code
40
+ def initialize(contents)
41
+ @attr = Attr.new contents[0]
42
+ @string = contents[1]
43
+ end
34
44
 
35
- # Create a new Code node
36
- #
37
- # @param contents [Array] an array of the attribute and the code
38
- def initialize(contents)
39
- @attr = Attr.new contents[0]
40
- @string = contents[1]
41
- end
45
+ # Create an AST representation of this Code node.
46
+ def ast_contents
47
+ [
48
+ @attr.to_ast,
49
+ @string
50
+ ]
51
+ end
42
52
 
43
- # Create an AST representation of this Code node.
44
- def ast_contents()
45
- [
46
- @attr.to_ast,
47
- @string
48
- ]
49
- end
53
+ # Has this Code node a string contents?
54
+ #
55
+ # @return [Boolean] true
56
+ def has_string?
57
+ true
58
+ end
50
59
 
51
- # Has this Code node a string contents?
52
- #
53
- # @return [Boolean] true
54
- def has_string?()
55
- true
56
- end
60
+ # Has this code node inline contents?
61
+ #
62
+ # @return [Boolean] false
63
+ def has_inline?
64
+ false
65
+ end
57
66
 
58
- # Has this code node inline contents?
59
- #
60
- # @return [Boolean] false
61
- def has_inline?()
62
- false
63
- end
64
-
65
- # Get the markdown representation of this Node, including the Node
66
- # itself.
67
- #
68
- # @return [String] the outer markdown representation of this Node
69
- def markdown()
70
- super.strip
71
- end
72
- end
67
+ # Get the markdown representation of this Node, including the Node
68
+ # itself.
69
+ #
70
+ # @return [String] the outer markdown representation of this Node
71
+ def markdown
72
+ super.strip
73
+ end
73
74
  end
75
+ end
74
76
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
4
+ # Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
3
5
  #
4
6
  # This file is part of Paru
5
7
  #
@@ -16,89 +18,87 @@
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 "./block.rb"
20
- require_relative "./attr.rb"
21
- require_relative "./inner_markdown.rb"
21
+ require_relative 'block'
22
+ require_relative 'attr'
23
+ require_relative 'inner_markdown'
22
24
 
23
25
  module Paru
24
- module PandocFilter
25
- # A CodeBlock is a Block level node with an attribute object and the
26
- # code as a string
27
- #
28
- # @!attribute attr
29
- # @return [Attr]
30
- #
31
- # @!attribute string
32
- # @return [String]
33
- class CodeBlock < Block
34
- include InnerMarkdown
35
- attr_accessor :attr, :string
26
+ module PandocFilter
27
+ # A CodeBlock is a Block level node with an attribute object and the
28
+ # code as a string
29
+ #
30
+ # @!attribute attr
31
+ # @return [Attr]
32
+ #
33
+ # @!attribute string
34
+ # @return [String]
35
+ class CodeBlock < Block
36
+ include InnerMarkdown
37
+
38
+ attr_accessor :attr, :string
36
39
 
37
- # Create a new CodeBlock based on the contents
38
- #
39
- # @param contents [Array] an array with the attribute and the code
40
- # string
41
- def initialize(contents)
42
- @attr = Attr.new contents[0]
43
- @string = contents[1]
44
- end
40
+ # Create a new CodeBlock based on the contents
41
+ #
42
+ # @param contents [Array] an array with the attribute and the code
43
+ # string
44
+ def initialize(contents)
45
+ @attr = Attr.new contents[0]
46
+ @string = contents[1]
47
+ end
45
48
 
46
- # An AST representation of this CodeBlock
47
- def ast_contents()
48
- [
49
- @attr.to_ast,
50
- @string
51
- ]
52
- end
49
+ # An AST representation of this CodeBlock
50
+ def ast_contents
51
+ [
52
+ @attr.to_ast,
53
+ @string
54
+ ]
55
+ end
53
56
 
54
- # Has this CodeBlock string contents?
55
- #
56
- # @return [Boolean] true
57
- def has_string?()
58
- true
59
- end
57
+ # Has this CodeBlock string contents?
58
+ #
59
+ # @return [Boolean] true
60
+ def has_string?
61
+ true
62
+ end
60
63
 
61
- # Write this CodeBlock's contents to file
62
- #
63
- # @param filename {String} the path to the file to write
64
- def to_file(filename)
65
- File.open(filename, "w") do |file|
66
- file.write "#{@string}\n"
67
- end
68
- end
64
+ # Write this CodeBlock's contents to file
65
+ #
66
+ # @param filename {String} the path to the file to write
67
+ def to_file(filename)
68
+ File.write(filename, "#{@string}\n")
69
+ end
69
70
 
70
- # Create a new CodeBlock based on the contents of a file, and,
71
- # optionally, a language
72
- #
73
- # @param filename {String} the path to the file to read the
74
- # contents from
75
- # @param language {String} the language of the contents
76
- #
77
- # @return [CodeBlock]
78
- def self.from_file(filename, language = "")
79
- return self.from_code_string(File.read(filename), language)
80
- end
71
+ # Create a new CodeBlock based on the contents of a file, and,
72
+ # optionally, a language
73
+ #
74
+ # @param filename {String} the path to the file to read the
75
+ # contents from
76
+ # @param language {String} the language of the contents
77
+ #
78
+ # @return [CodeBlock]
79
+ def self.from_file(filename, language = '')
80
+ from_code_string(File.read(filename), language)
81
+ end
81
82
 
82
- # Get this CodeBlock's contents as a string
83
- #
84
- # @return [String]
85
- def to_code_string()
86
- return @string
87
- end
83
+ # Get this CodeBlock's contents as a string
84
+ #
85
+ # @return [String]
86
+ def to_code_string
87
+ @string
88
+ end
88
89
 
89
- # Create a new CodeBlock based on a string and, optionally, a
90
- # language
91
- #
92
- #
93
- # @param code_string [String] the string with code to use as the
94
- # contents of the CodeBlock
95
- # @param language [String] the optional language class
96
- # @return [CodeBlock]
97
- def self.from_code_string(code_string, language = "")
98
- attributes = ["", [language], []]
99
- code_block = CodeBlock.new [attributes, code_string]
100
- return code_block
101
- end
102
- end
90
+ # Create a new CodeBlock based on a string and, optionally, a
91
+ # language
92
+ #
93
+ #
94
+ # @param code_string [String] the string with code to use as the
95
+ # contents of the CodeBlock
96
+ # @param language [String] the optional language class
97
+ # @return [CodeBlock]
98
+ def self.from_code_string(code_string, language = '')
99
+ attributes = ['', [language], []]
100
+ CodeBlock.new [attributes, code_string]
101
+ end
103
102
  end
103
+ end
104
104
  end