paru 0.2.4.2 → 0.2.4.3

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paru.rb +8 -20
  3. data/lib/paru/error.rb +4 -6
  4. data/lib/paru/filter.rb +144 -110
  5. data/lib/paru/filter/ast_manipulation.rb +75 -39
  6. data/lib/paru/filter/attr.rb +72 -36
  7. data/lib/paru/filter/block.rb +14 -8
  8. data/lib/paru/filter/block_quote.rb +12 -9
  9. data/lib/paru/filter/bullet_list.rb +6 -6
  10. data/lib/paru/filter/citation.rb +51 -25
  11. data/lib/paru/filter/cite.rb +29 -20
  12. data/lib/paru/filter/code.rb +41 -24
  13. data/lib/paru/filter/code_block.rb +36 -21
  14. data/lib/paru/filter/definition_list.rb +19 -15
  15. data/lib/paru/filter/definition_list_item.rb +30 -17
  16. data/lib/paru/filter/div.rb +29 -21
  17. data/lib/paru/filter/document.rb +73 -46
  18. data/lib/paru/filter/emph.rb +6 -6
  19. data/lib/paru/filter/empty_block.rb +17 -13
  20. data/lib/paru/filter/empty_inline.rb +24 -17
  21. data/lib/paru/filter/header.rb +38 -23
  22. data/lib/paru/filter/image.rb +13 -11
  23. data/lib/paru/filter/inline.rb +21 -10
  24. data/lib/paru/filter/line_block.rb +6 -6
  25. data/lib/paru/filter/line_break.rb +6 -6
  26. data/lib/paru/filter/link.rb +33 -21
  27. data/lib/paru/filter/list.rb +26 -17
  28. data/lib/paru/filter/list_attributes.rb +53 -32
  29. data/lib/paru/filter/markdown.rb +102 -59
  30. data/lib/paru/filter/math.rb +65 -38
  31. data/lib/paru/filter/meta.rb +26 -16
  32. data/lib/paru/filter/meta_blocks.rb +12 -9
  33. data/lib/paru/filter/meta_bool.rb +6 -6
  34. data/lib/paru/filter/meta_inlines.rb +12 -9
  35. data/lib/paru/filter/meta_list.rb +6 -6
  36. data/lib/paru/filter/meta_map.rb +49 -33
  37. data/lib/paru/filter/meta_string.rb +6 -6
  38. data/lib/paru/filter/meta_value.rb +22 -14
  39. data/lib/paru/filter/node.rb +204 -129
  40. data/lib/paru/filter/note.rb +31 -20
  41. data/lib/paru/filter/null.rb +6 -6
  42. data/lib/paru/filter/ordered_list.rb +34 -18
  43. data/lib/paru/filter/para.rb +20 -13
  44. data/lib/paru/filter/plain.rb +21 -12
  45. data/lib/paru/filter/quoted.rb +27 -18
  46. data/lib/paru/filter/raw_block.rb +32 -19
  47. data/lib/paru/filter/raw_inline.rb +40 -22
  48. data/lib/paru/filter/small_caps.rb +7 -6
  49. data/lib/paru/filter/soft_break.rb +6 -6
  50. data/lib/paru/filter/space.rb +6 -6
  51. data/lib/paru/filter/span.rb +28 -18
  52. data/lib/paru/filter/str.rb +29 -18
  53. data/lib/paru/filter/strikeout.rb +6 -6
  54. data/lib/paru/filter/strong.rb +6 -6
  55. data/lib/paru/filter/subscript.rb +6 -6
  56. data/lib/paru/filter/superscript.rb +6 -6
  57. data/lib/paru/filter/table.rb +51 -29
  58. data/lib/paru/filter/table_row.rb +21 -14
  59. data/lib/paru/filter/target.rb +29 -15
  60. data/lib/paru/filter/version.rb +23 -14
  61. data/lib/paru/pandoc.rb +165 -111
  62. data/lib/paru/pandoc_options.yaml +3 -3
  63. data/lib/paru/selector.rb +176 -153
  64. metadata +2 -3
  65. data/lib/paru/filter/alignment.rb +0 -30
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,51 +17,78 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
21
- require_relative "./inline"
20
+ module PandocFilter
21
+ require_relative "./inline"
22
22
 
