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/col_spec.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,69 +18,69 @@
|
|
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
|
21
|
+
require_relative 'value'
|
20
22
|
|
21
23
|
module Paru
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
module PandocFilter
|
25
|
+
# The allignment of a table column
|
26
|
+
ALIGNMENTS = %w[AlignLeft AlignRight AlignCenter AlignDefault].freeze
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
# The default width of a column
|
29
|
+
COL_WIDTH_DEFAULT = 'ColWidthDefault'
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
# Default value for a column specification: left aligned with default
|
32
|
+
# width
|
33
|
+
DEFAULT_COLSPEC = [{ 't' => 'AlignLeft' }, { 't' => COL_WIDTH_DEFAULT }].freeze
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
# ColSpec represents a colspec definition for a table column. It contains an alignment and the column's width.
|
36
|
+
#
|
37
|
+
# @see https://hackage.haskell.org/package/pandoc-types-1.21/docs/Text-Pandoc-Definition.html#t:ColSpec
|
38
|
+
#
|
39
|
+
# @!attribute alignment
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
# @!attribute width
|
43
|
+
# @return [Double|COL_WIDTH_DEFAULT]
|
44
|
+
class ColSpec
|
45
|
+
attr_reader :alignment, :width
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
# Create a new ColSpec object
|
48
|
+
#
|
49
|
+
# @param contents [Array = DEFAULT_COLSPEC] the attributes as a pair of [alignment, width]
|
50
|
+
def initialize(contents = DEFAULT_COLSPEC)
|
51
|
+
@alignment = Value.new contents[0]
|
52
|
+
@width = Value.new contents[1]
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
# Set the width
|
56
|
+
#
|
57
|
+
# @param [String|Integer|Float] new_width the new width. If it is
|
58
|
+
# "ColWidthDefault", it uses the default value.
|
59
|
+
def width=(new_width)
|
60
|
+
@width = if new_width == 'ColWidthDefault'
|
61
|
+
Value.new({ 't' => new_width })
|
62
|
+
else
|
63
|
+
Value.new({ 't' => 'ColWidth', 'c' => new_width })
|
64
|
+
end
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
# Set the alignment
|
68
|
+
#
|
69
|
+
# @param [String] new_alignment the new alignment.
|
70
|
+
def alignment=(new_alignment)
|
71
|
+
@alignment.value = new_alignment
|
72
|
+
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
74
|
+
# Convert this attributes object to an AST representation
|
75
|
+
#
|
76
|
+
# @return [Array] Array containing id, class name list, and
|
77
|
+
# key-value pair list
|
78
|
+
def to_ast
|
79
|
+
[
|
80
|
+
@alignment.to_ast,
|
81
|
+
@width.to_ast
|
82
|
+
]
|
83
|
+
end
|
83
84
|
end
|
85
|
+
end
|
84
86
|
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,65 +18,62 @@
|
|
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 'list'
|
23
|
+
require_relative 'para'
|
22
24
|
|
23
25
|
module Paru
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@children.push child
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Create an AST representation of this DefinitionList node
|
41
|
-
def ast_contents
|
42
|
-
@children.map {|child| child.to_ast}
|
43
|
-
end
|
26
|
+
module PandocFilter
|
27
|
+
# A DefinitionList is a list of term-definition pairs, respecitively an Inline list and a Block list.
|
28
|
+
class DefinitionList < Block
|
29
|
+
# Create a new DefinitionList node
|
30
|
+
#
|
31
|
+
# @param contents [Array] the contents of this definition list.
|
32
|
+
def initialize(contents)
|
33
|
+
super([])
|
34
|
+
contents.each do |item|
|
35
|
+
child = DefinitionListItem.new item
|
36
|
+
child.parent = self
|
44
37
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def to_array()
|
49
|
-
@children.map do |def_item|
|
50
|
-
def_item.to_array
|
51
|
-
end
|
52
|
-
end
|
38
|
+
@children.push child
|
39
|
+
end
|
40
|
+
end
|
53
41
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# @return [DefinitionList]
|
59
|
-
def self.from_array(definitions)
|
60
|
-
ast_items = definitions.map do |definition|
|
61
|
-
term = Block.from_markdown(definition[0]).ast_contents
|
62
|
-
defin = List.from_markdown(definition[1])
|
42
|
+
# Create an AST representation of this DefinitionList node
|
43
|
+
def ast_contents
|
44
|
+
@children.map(&:to_ast)
|
45
|
+
end
|
63
46
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
47
|
+
# Convert this DefinitionList to a hash of term => definitions
|
48
|
+
#
|
49
|
+
# @return [Array]
|
50
|
+
def to_array
|
51
|
+
@children.map(&:to_array)
|
52
|
+
end
|
71
53
|
|
72
|
-
|
73
|
-
|
54
|
+
# Create a new DefinitionList based on a hash of term =>
|
55
|
+
# definitions
|
56
|
+
#
|
57
|
+
# @param definitions [Array] Array of arrays with terms and their definitions
|
58
|
+
# @return [DefinitionList]
|
59
|
+
def self.from_array(definitions)
|
60
|
+
ast_items = definitions.map do |definition|
|
61
|
+
term = Block.from_markdown(definition[0]).ast_contents
|
62
|
+
defin = List.from_markdown(definition[1])
|
74
63
|
|
75
|
-
|
76
|
-
|
64
|
+
if defin.has_block?
|
65
|
+
defin = defin.children.map(&:to_ast)
|
66
|
+
else
|
67
|
+
para = Para.new []
|
68
|
+
para.inner_markdown = definition[1]
|
69
|
+
defin = [para.to_ast]
|
70
|
+
end
|
77
71
|
|
72
|
+
[term, [defin]]
|
78
73
|
end
|
74
|
+
|
75
|
+
DefinitionList.new ast_items
|
76
|
+
end
|
79
77
|
end
|
78
|
+
end
|
80
79
|
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,54 +18,54 @@
|
|
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 'list'
|
23
|
+
require_relative 'inline'
|
22
24
|
|
23
25
|
module Paru
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
module PandocFilter
|
27
|
+
# A DefinitionListItem is a helper node to represent the pair of a term
|
28
|
+
# and its definition in a DefinitionList
|
29
|
+
#
|
30
|
+
# @!attribute term
|
31
|
+
# @return [Block]
|
32
|
+
#
|
33
|
+
# @!attribute definition
|
34
|
+
# @return [List]
|
35
|
+
class DefinitionListItem < Block
|
36
|
+
attr_accessor :term, :definition
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
# Create a new DefinitionListItem
|
39
|
+
#
|
40
|
+
# @param item [Array] the [term, definition]
|
41
|
+
def initialize(item)
|
42
|
+
super([])
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
@term = Block.new item[0]
|
45
|
+
@term.parent = self
|
46
|
+
@children << @term
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
@definition = List.new item[1]
|
49
|
+
@definition.parent = self
|
50
|
+
@children << @definition
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
# Create an AST representation of this DefinitionListItem
|
54
|
+
def to_ast
|
55
|
+
[
|
56
|
+
@term.ast_contents,
|
57
|
+
@definition.ast_contents
|
58
|
+
]
|
59
|
+
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
61
|
+
# Convert this DefinitionListItem to a pair of term and definition
|
62
|
+
#
|
63
|
+
# @return [Array]
|
64
|
+
def to_array
|
65
|
+
term = @term.children.map { |c| c.markdown.strip }.reject(&:empty?).join(' ').strip
|
66
|
+
definition = @definition.children.map { |c| c.children.map(&:markdown) }.join("\n").strip
|
67
|
+
[term, definition]
|
68
|
+
end
|
68
69
|
end
|
70
|
+
end
|
69
71
|
end
|
data/lib/paru/filter/div.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,45 +18,45 @@
|
|
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
|
-
|
26
|
+
module PandocFilter
|
27
|
+
# A Div node consisting of an attribute object and a list of Block nodes.
|
28
|
+
class Div < Block
|
29
|
+
include InnerMarkdown
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# A Div node has an attribute object
|
32
|
+
#
|
33
|
+
# @!attribute attr
|
34
|
+
# @return [Attr]
|
35
|
+
attr_accessor :attr
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
# Create a new Div node based on the contents
|
38
|
+
#
|
39
|
+
# @param contents [Array] an array containing the attribute object
|
40
|
+
# and the contents of this div.
|
41
|
+
def initialize(contents)
|
42
|
+
@attr = Attr.new contents[0]
|
43
|
+
super(contents[1])
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
# Create an AST representation of this Div node.
|
47
|
+
def ast_contents
|
48
|
+
[
|
49
|
+
@attr.to_ast,
|
50
|
+
super
|
51
|
+
]
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
54
|
+
# Has this Div node Blocks as children?
|
55
|
+
#
|
56
|
+
# @return [Boolean] true
|
57
|
+
def has_block?
|
58
|
+
true
|
59
|
+
end
|
59
60
|
end
|
61
|
+
end
|
60
62
|
end
|