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
@@ -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
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
|
+
require_relative "./list"
|
23
|
+
require_relative "./inline"
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
data/lib/paru/filter/div.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,36 @@
|
|
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
|
-
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
data/lib/paru/filter/document.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,63 +17,90 @@
|
|
17
17
|
# along with Paru. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#++
|
19
19
|
module Paru
|
20
|
-
|
20
|
+
module PandocFilter
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
require "json"
|
23
|
+
require_relative "./node"
|
24
|
+
require_relative "./plain"
|
25
|
+
require_relative "./meta"
|
26
|
+
require_relative "./version"
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
VERSION = "pandoc-api-version"
|
29
|
+
META = "meta"
|
30
|
+
BLOCKS = "blocks"
|
31
31
|
|
32
|
-
|
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
|
-
|
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
|
-
|
43
|
+
attr_reader :meta
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
73
|
+
new_doc
|
74
|
+
end
|
58
75
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
data/lib/paru/filter/emph.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,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 "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
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
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./block"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
super []
|
26
|
-
end
|
23
|
+
# An EmptyBlock, has not contents
|
24
|
+
class EmptyBlock < Block
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
21
|
-
|
20
|
+
module PandocFilter
|
21
|
+
require_relative "./inline"
|
22
22
|
|
23
|
-
|
24
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
data/lib/paru/filter/header.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,46 @@
|
|
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 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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|