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, 2032 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,69 +18,69 @@
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 "./value.rb"
21
+ require_relative 'value'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # The allignment of a table column
24
- ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
24
+ module PandocFilter
25
+ # The allignment of a table column
26
+ ALIGNMENTS = %w[AlignLeft AlignRight AlignCenter AlignDefault].freeze
25
27
 
26
- # The default width of a column
27
- COL_WIDTH_DEFAULT = "ColWidthDefault"
28
+ # The default width of a column
29
+ COL_WIDTH_DEFAULT = 'ColWidthDefault'
28
30
 
29
- # Default value for a column specification: left aligned with default
30
- # width
31
- DEFAULT_COLSPEC = [{"t" => "AlignLeft"}, {"t" => COL_WIDTH_DEFAULT}]
31
+ # Default value for a column specification: left aligned with default
32
+ # width
33
+ DEFAULT_COLSPEC = [{ 't' => 'AlignLeft' }, { 't' => COL_WIDTH_DEFAULT }].freeze
32
34
 
33
- # ColSpec represents a colspec definition for a table column. It contains an alignment and the column's width.
34
- #
35
- # @see https://hackage.haskell.org/package/pandoc-types-1.21/docs/Text-Pandoc-Definition.html#t:ColSpec
36
- #
37
- # @!attribute alignment
38
- # @return [String]
39
- #
40
- # @!attribute width
41
- # @return [Double|COL_WIDTH_DEFAULT]
42
- class ColSpec
43
- attr_reader :alignment, :width
35
+ # ColSpec represents a colspec definition for a table column. It contains an alignment and the column's width.
36
+ #
37
+ # @see https://hackage.haskell.org/package/pandoc-types-1.21/docs/Text-Pandoc-Definition.html#t:ColSpec
38
+ #
39
+ # @!attribute alignment
40
+ # @return [String]
41
+ #
42
+ # @!attribute width
43
+ # @return [Double|COL_WIDTH_DEFAULT]
44
+ class ColSpec
45
+ attr_reader :alignment, :width
44
46
 
45
- # Create a new ColSpec object
46
- #
47
- # @param contents [Array = DEFAULT_COLSPEC] the attributes as a pair of [alignment, width]
48
- def initialize(contents = DEFAULT_COLSPEC)
49
- @alignment = Value.new contents[0]
50
- @width = Value.new contents[1]
51
- end
47
+ # Create a new ColSpec object
48
+ #
49
+ # @param contents [Array = DEFAULT_COLSPEC] the attributes as a pair of [alignment, width]
50
+ def initialize(contents = DEFAULT_COLSPEC)
51
+ @alignment = Value.new contents[0]
52
+ @width = Value.new contents[1]
53
+ end
52
54
 
53
- # Set the width
54
- #
55
- # @param [String|Integer|Float] new_width the new width. If it is
56
- # "ColWidthDefault", it uses the default value.
57
- def width=(new_width)
58
- if new_width == "ColWidthDefault" then
59
- @width = Value.new({"t" => new_width})
60
- else
61
- @width = Value.new({"t" => "ColWidth", "c" => new_width})
62
- end
63
- end
55
+ # Set the width
56
+ #
57
+ # @param [String|Integer|Float] new_width the new width. If it is
58
+ # "ColWidthDefault", it uses the default value.
59
+ def width=(new_width)
60
+ @width = if new_width == 'ColWidthDefault'
61
+ Value.new({ 't' => new_width })
62
+ else
63
+ Value.new({ 't' => 'ColWidth', 'c' => new_width })
64
+ end
65
+ end
64
66
 
65
- # Set the alignment
66
- #
67
- # @param [String] new_alignment the new alignment.
68
- def alignment=(new_alignment)
69
- @alignment.value = new_alignment
70
- end
67
+ # Set the alignment
68
+ #
69
+ # @param [String] new_alignment the new alignment.
70
+ def alignment=(new_alignment)
71
+ @alignment.value = new_alignment
72
+ end
71
73
 
72
- # Convert this attributes object to an AST representation
73
- #
74
- # @return [Array] Array containing id, class name list, and
75
- # key-value pair list
76
- def to_ast
77
- [
78
- @alignment.to_ast,
79
- @width.to_ast
80
- ]
81
- end
82
- end
74
+ # Convert this attributes object to an AST representation
75
+ #
76
+ # @return [Array] Array containing id, class name list, and
77
+ # key-value pair list
78
+ def to_ast
79
+ [
80
+ @alignment.to_ast,
81
+ @width.to_ast
82
+ ]
83
+ end
83
84
  end
