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,36 +18,35 @@
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
- # An Inline node
25
- # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:Inline
26
- class Inline < Node
27
- include InnerMarkdown
28
-
29
- # Create a new Inline node with contents
30
- # @param contents [Array] the contents of this inline node
31
- def initialize(contents)
32
- super contents, true
33
- end
25
+ module PandocFilter
26
+ # An Inline node
27
+ # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:Inline
28
+ class Inline < Node
29
+ include InnerMarkdown
34
30
 
35
- # Is this Inline node inline? Of course!
36
- #
37
- # @return [Boolean] true
38
- def is_inline?()
39
- true
40
- end
31
+ # Create a new Inline node with contents
32
+ # @param contents [Array] the contents of this inline node
33
+ def initialize(contents)
34
+ super(contents, true)
35
+ end
41
36
 
42
- # Has this Inline node inline contents? Of course!
43
- #
44
- # @return [Boolean] true
45
- def has_inline?()
46
- true
47
- end
37
+ # Is this Inline node inline? Of course!
38
+ #
39
+ # @return [Boolean] true
40
+ def is_inline?
41
+ true
42
+ end
48
43
 
49
- end
44
+ # Has this Inline node inline contents? Of course!
45
+ #
46
+ # @return [Boolean] true
47
+ def has_inline?
48
+ true
49
+ end
50
50
  end
51
+ end
51
52
  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,69 +19,65 @@
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Paru
20
- module PandocFilter
21
-
22
- # A mixin to add inner_markdown properties to Nodes for which it makes
23
- # sense to have an inner_markdown. Only those nodes that have a clear
24
- # identifiable Inline level content, have the {#inner_markdown}
25
- # method. This are almost all Inline nodes (except Cite) and Block
26
- # level nodes with Inline contents like {Para} or {Header}.
27
- module InnerMarkdown
28
-
29
- # Get the markdown representation of this Node's children.
30
- #
31
- # @return [String] the inner markdown representation of this Node
32
- #
33
- # @example Replace all occurrences of "hello" by "world" in all paragraphs
34
- # Paru::Filter.run do
35
- # with "Para" do |p|
36
- # p.inner_markdown = p.inner_markdown.gsub "hello", "world"
37
- # end
38
- # end
39
- #
40
- def inner_markdown()
41
- if has_children?
42
- temp_doc = PandocFilter::Document.fragment @children
43
- AST2MARKDOWN << temp_doc.to_JSON
44
- elsif has_string?
45
- @string
46
- end
47
- end
22
+ module PandocFilter
23
+ # A mixin to add inner_markdown properties to Nodes for which it makes
24
+ # sense to have an inner_markdown. Only those nodes that have a clear
25
+ # identifiable Inline level content, have the {#inner_markdown}
26
+ # method. This are almost all Inline nodes (except Cite) and Block
27
+ # level nodes with Inline contents like {Para} or {Header}.
28
+ module InnerMarkdown
29
+ # Get the markdown representation of this Node's children.
30
+ #
31
+ # @return [String] the inner markdown representation of this Node
32
+ #
33
+ # @example Replace all occurrences of "hello" by "world" in all paragraphs
34
+ # Paru::Filter.run do
35
+ # with "Para" do |p|
36
+ # p.inner_markdown = p.inner_markdown.gsub "hello", "world"
37
+ # end
38
+ # end
39
+ #
40
+ def inner_markdown
41
+ if has_children?
42
+ temp_doc = PandocFilter::Document.fragment @children
43
+ AST2MARKDOWN << temp_doc.to_JSON
44
+ elsif has_string?
45
+ @string
46
+ end
47
+ end
48
48
 
49
- # Replace this Node's children with the Nodes represented by the
50
- # markdown string
51
- #
52
- # @param markdown [String] the markdown string to replace this
53
- # Node's children
54
- #
55
- # @example Replace all occurrences of "hello" by "world" in all paragraphs
56
- # Paru::Filter.run do
57
- # with "Para" do |p|
58
- # p.inner_markdown = p.inner_markdown.gsub "hello", "world"
59
- # end
60
- # end
61
- #
62
- def inner_markdown=(markdown)
63
- if has_string?
64
- @string = markdown
65
- else
66
- if markdown.nil? or markdown.empty?
67
- @children = []
68
- else
69
- json = MARKDOWN2JSON << markdown
70
- temp_doc = PandocFilter::Document.from_JSON json
71
- temp_doc.children.each {|c| c.parent = @parent}
49
+ # Replace this Node's children with the Nodes represented by the
50
+ # markdown string
51
+ #
52
+ # @param markdown [String] the markdown string to replace this
53
+ # Node's children
54
+ #
55
+ # @example Replace all occurrences of "hello" by "world" in all paragraphs
56
+ # Paru::Filter.run do
57
+ # with "Para" do |p|
58
+ # p.inner_markdown = p.inner_markdown.gsub "hello", "world"
59
+ # end
60
+ # end
61
+ #
62
+ def inner_markdown=(markdown)
63
+ if has_string?
64
+ @string = markdown
65
+ elsif markdown.nil? || markdown.empty?
66
+ @children = []
67
+ else
68
+ json = MARKDOWN2JSON << markdown
69
+ temp_doc = PandocFilter::Document.from_JSON json
70
+ temp_doc.children.each { |c| c.parent = @parent }
72
71
 
