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.
- checksums.yaml +4 -4
- data/lib/paru.rb +8 -20
- data/lib/paru/error.rb +4 -6
- data/lib/paru/filter.rb +144 -110
- data/lib/paru/filter/ast_manipulation.rb +75 -39
- data/lib/paru/filter/attr.rb +72 -36
- data/lib/paru/filter/block.rb +14 -8
- data/lib/paru/filter/block_quote.rb +12 -9
- data/lib/paru/filter/bullet_list.rb +6 -6
- data/lib/paru/filter/citation.rb +51 -25
- data/lib/paru/filter/cite.rb +29 -20
- data/lib/paru/filter/code.rb +41 -24
- data/lib/paru/filter/code_block.rb +36 -21
- data/lib/paru/filter/definition_list.rb +19 -15
- data/lib/paru/filter/definition_list_item.rb +30 -17
- data/lib/paru/filter/div.rb +29 -21
- data/lib/paru/filter/document.rb +73 -46
- data/lib/paru/filter/emph.rb +6 -6
- data/lib/paru/filter/empty_block.rb +17 -13
- data/lib/paru/filter/empty_inline.rb +24 -17
- data/lib/paru/filter/header.rb +38 -23
- data/lib/paru/filter/image.rb +13 -11
- data/lib/paru/filter/inline.rb +21 -10
- data/lib/paru/filter/line_block.rb +6 -6
- data/lib/paru/filter/line_break.rb +6 -6
- data/lib/paru/filter/link.rb +33 -21
- data/lib/paru/filter/list.rb +26 -17
- data/lib/paru/filter/list_attributes.rb +53 -32
- data/lib/paru/filter/markdown.rb +102 -59
- data/lib/paru/filter/math.rb +65 -38
- data/lib/paru/filter/meta.rb +26 -16
- data/lib/paru/filter/meta_blocks.rb +12 -9
- data/lib/paru/filter/meta_bool.rb +6 -6
- data/lib/paru/filter/meta_inlines.rb +12 -9
- data/lib/paru/filter/meta_list.rb +6 -6
- data/lib/paru/filter/meta_map.rb +49 -33
- data/lib/paru/filter/meta_string.rb +6 -6
- data/lib/paru/filter/meta_value.rb +22 -14
- data/lib/paru/filter/node.rb +204 -129
- data/lib/paru/filter/note.rb +31 -20
- data/lib/paru/filter/null.rb +6 -6
- data/lib/paru/filter/ordered_list.rb +34 -18
- data/lib/paru/filter/para.rb +20 -13
- data/lib/paru/filter/plain.rb +21 -12
- data/lib/paru/filter/quoted.rb +27 -18
- data/lib/paru/filter/raw_block.rb +32 -19
- data/lib/paru/filter/raw_inline.rb +40 -22
- data/lib/paru/filter/small_caps.rb +7 -6
- data/lib/paru/filter/soft_break.rb +6 -6
- data/lib/paru/filter/space.rb +6 -6
- data/lib/paru/filter/span.rb +28 -18
- data/lib/paru/filter/str.rb +29 -18
- data/lib/paru/filter/strikeout.rb +6 -6
- data/lib/paru/filter/strong.rb +6 -6
- data/lib/paru/filter/subscript.rb +6 -6
- data/lib/paru/filter/superscript.rb +6 -6
- data/lib/paru/filter/table.rb +51 -29
- data/lib/paru/filter/table_row.rb +21 -14
- data/lib/paru/filter/target.rb +29 -15
- data/lib/paru/filter/version.rb +23 -14
- data/lib/paru/pandoc.rb +165 -111
- data/lib/paru/pandoc_options.yaml +3 -3
- data/lib/paru/selector.rb +176 -153
- metadata +2 -3
- data/lib/paru/filter/alignment.rb +0 -30
data/lib/paru/filter/attr.rb
CHANGED
@@ -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,40 +17,76 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
20
|
+
module PandocFilter
|
21
|
+
|
22
|
+
# Attr represents an attribute object for a node. It contains of an id, a
|
23
|
+
# list of class names and a list of key-value pairs.
|
24
|
+
#
|
25
|
+
# @see https://hackage.haskell.org/package/pandoc-types-1.17.0.5/docs/Text-Pandoc-Definition.html#t:Attr
|
26
|
+
#
|
27
|
+
# @!attribute id
|
28
|
+
# @return [String]
|
29
|
+
#
|
30
|
+
# @!attribute classes
|
31
|
+
# @return [Array<String>]
|
32
|
+
class Attr
|
33
|
+
include Enumerable
|
34
|
+
|
35
|
+
attr_accessor :id, :classes
|
36
|
+
|
37
|
+
# Create a new attributes object
|
38
|
+
#
|
39
|
+
# @param attributes [Array] the attributes as [id, [class names],
|
40
|
+
# [key-value pairs]]
|
41
|
+
def initialize(attributes)
|
42
|
+
@id, @classes, @data = attributes
|
43
|
+
end
|
44
|
+
|
45
|
+
# For each key-value pair of this attributes object
|
46
|
+
def each
|
47
|
+
@data.each
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get the value for key in this attributes object
|
51
|
+
#
|
52
|
+
# @param key [String] the key to get the value for. Nil if it does
|
53
|
+
# not exists
|
54
|
+
def [](key)
|
55
|
+
if @data.key_exists? key
|
56
|
+
@data[key]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Does this attributes object have this key?
|
61
|
+
#
|
62
|
+
# @param name [String] key to find
|
63
|
+
#
|
64
|
+
# @return [Boolean] true if this key exist, false otherwise
|
65
|
+
def has_key?(name)
|
66
|
+
@data.key_exists? name
|
67
|
+
end
|
68
|
+
|
69
|
+
# Does this attributes object have a class?
|
70
|
+
#
|
71
|
+
# @param name [String] the class name to search for.
|
72
|
+
#
|
73
|
+
# @return [Boolean] true if this class name exist, false
|
74
|
+
# otherwise.
|
75
|
+
def has_class?(name)
|
76
|
+
@classes.include? name
|
77
|
+
end
|
78
|
+
|
79
|
+
# Convert this attributes object to an AST representation
|
80
|
+
#
|
81
|
+
# @return [Array] Array containing id, class name list, and
|
82
|
+
# key-value pair list
|
83
|
+
def to_ast
|
84
|
+
[
|
85
|
+
@id,
|
86
|
+
@classes,
|
87
|
+
@data
|
88
|
+
]
|
89
|
+
end
|
90
|
+
end
|
54
91
|
end
|
55
|
-
end
|
56
92
|
end
|
data/lib/paru/filter/block.rb
CHANGED
@@ -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,13 +17,19 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./node"
|
22
|
+
|
23
|
+
# A Block level node.
|
24
|
+
# @see https://hackage.haskell.org/package/pandoc-types-1.17.0.5/docs/Text-Pandoc-Definition.html#t:Block
|
25
|
+
class Block < Node
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
# Is this node a block?
|
28
|
+
#
|
29
|
+
# @return [Boolean] true
|
30
|
+
def is_block?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
27
34
|
end
|
28
|
-
end
|
29
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,14 +17,17 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# A BlockQuote node. Contains a list of Blocks
|
24
|
+
class BlockQuote < Block
|
25
|
+
# Has this node a block?
|
26
|
+
#
|
27
|
+
# @return [Boolean] true
|
28
|
+
def has_block?
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
28
32
|
end
|
29
|
-
end
|
30
33
|
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
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./list"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# BulletList, contains a list of list of Block nodes.
|
24
|
+
class BulletList < List
|
25
|
+
end
|
25
26
|
end
|
26
|
-
end
|
27
27
|
end
|
data/lib/paru/filter/citation.rb
CHANGED
@@ -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,57 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#--
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
|
+
|
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
|
22
47
|
|
23
|
-
|
24
|
-
|
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
|
25
59
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
citation["citationPrefix"] = @prefix.ast_contents if not @prefix.nil?
|
39
|
-
citation["citationSuffix"] = @suffix.ast_contents if not @suffix.nil?
|
40
|
-
citation["citationMode"] = @mode if not @mode.nil?
|
41
|
-
citation["citationNoteNum"] = @note_num if not @note_num.nil?
|
42
|
-
citation["citationHash"] = @hash if not @hash.nil?
|
43
|
-
citation
|
44
|
-
end
|
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
|
45
72
|
end
|
46
|
-
end
|
47
73
|
end
|
data/lib/paru/filter/cite.rb
CHANGED
@@ -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,37 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
# A Cite node, consisting of a list of Citation nodes, and a list of
|
24
|
+
# Inline nodes
|
25
|
+
#
|
26
|
+
# @!attribute citations
|
27
|
+
# @return [Array<Citation>]
|
28
|
+
class Cite < Inline
|
29
|
+
attr_accessor :citations
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# Create a new Cite node
|
32
|
+
#
|
33
|
+
# @param contents [Array] an array containing a list of citations
|
34
|
+
# and a list of inline nodes
|
35
|
+
def initialize contents
|
36
|
+
@citations = []
|
37
|
+
contents[0].each do |citation|
|
38
|
+
@citations.push Citation.new(citation)
|
39
|
+
end
|
40
|
+
super contents[1]
|
41
|
+
end
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
# Create an AST representation of this Cite node.
|
44
|
+
def ast_contents()
|
45
|
+
[
|
46
|
+
@citations.map {|citation| citation.to_ast},
|
47
|
+
super
|
48
|
+
]
|
49
|
+
end
|
50
|
+
end
|
41
51
|
end
|
42
|
-
end
|
43
52
|
end
|
44
53
|
|
data/lib/paru/filter/code.rb
CHANGED
@@ -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,33 +17,50 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
|
+
require_relative "./attr"
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
# Create an AST representation of this Code node.
|
44
|
+
def ast_contents()
|
45
|
+
[
|
46
|
+
@attr.to_ast,
|
47
|
+
@string
|
48
|
+
]
|
49
|
+
end
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
# Has this Code node a string contents?
|
52
|
+
#
|
53
|
+
# @return [Boolean] true
|
54
|
+
def has_string?()
|
55
|
+
true
|
56
|
+
end
|
43
57
|
|
44
|
-
|
45
|
-
|
46
|
-
|
58
|
+
# Has this code node inline contents?
|
59
|
+
#
|
60
|
+
# @return [Boolean] false
|
61
|
+
def has_inline?()
|
62
|
+
false
|
63
|
+
end
|
64
|
+
end
|
47
65
|
end
|
48
|
-
end
|
49
66
|
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,29 +17,44 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
|
+
require_relative "./attr"
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# A CodeBlock is a Block level node with an attribute object and the
|
25
|
+
# code as a string
|
26
|
+
#
|
27
|
+
# @!attribute attr
|
28
|
+
# @return [Attr]
|
29
|
+
#
|
30
|
+
# @!attribute string
|
31
|
+
# @return [String]
|
32
|
+
class CodeBlock < Block
|
33
|
+
attr_accessor :attr, :string
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
# Create a new CodeBlock based on the contents
|
36
|
+
#
|
37
|
+
# @param contents [Array] an array with the attribute and the code
|
38
|
+
# string
|
39
|
+
def initialize(contents)
|
40
|
+
@attr = Attr.new contents[0]
|
41
|
+
@string = contents[1]
|
42
|
+
end
|
32
43
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
# An AST representation of this CodeBlock
|
45
|
+
def ast_contents()
|
46
|
+
[
|
47
|
+
@attr.to_ast,
|
48
|
+
@string
|
49
|
+
]
|
50
|
+
end
|
39
51
|
|
40
|
-
|
41
|
-
|
42
|
-
|
52
|
+
# Has this CodeBlock string contents?
|
53
|
+
#
|
54
|
+
# @return [Boolean] true
|
55
|
+
def has_string?()
|
56
|
+
true
|
57
|
+
end
|
58
|
+
end
|
43
59
|
end
|
44
|
-
end
|
45
60
|
end
|