23
- # Math MathType String
24
- class Math < Inline
25
- attr_accessor :math_type, :string
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
26
34
 
27
- def initialize contents
28
- @math_type, @string = contents
29
- end
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
30
41
 
31
- def inline?
32
- "InlineMath" == @math_type[t]
33
- end
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
34
49
 
35
- def inline!
36
- @math_type = {
37
- "t" => "InlineMath"
38
- }
39
- end
50
+ # Convert this Math node's content to Inline
51
+ def inline!()
52
+ @math_type = {
53
+ "t" => "InlineMath"
54
+ }
55
+ end
40
56
 
41
- def display?
42
- "DisplayMath" == @math_type[t]
43
- end
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
44
63
 
45
- def display!
46
- @math_type = {
47
- "t" => "DisplayMath"
48
- }
49
- end
64
+ # Make this Math node's content display as a block
65
+ def display!()
66
+ @math_type = {
67
+ "t" => "DisplayMath"
68
+ }
69
+ end
50
70
 
51
- def ast_contents
52
- [
53
- @math_type,
54
- @string
55
- ]
56
- end
71
+ # Create an AST representation of this Math node
72
+ def ast_contents()
73
+ [
74
+ @math_type,
75
+ @string
76
+ ]
77
+ end
57
78
 
58
- def has_string?
59
- true
60
- end
79
+ # Has this Math node string contents?
80
+ #
81
+ # @return [Boolean] true
82
+ def has_string?()
83
+ true
84
+ end
61
85
 
62
- def has_inline?
63
- false
64
- end
86
+ # Has this Math node inline contents?
87
+ #
88
+ # @return [Boolean] false
89
+ def has_inline?()
90
+ false
91
+ end
92
+ end
65
93
  end
66
- end
67
94
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,25 +17,35 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
21
- require_relative "./meta_map"
20
+ module PandocFilter
21
+ require_relative "./meta_map"
22
22
 
23
- # Meta is a MetaMap
24
- class Meta < MetaMap
25
- include Enumerable
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
+ include Enumerable
26
29
 
27
- def initialize contents
28
- super contents
29
- end
30
+ # Create a new Meta node based on the contents
31
+ #
32
+ # @param value [String]
33
+ def initialize(value)
34
+ super value
35
+ end
30
36
 
31
- def ast_type
32
- "meta"
33
- end
37
+ # The type of a Meta is "meta"
38
+ #
39
+ # @return [String] "meta"
40
+ def ast_type()
41
+ "meta"
42
+ end
34
43
 
35
- def to_ast
36
- ast_contents
37
- end
44
+ # Convert this Meta node to an AST representation
45
+ def to_ast()
46
+ ast_contents
47
+ end
38
48
 
49
+ end
39
50
  end
40
- end
41
51
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,16 +17,19 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./node"
22
+ require_relative "./node"
23
23
 
24
- # MetaBlocks [Blocks]
25
- class MetaBlocks < Node
24
+ # A MetaBlocks Node contains a list of Blocks
25
+ class MetaBlocks < Node
26
26
 
27
- def initialize value
28
- super value
29
- end
27
+ # Create a MetaBlocks node based on the contents
28
+ #
29
+ # @param value [String] the contents of the MetaBlocks
30
+ def initialize(value)
31
+ super value
32
+ end
33
+ end
30
34
  end
31
- end
32
35
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,12 +17,12 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./meta_value"
22
+ require_relative "./meta_value"
23
23
 
24
- # MetaBool Bool
25
- class MetaBool < MetaValue
24
+ # A MetaBool Note representa a Boolean value
25
+ class MetaBool < MetaValue
26
+ end
26
27
  end
27
- end
28
28
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,16 +17,19 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./node"
22
+ require_relative "./node"
23
23
 
24
- # MetaInlines [Inline]
25
- class MetaInlines < Node
24
+ # A MetaInlines node contains a list of Inline nodes
25
+ class MetaInlines < Node
26
26
 