85
+ end
84
86
  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,65 +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_relative "./block.rb"
20
- require_relative "./list.rb"
21
- require_relative "./para.rb"
21
+ require_relative 'block'
22
+ require_relative 'list'
23
+ require_relative 'para'
22
24
 
23
25
  module Paru
24
- module PandocFilter
25
- # A DefinitionList is a list of term-definition pairs, respecitively an Inline list and a Block list.
26
- class DefinitionList < Block
27
- # Create a new DefinitionList node
28
- #
29
- # @param contents [Array] the contents of this definition list.
30
- def initialize(contents)
31
- super []
32
- contents.each do |item|
33
- child = DefinitionListItem.new item
34
- child.parent = self
35
-
36
- @children.push child
37
- end
38
- end
39
-
40
- # Create an AST representation of this DefinitionList node
41
- def ast_contents
42
- @children.map {|child| child.to_ast}
43
- end
26
+ module PandocFilter
27
+ # A DefinitionList is a list of term-definition pairs, respecitively an Inline list and a Block list.
28
+ class DefinitionList < Block
29
+ # Create a new DefinitionList node
30
+ #
31
+ # @param contents [Array] the contents of this definition list.
32
+ def initialize(contents)
33
+ super([])
34
+ contents.each do |item|
35
+ child = DefinitionListItem.new item
36
+ child.parent = self
44
37
 
45
- # Convert this DefinitionList to a hash of term => definitions
46
- #
47
- # @return [Array]
48
- def to_array()
49
- @children.map do |def_item|
50
- def_item.to_array
51
- end
52
- end
38
+ @children.push child
39
+ end
40
+ end
53
41
 
54
- # Create a new DefinitionList based on a hash of term =>
55
- # definitions
56
- #
57
- # @param definitions [Array] Array of arrays with terms and their definitions
58
- # @return [DefinitionList]
59
- def self.from_array(definitions)
60
- ast_items = definitions.map do |definition|
61
- term = Block.from_markdown(definition[0]).ast_contents
62
- defin = List.from_markdown(definition[1])
42
+ # Create an AST representation of this DefinitionList node
43
+ def ast_contents
44
+ @children.map(&:to_ast)
45
+ end
63
46
 
64
- if not defin.has_block?
65
- para = Para.new []
66
- para.inner_markdown = definition[1]
67
- defin = [para.to_ast]
68
- else
69
- defin = defin.children.map{|c| c.to_ast}
70
- end
47
+ # Convert this DefinitionList to a hash of term => definitions
48
+ #
49
+ # @return [Array]
50
+ def to_array
51
+ @children.map(&:to_array)
52
+ end
71
53
 
72
- [term, [defin]]
73
- end
54
+ # Create a new DefinitionList based on a hash of term =>
55
+ # definitions
56
+ #
57
+ # @param definitions [Array] Array of arrays with terms and their definitions
58
+ # @return [DefinitionList]
59
+ def self.from_array(definitions)
60
+ ast_items = definitions.map do |definition|
61
+ term = Block.from_markdown(definition[0]).ast_contents
62
+ defin = List.from_markdown(definition[1])
74
63
 
75
- DefinitionList.new ast_items
76
- end
64
+ if defin.has_block?
65
+ defin = defin.children.map(&:to_ast)
66
+ else
67
+ para = Para.new []
68
+ para.inner_markdown = definition[1]
69
+ defin = [para.to_ast]
70
+ end
77
71
 
72
+ [term, [defin]]
78
73
  end
74
+
75
+ DefinitionList.new ast_items
76
+ end
79
77
  end
78
+ end
80
79
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright 2015, 2016 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,54 +18,54 @@
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 "./list.rb"
21
- require_relative "./inline.rb"
21
+ require_relative 'block'
22
+ require_relative 'list'
23
+ require_relative 'inline'
22
24
 
23
25
  module Paru
