paru 0.2.4.2 → 0.2.4.3

Sign up to get free protection for your applications and to get access to all the features.
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,22 +17,26 @@
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 "./block"
20
+ module PandocFilter
21
+ require_relative "./block"
22
22
 
23
- # DefinitionList [([Inline], [[Block]])]
24
- class DefinitionList < Block
25
- def initialize contents
26
- super []
27
- contents.each do |item|
28
- @children.push DefinitionListItem.new item
29
- end
30
- end
23
+ # A DefinitionList is a list of term-definition pairs, respecitively an Inline list and a Block list.
24
+ class DefinitionList < Block
25
+ # Create a new DefinitionList node
26
+ #
27
+ # @param contents [Array] the contents of this definition list.
28
+ def initialize(contents)
29
+ super []
30
+ contents.each do |item|
31
+ @children.push DefinitionListItem.new item
32
+ end
33
+ end
31
34
 
32
- def ast_contents
33
- @children.map {|child| child.to_ast}
34
- end
35
+ # Create an AST representation of this DefinitionList node
36
+ def ast_contents
37
+ @children.map {|child| child.to_ast}
38
+ end
35
39
 
40
+ end
36
41
  end
37
- end
38
42
  end
@@ -17,24 +17,37 @@
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 "./block"
22
- require_relative "./list"
23
- require_relative "./inline"
20
+ module PandocFilter
21
+ require_relative "./block"
22
+ require_relative "./list"
23
+ require_relative "./inline"
24
24
 
25
- class DefinitionListItem < Block
26
- attr_accessor :term, :definition
27
- def initialize item
28
- @term = Block.new item[0]
29
- @definition = List.new item[1]
30
- end
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
31
35
 
32
- def to_ast
33
- [
34
- @term.ast_contents,
35
- @definition.ast_contents
36
- ]
37
- end
36
+ # Create a new DefinitionListItem
37
+ #
38
+ # @param item [Array] the [term, definition]
39
+ def initialize(item)
40
+ @term = Block.new item[0]
41
+ @definition = List.new item[1]
42
+ end
43
+
44
+ # Create an AST representation of this DefinitionListItem
45
+ def to_ast
46
+ [
47
+ @term.ast_contents,
48
+ @definition.ast_contents
49
+ ]
50
+ end
51
+ end
38
52
  end
39
- end
40
53
  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,28 +17,36 @@
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 "./block"
22
- require_relative "./attr"
20
+ module PandocFilter
21
+ require_relative "./block"
22
+ require_relative "./attr"
23
23
 
24
- # Div Attr [Block]
25
- class Div < Block
26
- def initialize contents
27
- @attr = Attr.new contents[0]
28
- super contents[1]
29
- end
24
+ # A Div node consisting of an attribute object and a list of Block nodes.
25
+ class Div < Block
30
26
 
31
- def ast_contents
32
- [
33
- @attr.to_ast,
34
- super
35
- ]
36
- end
27
+ # Create a new Div node based on the contents
28
+ #
29
+ # @param contents [Array] an array containing the attribute object
30
+ # and the contents of this div.
31
+ def initialize(contents)
32
+ @attr = Attr.new contents[0]
33
+ super contents[1]
34
+ end
37
35
 
38
- def has_block?
39
- true
40
- end
36
+ # Create an AST representation of this Div node.
37
+ def ast_contents()
38
+ [
39
+ @attr.to_ast,
40
+ super
41
+ ]
42
+ end
43
+
44
+ # Has this Div node Blocks as children?
45
+ #
46
+ # @return [Boolean] true
47
+ def has_block?
48
+ true
49
+ end
50
+ end
41
51
  end
42
- end
43
52
  end
44
-
@@ -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,63 +17,90 @@
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 "json"
23
- require_relative "./node"
24
- require_relative "./plain"
25
- require_relative "./meta"
26
- require_relative "./version"
22
+ require "json"
23
+ require_relative "./node"
24
+ require_relative "./plain"
25
+ require_relative "./meta"
26
+ require_relative "./version"
27
27
 