73
- if has_inline?
74
- @children = temp_doc.children.first.children
75
- elsif has_block?
76
- @children = temp_doc.children
77
- else
78
- # Unknown; what to do here?
79
- end
80
- end
81
- end
82
- end
72
+ if has_inline?
73
+ @children = temp_doc.children.first.children
74
+ elsif has_block?
75
+ @children = temp_doc.children
76
+ else
77
+ # Unknown; what to do here?
78
+ end
83
79
  end
80
+ end
84
81
  end
85
- end
82
+ end
83
+ 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,27 +18,26 @@
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
- # An IntValue represents some sort of integer metadata about block or
26
- # inline nodes
27
- class IntValue
28
- attr_accessor :value
25
+ module PandocFilter
26
+ # An IntValue represents some sort of integer metadata about block or
27
+ # inline nodes
28
+ class IntValue
29
+ attr_accessor :value
29
30
 
30
- def initialize(value)
31
- @value = value
32
- end
31
+ def initialize(value)
32
+ @value = value
33
+ end
33
34
 
34
- # Create an AST representation of this Node
35
- #
36
- # @return [Hash]
37
- def to_ast()
38
- @value
39
- end
40
- end
35
+ # Create an AST representation of this Node
36
+ #
37
+ # @return [Hash]
38
+ def to_ast
39
+ @value
40
+ end
41
41
  end
42
+ end
42
43
  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,18 +18,18 @@
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 "./list.rb"
21
+ require_relative 'list'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # A LineBlock is a List of Lists of Inline nodes
24
- class LineBlock < List
25
- # Create a new LineBlock node based on contents
26
- #
27
- # @param contents [Array] the contents of the LineBlock
28
- def initialize(contents)
29
- super(contents, Para)
30
- end
31
- end
24
+ module PandocFilter
25
+ # A LineBlock is a List of Lists of Inline nodes
26
+ class LineBlock < List
27
+ # Create a new LineBlock node based on contents
28
+ #
29
+ # @param contents [Array] the contents of the LineBlock
30
+ def initialize(contents)
31
+ super(contents, Para)
32
+ end
32
33
  end
34
+ end
33
35
  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 "./empty_inline.rb"
21
+ require_relative 'empty_inline'
20
22
 
21
23
  module Paru
22
- module PandocFilter
23
- # A LineBreak is an empty inline element
24
- class LineBreak < EmptyInline
25
- end
24
+ module PandocFilter
25
+ # A LineBreak is an empty inline element
26
+ class LineBreak < EmptyInline
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,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 "./attr.rb"
21
- require_relative "./target.rb"
21
+ require_relative 'inline'
22
+ require_relative 'attr'
23
+ require_relative 'target'
22
24
 
23
25
  module Paru
24
- module PandocFilter
25
- # A Link node has an attribute object, an Inline description and a
26
- # target
27
- #
28
- # @!attribute attr
29
- # @return [Attr]
30
- #
31
- # @!attribute target
32
- # @return [Target]
33
- class Link < Inline
34
- attr_accessor :attr, :target
35
-
36
- # Create a new Link node with contents
37
- #
38
- # @param contents [Array] an array with attributes, description,
39
- # and target information
40
- def initialize(contents)
41
- @attr = Attr.new contents[0]
42
- super contents[1]
43
- @target = Target.new contents[2]
44
- end
26
+ module PandocFilter
27
+ # A Link node has an attribute object, an Inline description and a
28
+ # target
29
+ #
30
+ # @!attribute attr
31
+ # @return [Attr]
32
+ #
33
+ # @!attribute target
34
+ # @return [Target]
35
+ class Link < Inline
36
+ attr_accessor :attr, :target
45
37
 
46
- # Create an AST representation of this Link node
47
- def ast_contents
48
- [
49
- @attr.to_ast,
50
- super,
51
- @target.to_ast
52
- ]
53
- end
38
+ # Create a new Link node with contents
39
+ #
40
+ # @param contents [Array] an array with attributes, description,
41
+ # and target information
42
+ def initialize(contents)
43
+ @attr = Attr.new contents[0]
44
+ super(contents[1])
45
+ @target = Target.new contents[2]
46
+ end
54
47
 
55
- end
48
+ # Create an AST representation of this Link node
49
+ def ast_contents
50
+ [
51
+ @attr.to_ast,
52
+ super,
53
+ @target.to_ast
54
+ ]
55
+ end
56
56
  end
57
+ end
57
58
  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,49 +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 "./block.rb"
20
- require_relative "./inline.rb"
21
+ require_relative 'block'
22
+ require_relative 'inline'
21
23
 
22
24
  module Paru