24
- module PandocFilter
25
- # A DefinitionListItem is a helper node to represent the pair of a term
26
- # and its definition in a DefinitionList
27
- #
28
- # @!attribute term
29
- # @return [Block]
30
- #
31
- # @!attribute definition
32
- # @return [List]
33
- class DefinitionListItem < Block
34
- attr_accessor :term, :definition
26
+ module PandocFilter
27
+ # A DefinitionListItem is a helper node to represent the pair of a term
28
+ # and its definition in a DefinitionList
29
+ #
30
+ # @!attribute term
31
+ # @return [Block]
32
+ #
33
+ # @!attribute definition
34
+ # @return [List]
35
+ class DefinitionListItem < Block
36
+ attr_accessor :term, :definition
35
37
 
36
- # Create a new DefinitionListItem
37
- #
38
- # @param item [Array] the [term, definition]
39
- def initialize(item)
40
- super []
38
+ # Create a new DefinitionListItem
39
+ #
40
+ # @param item [Array] the [term, definition]
41
+ def initialize(item)
42
+ super([])
41
43
 
42
- @term = Block.new item[0]
43
- @term.parent = self
44
- @children << @term
44
+ @term = Block.new item[0]
45
+ @term.parent = self
46
+ @children << @term
45
47
 
46
- @definition = List.new item[1]
47
- @definition.parent = self
48
- @children << @definition
49
- end
48
+ @definition = List.new item[1]
49
+ @definition.parent = self
50
+ @children << @definition
51
+ end
50
52
 
51
- # Create an AST representation of this DefinitionListItem
52
- def to_ast
53
- [
54
- @term.ast_contents,
55
- @definition.ast_contents
56
- ]
57
- end
53
+ # Create an AST representation of this DefinitionListItem
54
+ def to_ast
55
+ [
56
+ @term.ast_contents,
57
+ @definition.ast_contents
58
+ ]
59
+ end
58
60
 
59
- # Convert this DefinitionListItem to a pair of term and definition
60
- #
61
- # @return [Array]
62
- def to_array
63
- term = @term.children.map{|c| c.markdown.strip}.select{|c| !c.empty?}.join(" ").strip
64
- definition = @definition.children.map{|c| c.children.map{|d| d.markdown}}.join("\n").strip
65
- [term, definition]
66
- end
67
- end
61
+ # Convert this DefinitionListItem to a pair of term and definition
62
+ #
63
+ # @return [Array]
64
+ def to_array
65
+ term = @term.children.map { |c| c.markdown.strip }.reject(&:empty?).join(' ').strip
66
+ definition = @definition.children.map { |c| c.children.map(&:markdown) }.join("\n").strip
67
+ [term, definition]
68
+ end
68
69
  end
70
+ end
69
71
  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,45 +18,45 @@
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 Div node consisting of an attribute object and a list of Block nodes.
26
- class Div < Block
27
- include InnerMarkdown
26
+ module PandocFilter
27
+ # A Div node consisting of an attribute object and a list of Block nodes.
28
+ class Div < Block
29
+ include InnerMarkdown
28
30
 
29
- # A Div node has an attribute object
30
- #
31
- # @!attribute attr
32
- # @return [Attr]
33
- attr_accessor :attr
31
+ # A Div node has an attribute object
32
+ #
33
+ # @!attribute attr
34
+ # @return [Attr]
35
+ attr_accessor :attr
34
36
 
35
- # Create a new Div node based on the contents
36
- #
37
- # @param contents [Array] an array containing the attribute object
38
- # and the contents of this div.
39
- def initialize(contents)
40
- @attr = Attr.new contents[0]
41
- super contents[1]
42
- end
37
+ # Create a new Div node based on the contents
38
+ #
39
+ # @param contents [Array] an array containing the attribute object
40
+ # and the contents of this div.
41
+ def initialize(contents)
42
+ @attr = Attr.new contents[0]
43
+ super(contents[1])
44
+ end
43
45
 
44
- # Create an AST representation of this Div node.
45
- def ast_contents()
46
- [
47
- @attr.to_ast,
48
- super
49
- ]
50
- end
46
+ # Create an AST representation of this Div node.
47
+ def ast_contents
48
+ [
49
+ @attr.to_ast,
50
+ super
51
+ ]
52
+ end
51
53
 
52
- # Has this Div node Blocks as children?
53
- #
54
- # @return [Boolean] true
55
- def has_block?
56
- true
57
- end
58
- end
54
+ # Has this Div node Blocks as children?
55
+ #
56
+ # @return [Boolean] true
57
+ def has_block?
58
+ true
59
+ end
59
60
  end
61
+ end
60
62
  end