28
- VERSION = "pandoc-api-version"
29
- META = "meta"
30
- BLOCKS = "blocks"
28
+ VERSION = "pandoc-api-version"
29
+ META = "meta"
30
+ BLOCKS = "blocks"
31
31
 
32
- CURRENT_PANDOC_VERSION = [1, 17, 4]
32
+ # The current pandoc type version
33
+ # @see https://hackage.haskell.org/package/pandoc-types
34
+ CURRENT_PANDOC_VERSION = [1, 17, 0, 5]
33
35
 
34
- class Document < Node
36
+ # Each file that is being filtered by pandoc is represented by a root
37
+ # Document. It is the root node of the AST of the document in the file.
38
+ #
39
+ # @!attribute meta
40
+ # @return [Meta] the metadata of this document
41
+ class Document < Node
35
42
 
36
- attr_reader :meta
43
+ attr_reader :meta
37
44
 
38
- def self.from_JSON json
39
- doc = JSON.parse json
40
- version, metadata, contents = doc.values_at(VERSION, META, BLOCKS)
41
- PandocFilter::Document.new version, metadata, contents
42
- end
45
+ # Create a new Document from a JSON representation of the AST
46
+ #
47
+ # @param json [String] a JSON string representation of the AST of a document
48
+ # @return [Document] the newly created document
49
+ def self.from_JSON(json)
50
+ doc = JSON.parse json
51
+ version, metadata, contents = doc.values_at(VERSION, META, BLOCKS)
52
+ PandocFilter::Document.new version, metadata, contents
53
+ end
43
54
 
44
- def self.fragment node_list
45
- meta = Hash.new
55
+ # Create a new Document fragment from a list of Node elements
56
+ #
57
+ # @param node_list [Array<Node>] a list of nodes to create a Document
58
+ # fragment from
59
+ #
60
+ # @return [Document] the document containing nodes in node_list
61
+ def self.fragment(node_list)
62
+ meta = Hash.new
46
63
 
47
- if node_list.any? {|n| n.is_block?}
48
- new_doc = Document.new CURRENT_PANDOC_VERSION, meta, []
49
- new_doc.children = node_list
50
- else
51
- node = PandocFilter::Plain.new []
52
- node.children = node_list
53
- new_doc = Document.new CURRENT_PANDOC_VERSION, meta, [node.to_ast]
54
- end
64
+ if node_list.any? {|n| n.is_block?}
65
+ new_doc = Document.new CURRENT_PANDOC_VERSION, meta, []
66
+ new_doc.children = node_list
67
+ else
68
+ node = PandocFilter::Plain.new []
69
+ node.children = node_list
70
+ new_doc = Document.new CURRENT_PANDOC_VERSION, meta, [node.to_ast]
71
+ end
55
72
 
56
- new_doc
57
- end
73
+ new_doc
74
+ end
58
75
 
59
- def initialize(version, meta, contents)
60
- @version = Version.new version
61
- @meta = Meta.new meta
62
- super contents
63
- end
76
+ # Create a new Document node based on the pandoc type version,
77
+ # metadata, and the contents of the document
78
+ #
79
+ # @param version [Array<Integer>] the version of pandoc types
80
+ # @param meta [Array] metadata
81
+ # @param contents [Array] contents
82
+ def initialize(version, meta, contents)
83
+ @version = Version.new version
84
+ @meta = Meta.new meta
85
+ super contents
86
+ end
64
87
 
65
- def to_ast
66
- {
67
- VERSION => @version.to_ast,
68
- META => @meta.to_ast,
69
- BLOCKS => ast_contents
70
- }
71
- end
88
+ # Create an AST representation of this Document
89
+ def to_ast()
90
+ {
91
+ VERSION => @version.to_ast,
92
+ META => @meta.to_ast,
93
+ BLOCKS => ast_contents
94
+ }
95
+ end
72
96
 
