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.
- checksums.yaml +4 -4
- data/lib/paru/error.rb +6 -4
- data/lib/paru/filter/ast_manipulation.rb +90 -91
- data/lib/paru/filter/attr.rb +75 -69
- data/lib/paru/filter/block.rb +15 -14
- data/lib/paru/filter/block_quote.rb +14 -12
- data/lib/paru/filter/bullet_list.rb +17 -16
- data/lib/paru/filter/caption.rb +50 -48
- data/lib/paru/filter/cell.rb +52 -50
- data/lib/paru/filter/citation.rb +53 -51
- data/lib/paru/filter/cite.rb +34 -33
- data/lib/paru/filter/code.rb +51 -49
- data/lib/paru/filter/code_block.rb +76 -76
- data/lib/paru/filter/col_spec.rb +58 -56
- data/lib/paru/filter/definition_list.rb +51 -52
- data/lib/paru/filter/definition_list_item.rb +45 -43
- data/lib/paru/filter/div.rb +37 -35
- data/lib/paru/filter/document.rb +112 -115
- data/lib/paru/filter/emph.rb +7 -5
- data/lib/paru/filter/empty_block.rb +17 -16
- data/lib/paru/filter/empty_inline.rb +23 -22
- data/lib/paru/filter/figure.rb +41 -39
- data/lib/paru/filter/header.rb +41 -39
- data/lib/paru/filter/horizontal_rule.rb +7 -5
- data/lib/paru/filter/image.rb +13 -12
- data/lib/paru/filter/inline.rb +27 -26
- data/lib/paru/filter/inner_markdown.rb +60 -62
- data/lib/paru/filter/int_value.rb +19 -18
- data/lib/paru/filter/line_block.rb +13 -11
- data/lib/paru/filter/line_break.rb +7 -5
- data/lib/paru/filter/link.rb +34 -33
- data/lib/paru/filter/list.rb +37 -37
- data/lib/paru/filter/list_attributes.rb +52 -51
- data/lib/paru/filter/math.rb +66 -64
- data/lib/paru/filter/meta.rb +40 -39
- data/lib/paru/filter/meta_blocks.rb +7 -5
- data/lib/paru/filter/meta_bool.rb +7 -5
- data/lib/paru/filter/meta_inlines.rb +9 -7
- data/lib/paru/filter/meta_list.rb +7 -5
- data/lib/paru/filter/meta_map.rb +50 -49
- data/lib/paru/filter/meta_string.rb +7 -6
- data/lib/paru/filter/meta_value.rb +26 -25
- data/lib/paru/filter/metadata.rb +150 -88
- data/lib/paru/filter/node.rb +400 -406
- data/lib/paru/filter/note.rb +29 -29
- data/lib/paru/filter/null.rb +7 -5
- data/lib/paru/filter/ordered_list.rb +50 -49
- data/lib/paru/filter/para.rb +21 -20
- data/lib/paru/filter/plain.rb +23 -21
- data/lib/paru/filter/quoted.rb +28 -26
- data/lib/paru/filter/short_caption.rb +7 -5
- data/lib/paru/filter/small_caps.rb +8 -7
- data/lib/paru/filter/soft_break.rb +7 -5
- data/lib/paru/filter/space.rb +7 -5
- data/lib/paru/filter/span.rb +29 -27
- data/lib/paru/filter/str.rb +33 -32
- data/lib/paru/filter/strikeout.rb +7 -6
- data/lib/paru/filter/strong.rb +7 -6
- data/lib/paru/filter/subscript.rb +7 -6
- data/lib/paru/filter/superscript.rb +7 -6
- data/lib/paru/filter/table.rb +201 -210
- data/lib/paru/filter/table_body.rb +67 -67
- data/lib/paru/filter/table_end.rb +53 -55
- data/lib/paru/filter/table_foot.rb +8 -7
- data/lib/paru/filter/table_head.rb +8 -7
- data/lib/paru/filter/target.rb +29 -27
- data/lib/paru/filter/underline.rb +7 -5
- data/lib/paru/filter/value.rb +74 -75
- data/lib/paru/filter/version.rb +23 -22
- data/lib/paru/filter.rb +355 -331
- data/lib/paru/filter_error.rb +7 -5
- data/lib/paru/info.rb +29 -30
- data/lib/paru/pandoc.rb +241 -248
- data/lib/paru/pandoc2yaml.rb +51 -42
- data/lib/paru/selector.rb +193 -184
- data/lib/paru.rb +3 -1
- metadata +4 -73
data/lib/paru/filter/cell.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright 2020
|
4
|
+
# Copyright 2020--2025 Huub de Beer <Huub@heerdebeer.org>
|
3
5
|
#
|
4
6
|
# This file is part of Paru
|
5
7
|
#
|
@@ -16,60 +18,60 @@
|
|
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
|
20
|
-
require_relative
|
21
|
-
require_relative
|
21
|
+
require_relative 'block'
|
22
|
+
require_relative 'value'
|
23
|
+
require_relative 'int_value'
|
22
24
|
|
23
25
|
module Paru
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
module PandocFilter
|
27
|
+
# A Cell node represents a cell in a table's head, body, or foot.
|
28
|
+
#
|
29
|
+
# @!attribute attr
|
30
|
+
# @return Attr
|
31
|
+
#
|
32
|
+
# @!attribute alignment
|
33
|
+
# @return Value containing a String, one of AlignRight, AlignLeft,
|
34
|
+
# AlignCenter, or AlignDefault.
|
35
|
+
#
|
36
|
+
# @!attribute rowspan
|
37
|
+
# @return Value containing an Integer
|
38
|
+
#
|
39
|
+
# @!attribute colspan
|
40
|
+
# @return Value containing an Integer
|
41
|
+
class Cell < Block
|
42
|
+
attr_accessor :attr, :alignment, :rowspan, :colspan
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
# Create a new Cell based on the row_data
|
45
|
+
#
|
46
|
+
# @param contents [Array]
|
47
|
+
def initialize(contents)
|
48
|
+
@attr = Attr.new contents[0]
|
49
|
+
@alignment = Value.new contents[1]
|
50
|
+
@rowspan = IntValue.new contents[2]
|
51
|
+
@colspan = IntValue.new contents[3]
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
+
super(contents[4])
|
54
|
+
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
# The AST contents of this Cell
|
57
|
+
#
|
58
|
+
# @return [Array]
|
59
|
+
def ast_contents
|
60
|
+
[
|
61
|
+
@attr.to_ast,
|
62
|
+
@alignment.to_ast,
|
63
|
+
@rowspan.to_ast,
|
64
|
+
@colspan.to_ast,
|
65
|
+
@children.map(&:to_ast)
|
66
|
+
]
|
67
|
+
end
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
69
|
+
# Create an AST representation of this Node
|
70
|
+
#
|
71
|
+
# @return [Hash]
|
72
|
+
def to_ast
|
73
|
+
ast_contents
|
74
|
+
end
|
74
75
|
end
|
76
|
+
end
|
75
77
|
end
|
data/lib/paru/filter/citation.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright 2015
|
4
|
+
# Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
|
3
5
|
#
|
4
6
|
# This file is part of Paru
|
5
7
|
#
|
@@ -16,58 +18,58 @@
|
|
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
|
20
|
-
|
21
|
+
require_relative 'inline'
|
22
|
+
|
21
23
|
module Paru
|
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
|
-
|
24
|
+
module PandocFilter
|
25
|
+
# A Citation consists of an id, a prefix, a suffix, a mode, a note
|
26
|
+
# number, and integer hash. All of which are optional.
|
27
|
+
#
|
28
|
+
# @see https://hackage.haskell.org/package/pandoc-types-1.17.0.5/docs/Text-Pandoc-Definition.html#t:Citation
|
29
|
+
#
|
30
|
+
# @!attribute id
|
31
|
+
# @return [String]
|
32
|
+
#
|
33
|
+
# @!attribute prefix
|
34
|
+
# @return [Array<Inline>]
|
35
|
+
#
|
36
|
+
# @!attribute suffix
|
37
|
+
# @return [Array<Inline>]
|
38
|
+
#
|
39
|
+
# @!attribute mode
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
# @!attribute note_num
|
43
|
+
# @return [Integer]
|
44
|
+
#
|
45
|
+
# @!attribute hash
|
46
|
+
# @return [Integer]
|
47
|
+
class Citation
|
48
|
+
attr_accessor :id, :prefix, :suffix, :mode, :note_num, :hash
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
# Create a new Citation node base on an AST specification
|
51
|
+
#
|
52
|
+
# @param spec [Hash] the specification of this citation
|
53
|
+
def initialize(spec)
|
54
|
+
@id = spec['citationId'] if spec.key? 'citationId'
|
55
|
+
@prefix = Inline.new spec['citationPrefix'] if spec.key? 'citationPrefix'
|
56
|
+
@suffix = Inline.new spec['citationSuffix'] if spec.key? 'citationSuffix'
|
57
|
+
@mode = spec['citationMode'] if spec.key? 'citationMode'
|
58
|
+
@note_num = spec['citationNoteNum'] if spec.key? 'citationNoteNum'
|
59
|
+
@hash = spec['citationHash'] if spec.key? 'citationHash'
|
60
|
+
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
62
|
+
# Convert this Citation to an AST representation
|
63
|
+
def to_ast
|
64
|
+
citation = {}
|
65
|
+
citation['citationId'] = @id unless @id.nil?
|
66
|
+
citation['citationPrefix'] = @prefix.ast_contents unless @prefix.nil?
|
67
|
+
citation['citationSuffix'] = @suffix.ast_contents unless @suffix.nil?
|
68
|
+
citation['citationMode'] = @mode unless @mode.nil?
|
69
|
+
citation['citationNoteNum'] = @note_num unless @note_num.nil?
|
70
|
+
citation['citationHash'] = @hash unless @hash.nil?
|
71
|
+
citation
|
72
|
+
end
|
72
73
|
end
|
74
|
+
end
|
73
75
|
end
|
data/lib/paru/filter/cite.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright 2015
|
4
|
+
# Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
|
3
5
|
#
|
4
6
|
# This file is part of Paru
|
5
7
|
#
|
@@ -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
|
20
|
-
require_relative
|
21
|
+
require_relative 'inline'
|
22
|
+
require_relative 'citation'
|
21
23
|
|
22
24
|
module Paru
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
module PandocFilter
|
26
|
+
# A Cite node, consisting of a list of Citation nodes, and a list of
|
27
|
+
# Inline nodes
|
28
|
+
#
|
29
|
+
# @!attribute citations
|
30
|
+
# @return [Array<Citation>]
|
31
|
+
class Cite < Inline
|
32
|
+
attr_accessor :citations
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
# Create a new Cite node
|
35
|
+
#
|
36
|
+
# @param contents [Array] an array containing a list of citations
|
37
|
+
# and a list of inline nodes
|
38
|
+
def initialize(contents)
|
39
|
+
super(contents[1])
|
40
|
+
@citations = []
|
41
|
+
contents[0].each do |citation|
|
42
|
+
@citations.push Citation.new(citation)
|
43
|
+
end
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
# Create an AST representation of this Cite node.
|
47
|
+
def ast_contents
|
48
|
+
[
|
49
|
+
@citations.map(&:to_ast),
|
50
|
+
super
|
51
|
+
]
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
54
|
+
# undef_method :inner_markdown
|
55
|
+
# undef_method :inner_markdown=
|
55
56
|
end
|
57
|
+
end
|
56
58
|
end
|
57
|
-
|
data/lib/paru/filter/code.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright 2015
|
4
|
+
# Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
|
3
5
|
#
|
4
6
|
# This file is part of Paru
|
5
7
|
#
|
@@ -16,59 +18,59 @@
|
|
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
|
20
|
-
require_relative
|
21
|
+
require_relative 'inline'
|
22
|
+
require_relative 'attr'
|
21
23
|
|
22
24
|
module Paru
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
module PandocFilter
|
26
|
+
# A Code node, with an attribute object and the code itself as a
|
27
|
+
# string.
|
28
|
+
#
|
29
|
+
# @!attribute attr
|
30
|
+
# @return [Attr]
|
31
|
+
#
|
32
|
+
# @!attribute string
|
33
|
+
# @return [String]
|
34
|
+
class Code < Inline
|
35
|
+
attr_accessor :attr, :string
|
36
|
+
|
37
|
+
# Create a new Code node
|
38
|
+
#
|
39
|
+
# @param contents [Array] an array of the attribute and the code
|
40
|
+
def initialize(contents)
|
41
|
+
@attr = Attr.new contents[0]
|
42
|
+
@string = contents[1]
|
43
|
+
end
|
34
44
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
# Create an AST representation of this Code node.
|
46
|
+
def ast_contents
|
47
|
+
[
|
48
|
+
@attr.to_ast,
|
49
|
+
@string
|
50
|
+
]
|
51
|
+
end
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
53
|
+
# Has this Code node a string contents?
|
54
|
+
#
|
55
|
+
# @return [Boolean] true
|
56
|
+
def has_string?
|
57
|
+
true
|
58
|
+
end
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
60
|
+
# Has this code node inline contents?
|
61
|
+
#
|
62
|
+
# @return [Boolean] false
|
63
|
+
def has_inline?
|
64
|
+
false
|
65
|
+
end
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
# Get the markdown representation of this Node, including the Node
|
66
|
-
# itself.
|
67
|
-
#
|
68
|
-
# @return [String] the outer markdown representation of this Node
|
69
|
-
def markdown()
|
70
|
-
super.strip
|
71
|
-
end
|
72
|
-
end
|
67
|
+
# Get the markdown representation of this Node, including the Node
|
68
|
+
# itself.
|
69
|
+
#
|
70
|
+
# @return [String] the outer markdown representation of this Node
|
71
|
+
def markdown
|
72
|
+
super.strip
|
73
|
+
end
|
73
74
|
end
|
75
|
+
end
|
74
76
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright 2015
|
4
|
+
# Copyright 2015--2025 Huub de Beer <Huub@heerdebeer.org>
|
3
5
|
#
|
4
6
|
# This file is part of Paru
|
5
7
|
#
|
@@ -16,89 +18,87 @@
|
|
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
|
20
|
-
require_relative
|
21
|
-
require_relative
|
21
|
+
require_relative 'block'
|
22
|
+
require_relative 'attr'
|
23
|
+
require_relative 'inner_markdown'
|
22
24
|
|
23
25
|
module Paru
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
module PandocFilter
|
27
|
+
# A CodeBlock is a Block level node with an attribute object and the
|
28
|
+
# code as a string
|
29
|
+
#
|
30
|
+
# @!attribute attr
|
31
|
+
# @return [Attr]
|
32
|
+
#
|
33
|
+
# @!attribute string
|
34
|
+
# @return [String]
|
35
|
+
class CodeBlock < Block
|
36
|
+
include InnerMarkdown
|
37
|
+
|
38
|
+
attr_accessor :attr, :string
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
# Create a new CodeBlock based on the contents
|
41
|
+
#
|
42
|
+
# @param contents [Array] an array with the attribute and the code
|
43
|
+
# string
|
44
|
+
def initialize(contents)
|
45
|
+
@attr = Attr.new contents[0]
|
46
|
+
@string = contents[1]
|
47
|
+
end
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
# An AST representation of this CodeBlock
|
50
|
+
def ast_contents
|
51
|
+
[
|
52
|
+
@attr.to_ast,
|
53
|
+
@string
|
54
|
+
]
|
55
|
+
end
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
# Has this CodeBlock string contents?
|
58
|
+
#
|
59
|
+
# @return [Boolean] true
|
60
|
+
def has_string?
|
61
|
+
true
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
64
|
+
# Write this CodeBlock's contents to file
|
65
|
+
#
|
66
|
+
# @param filename {String} the path to the file to write
|
67
|
+
def to_file(filename)
|
68
|
+
File.write(filename, "#{@string}\n")
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
71
|
+
# Create a new CodeBlock based on the contents of a file, and,
|
72
|
+
# optionally, a language
|
73
|
+
#
|
74
|
+
# @param filename {String} the path to the file to read the
|
75
|
+
# contents from
|
76
|
+
# @param language {String} the language of the contents
|
77
|
+
#
|
78
|
+
# @return [CodeBlock]
|
79
|
+
def self.from_file(filename, language = '')
|
80
|
+
from_code_string(File.read(filename), language)
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
# Get this CodeBlock's contents as a string
|
84
|
+
#
|
85
|
+
# @return [String]
|
86
|
+
def to_code_string
|
87
|
+
@string
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
end
|
90
|
+
# Create a new CodeBlock based on a string and, optionally, a
|
91
|
+
# language
|
92
|
+
#
|
93
|
+
#
|
94
|
+
# @param code_string [String] the string with code to use as the
|
95
|
+
# contents of the CodeBlock
|
96
|
+
# @param language [String] the optional language class
|
97
|
+
# @return [CodeBlock]
|
98
|
+
def self.from_code_string(code_string, language = '')
|
99
|
+
attributes = ['', [language], []]
|
100
|
+
CodeBlock.new [attributes, code_string]
|
101
|
+
end
|
103
102
|
end
|
103
|
+
end
|
104
104
|
end
|