27
- def initialize value
28
- super value
29
- end
27
+ # Create a new MetaInlines Node based on the contents
28
+ #
29
+ # @param value [String] the contents of this MetaInlines node
30
+ def initialize(value)
31
+ super value
32
+ end
33
+ end
30
34
  end
31
- end
32
35
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,12 +17,12 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./node"
22
+ require_relative "./node"
23
23
 
24
- # MetaList [MetaValue]
25
- class MetaList < Node
24
+ # A MetaList node contains a list of MetaValue nodes
25
+ class MetaList < Node
26
+ end
26
27
  end
27
- end
28
28
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,47 +17,63 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./node"
22
+ require_relative "./node"
23
23
 
24
- # MetaMap (M.Map String MetaValue)
25
- class MetaMap < Node
24
+ # A MetaMap Node is a map of String keys with MetaValue values
25
+ class MetaMap < Node
26
26
 
27
- def initialize contents
28
- @children = Hash.new
27
+ # Create a new MetaMap based on the contents
28
+ #
29
+ # @param contents [Array] a list of key-value pairs
30
+ def initialize(contents)
31
+ @children = Hash.new
29
32
 
30
- if contents.is_a? Hash
31
- contents.each_pair do |key, value|
32
- if not value.empty? and PandocFilter.const_defined? value["t"]
33
- @children[key] = PandocFilter.const_get(value["t"]).new value["c"]
33
+ if contents.is_a? Hash
34
+ contents.each_pair do |key, value|
35
+ if not value.empty? and PandocFilter.const_defined? value["t"]
36
+ @children[key] = PandocFilter.const_get(value["t"]).new value["c"]
37
+ end
38
+ end
39
+ end
34
40
  end
35
- end
36
- end
37
- end
38
41
 
39
- def [](key)
40
- if @children.key_exists?
41
- @children[key]
42
- end
43
- end
42
+ # Get the value belonging to key
43
+ #
44
+ # @param key [String] the key
45
+ #
46
+ # @return [MetaValue] the value belonging to the key
47
+ def [](key)
48
+ if @children.key_exists?
49
+ @children[key]
50
+ end
51
+ end
44
52
 
45
- def has_key? key
46
- @children.has_key? key
47
- end
53
+ # Does this MetaMap node have key?
54
+ #
55
+ # @param key [String] the key to find
56
+ #
57
+ # @return [Boolean] true if this MetaMap node contains this key
58
+ def has_key?(key)
59
+ @children.has_key? key
60
+ end
48
61
 
49
- def delete key
50
- @children.delete key
51
- end
62
+ # Delete the key-value pair from this MetaMap
63
+ #
64
+ # @param key [String] the key to delete
65
+ def delete(key)
66
+ @children.delete key
67
+ end
52
68
 
53
- def ast_contents
54
- ast = Hash.new
55
- @children.each_pair do |key, value|
56
- ast[key] = value.to_ast
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
75
+ ast
76
+ end
57
77
  end
58
- ast
59
- end
60
-
61
78
  end
62
- end
63
79
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,12 +17,12 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./meta_value"
22
+ require_relative "./meta_value"
23
23
 
24
- # MetaString String
25
- class MetaString < MetaValue
24
+ # A MetaString Node represents a String value
25
+ class MetaString < MetaValue
26
+ end
26
27
  end
27
- end
28
28
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,24 +17,32 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  module Paru
20
- module PandocFilter
20
+ module PandocFilter
21
21
 
22
- require_relative "./node"
22
+ require_relative "./node"
23
23
 
24
- # MetaValue = MetaMap | MetaList | MetaBool | MetaString | MetaInlines |
25
- # MetaBlocks
26
- class MetaValue < Node
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]
30
+ class MetaValue < Node
27
31
 
28
- attr_accessor :value
32
+ attr_accessor :value
29
33
 
30
- def initialize value
31
- @value = value
32
- end
34
+ # Create a new MetaValue Node based on the value
35
+ #
36
+ # @param value [String]
37
+ def initialize(value)
38
+ @value = value
39
+ end
33
40
 
34
- def ast_contents
35
- @value
36
- end
41
+ # The AST contents
42
+ def ast_contents()
43
+ @value
44
+ end
37
45
 
46
+ end
38
47
  end
39
- end
40
48
  end