73
- def to_JSON
74
- to_ast.to_json
75
- end
97
+ # Create a JSON string representation of the AST of this Document.
98
+ # Use this to write back the manipulated AST in a format that
99
+ # pandoc understands.
100
+ def to_JSON
101
+ to_ast.to_json
102
+ end
76
103
 
104
+ end
77
105
  end
78
- end
79
106
  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,11 +17,11 @@
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
- # Emph [Inline]
24
- class Emph < Inline
23
+ # An Emph, emphasized Inline
24
+ class Emph < Inline
25
+ end
25
26
  end
26
- end
27
27
  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,19 +17,23 @@
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 "./block"
20
+ module PandocFilter
21
+ require_relative "./block"
22
22
 
23
- class EmptyBlock < Block
24
- def initialize _
25
- super []
26
- end
23
+ # An EmptyBlock, has not contents
24
+ class EmptyBlock < Block
27
25
 
28
- def to_ast
29
- {
30
- "t" => ast_type
31
- }
32
- end
26
+ # Create an empty block
27
+ def initialize _
28
+ super []
29
+ end
30
+
31
+ # Create an AST representation of this EmptyBlock
32
+ def to_ast
33
+ {
34
+ "t" => ast_type
35
+ }
36
+ end
37
+ end
33
38
  end
34
- end
35
39
  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,23 +17,30 @@
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
- class EmptyInline < Inline
24
- def initialize _
25
- super []
26
- end
27
-
28
- def has_inline?
29
- false
30
- end
23
+ # An EmptyInline node, has no content
24
+ class EmptyInline < Inline
31
25
 
32
- def to_ast
33
- {
34
- "t" => ast_type
35
- }
36
- end
26
+ # Create an EmptyInline node
27
+ def initialize _
28
+ super []
29
+ end
30
+
31
+ # Has this empty inline contents?
32
+ #
33
+ # @return [Boolean] false
34
+ def has_inline?
35
+ false
36
+ end
37
+
38
+ # Create an AST representation of this EmptyInline
39
+ def to_ast
40
+ {
41
+ "t" => ast_type
42
+ }
43
+ end
44
+ end
37
45
  end
38
- end
39
46
  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,31 +17,46 @@
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 "./block"
22
- require_relative "./attr"
20
+ module PandocFilter
21
+ require_relative "./block"
22
+ require_relative "./attr"
23
23
 
24
- # Header Int Attr [Inline]
25
- class Header < Block
26
- attr_accessor :level, :attr
24
+ # A Header node has a level, an attribute object and the contents of
25
+ # the header as a list on Inline nodes.
26
+ #
27
+ # @!attribute level
28
+ # @return [Integer]
29
+ #
30
+ # @!attribute attr
31
+ # @return [Attr]
32
+ class Header < Block
33
+ attr_accessor :level, :attr
27
34
 
28
- def initialize contents
29
- @level = contents[0]
30
- @attr = Attr.new contents[1]
31
- super contents[2], true
32
- end
35
+ # Create a new Header node
36
+ #
37
+ # @param contents [Array] an array with the level, attribute, and
38
+ # the header contents
39
+ def initialize(contents)
40
+ @level = contents[0]
41
+ @attr = Attr.new contents[1]
42
+ super contents[2], true
43
+ end
33
44
 
34
- def ast_contents
35
- [
36
- @level,
37
- @attr.to_ast,
38
- super
39
- ]
40
- end
45
+ # Create an AST representation of this Header node
46
+ def ast_contents()
47
+ [
48
+ @level,
49
+ @attr.to_ast,
50
+ super
51
+ ]
52
+ end
41
53
 
42
- def has_inline?
43
- true
44
- end
54
+ # Has this Header node inline contents?
55
+ #
56
+ # @return [Boolean] true
57
+ def has_inline?
58
+ true
59
+ end
60
+ end
45
61
  end
46
- end
47
62
  end