23
- module PandocFilter
24
- # A List node is a base node for various List node types
25
- class List < Block
26
-
27
- # Create a new List node based on contents
28
- #
29
- # @param contents [Array] the contents of the list
30
- # @param node_class [Node = PandocFilter::Block] the contents are {Inline} nodes
31
- def initialize(contents, node_class = Block)
32
- super []
33
- contents.each do |item|
34
- child = node_class.new(item)
35
- child.parent = self
25
+ module PandocFilter
26
+ # A List node is a base node for various List node types
27
+ class List < Block
28
+ # Create a new List node based on contents
29
+ #
30
+ # @param contents [Array] the contents of the list
31
+ # @param node_class [Node = PandocFilter::Block] the contents are {Inline} nodes
32
+ def initialize(contents, node_class = Block)
33
+ super([])
34
+ contents.each do |item|
35
+ child = node_class.new(item)
36
+ child.parent = self
36
37
 
37
- @children.push child
38
- end
39
- end
40
-
41
- # Create an AST representation of this List node
42
- def ast_contents()
43
- @children.map {|child| child.ast_contents}
44
- end
38
+ @children.push child
39
+ end
40
+ end
45
41
 
46
- # Has this List node block contents?
47
- #
48
- # @return [Boolean] true
49
- def has_block?()
50
- true
51
- end
42
+ # Create an AST representation of this List node
43
+ def ast_contents
44
+ @children.map(&:ast_contents)
45
+ end
52
46
 
53
- # Convert this List to an array of markdown strings
54
- #
55
- # @return [String[]]
56
- def to_array()
57
- @children.map do |block|
58
- block.children.map{|c| c.markdown.strip}.join("\n")
59
- end
60
- end
47
+ # Has this List node block contents?
48
+ #
49
+ # @return [Boolean] true
50
+ def has_block?
51
+ true
52
+ end
61
53
 
54
+ # Convert this List to an array of markdown strings
55
+ #
56
+ # @return [String[]]
57
+ def to_array
58
+ @children.map do |block|
59
+ block.children.map { |c| c.markdown.strip }.join("\n")
62
60
  end
61
+ end
63
62
  end
63
+ end
64
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
  #
@@ -17,60 +19,59 @@
17
19
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
20
  #++
19
21
  module Paru
20
- module PandocFilter
21
- # ListAttributes represent the attributes of a list.
22
- #
23
- # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:ListAttributes
24
- #
25
- # @!attribute start
26
- # @return [Integer]
27
- #
28
- # @!attribute number_style
29
- # @return [STYLES]
30
- #
31
- # @!attribute number_delim
32
- # @return [DELIMS]
33
- class ListAttributes
34
-
35
- # The various styles of list numbers
36
- STYLES = [
37
- "DefaultStyle",
38
- "Example",
39
- "Decimal",
40
- "LowerRoman",
41
- "UpperRoman",
42
- "LowerAlpha",
43
- "UpperAlpha"
44
- ]
22
+ module PandocFilter
23
+ # ListAttributes represent the attributes of a list.
24
+ #
25
+ # @see http://hackage.haskell.org/package/pandoc-types-1.17.0.4/docs/Text-Pandoc-Definition.html#t:ListAttributes
26
+ #
27
+ # @!attribute start
28
+ # @return [Integer]
29
+ #
30
+ # @!attribute number_style
31
+ # @return [STYLES]
32
+ #
33
+ # @!attribute number_delim
34
+ # @return [DELIMS]
35
+ class ListAttributes
36
+ # The various styles of list numbers
37
+ STYLES = %w[
38
+ DefaultStyle
39
+ Example
40
+ Decimal
41
+ LowerRoman
42
+ UpperRoman
43
+ LowerAlpha
44
+ UpperAlpha
45
+ ].freeze
45
46
 
46
- # The various delimeters of list numbers
47
- DELIMS = [
48
- "DefaultDelim",
49
- "Period",
50
- "OneParen",
51
- "TwoParens"
52
- ]
47
+ # The various delimeters of list numbers
48
+ DELIMS = %w[
49
+ DefaultDelim
50
+ Period
51
+ OneParen
52
+ TwoParens
53
+ ].freeze
53
54
 
54
- attr_accessor :start, :number_style, :number_delim
55
+ attr_accessor :start, :number_style, :number_delim
55
56
 
56
- # Create a new ListAttribute object with attributes
57
- #
58
- # @param attributes [Array] an array with start, number style, and
59
- # number delimeter
60
- def initialize(attributes)
61
- @start = attributes[0]
62
- @number_style = attributes[1]
63
- @number_delim = attributes[2]
64
- end
57
+ # Create a new ListAttribute object with attributes
58
+ #
59
+ # @param attributes [Array] an array with start, number style, and
60
+ # number delimeter
61
+ def initialize(attributes)
62
+ @start = attributes[0]
63
+ @number_style = attributes[1]
64
+ @number_delim = attributes[2]
65
+ end
65
66
 
66
- # Create an AST representation of this ListAttributes object
67
- def to_ast()
68
- [
69
- @start,
70
- @number_style,
71
- @number_delim
72
- ]
73
- end
74
- end
67
+ # Create an AST representation of this ListAttributes object
68
+ def to_ast
69
+ [
70
+ @start,
71
+ @number_style,
72
+ @number_delim
73
+ ]
74
+ end
75
75
  end
76
+ end
76
77
  end