paru 0.3.2.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7c38fdb7f414d72479af9800c0657890853235121c6d6babe1b50e11cb37f87
4
- data.tar.gz: 50ccdff7030eb0f4095ce3230de1eddbcf176ae8878e0358cacc5832329c0f28
3
+ metadata.gz: febb7143d810ddbfefb9ca97accffd9af39376a8ca88ac39f0f03cee17e587cc
4
+ data.tar.gz: a4c93b39c6fe58f8096a35c3daf7c9535b623e650bcd77ba308b0468ce5cb762
5
5
  SHA512:
6
- metadata.gz: daa06cee52aad9ca28c29fb4e064acfa53e9136f40197a9faf2280644d4e91924e8a2cf0fd940af6755c60e17a1c6aa9e8bfc9b05fc48087f5d5b6ff31ee3137
7
- data.tar.gz: 7f465517bd4084d2314073258e5897b5ad22a95190c36c4db1ff4d655e8b80f3f617a9dfead9dd8cff087d21cae7864a4f6d3d20a3e21f20aa3dfbebe968eb71
6
+ metadata.gz: 5e33f1a361dd742cf46325e5d743e2961b5ac678e640a9e52538e00206720ae1e8056224f1427cf50507f25fb3a693147d2fb9962a7277b2a5d3a178e1f62431
7
+ data.tar.gz: 474a1a1e9be86e4798b61dadb9261fa125fc94eb47a1a46663005cee2d2467e938e2d536f7e60ddfd49ee852e8b8304a08893c2727e801b63599d130e9a6acde
@@ -16,7 +16,7 @@ parser = OptionParser.new do |opts|
16
16
  end
17
17
 
18
18
  opts.on("-v", "--version", "Show version") do
19
- puts "do-pandoc.rb is part of paru version 0.2.3"
19
+ puts "do-pandoc.rb is part of paru version 0.4.1"
20
20
  exit
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017, 2018, 2019 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2018, 2019, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -18,5 +18,5 @@
18
18
  #++
19
19
  module Paru
20
20
  # Paru's current version
21
- VERSION = [0, 3, 2, 3]
21
+ VERSION = [0, 4, 1]
22
22
  end
@@ -39,6 +39,12 @@ module Paru
39
39
  "Header",
40
40
  "HorizontalRule",
41
41
  "Table",
42
+ "TableHead",
43
+ "TableFoot",
44
+ "TableBody",
45
+ "Row",
46
+ "Cell",
47
+ "Caption",
42
48
  "Div",
43
49
  "Null"
44
50
  ]
@@ -47,6 +53,7 @@ module Paru
47
53
  PANDOC_INLINE = [
48
54
  "Str",
49
55
  "Emph",
56
+ "Underline",
50
57
  "Strong",
51
58
  "Strikeout",
52
59
  "Superscript",
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./block.rb"
20
+ require_relative "./short_caption.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+ # A table's caption, can contain an optional short caption
25
+ class Caption < Block
26
+ attr_accessor :short
27
+
28
+ # Create a new Caption based on the contents
29
+ #
30
+ # @param contents [Array]
31
+ def initialize(contents)
32
+ if contents[0].nil?
33
+ @short = nil
34
+ else
35
+ @short = ShortCaption.new contents[0]
36
+ end
37
+ super(contents[1])
38
+ end
39
+
40
+ # Does this Caption have a short caption?
41
+ #
42
+ # @return [Boolean]
43
+ def has_short?()
44
+ not @short.nil?
45
+ end
46
+
47
+ # Has this node a block?
48
+ #
49
+ # @return [Boolean] true
50
+ def has_block?
51
+ true
52
+ end
53
+
54
+ # The AST contents of this Caption node
55
+ #
56
+ # @return [Array]
57
+ def ast_contents()
58
+ [
59
+ if has_short? then @short.to_ast else nil end,
60
+ @children.map {|row| row.to_ast}
61
+ ]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,67 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./block.rb"
20
+ require_relative "./value.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+ # A Cell node represents a cell in a table's head, body, or foot
25
+ #
26
+ # @!attribute attr
27
+ # @return Attr
28
+ #
29
+ # @!attribute alignment
30
+ # @return Value containing a String, one of AlignRight, AlignLeft,
31
+ # AlignCenter, or AlignDefault.
32
+ #
33
+ # @!attribute rowspan
34
+ # @return Value containing an Integer
35
+ #
36
+ # @!attribute colspan
37
+ # @return Value containing an Integer
38
+ class Cell < Block
39
+ attr_accessor :attr, :alignment, :rowspan, :colspan
40
+
41
+ # Create a new Cell based on the row_data
42
+ #
43
+ # @param contents [Array]
44
+ def initialize(contents)
45
+ @attr = Attr.new contents[0]
46
+ @alignment = Value.new contents[1]
47
+ @rowspan = Value.new contents[2]
48
+ @colspan = Value.new contents[3]
49
+
50
+ super contents[4]
51
+ end
52
+
53
+ # The AST contents of this Cell
54
+ #
55
+ # @return [Array]
56
+ def ast_contents
57
+ [
58
+ @attr.to_ast,
59
+ @alignment.to_ast,
60
+ @rowspan.to_ast,
61
+ @colspan.to_ast,
62
+ @children.map {|child| child.to_ast}
63
+ ]
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,84 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./value.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+ # The allignment of a table column
24
+ ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
25
+
26
+ # The default width of a column
27
+ COL_WIDTH_DEFAULT = "ColWidthDefault"
28
+
29
+ # Default value for a column specification: left aligned with default
30
+ # width
31
+ DEFAULT_COLSPEC = [{"t": "AlignLeft"}, {"t": COL_WIDTH_DEFAULT}]
32
+
33
+ # ColSpec represents a colspec definition for a table column. It contains an alignment and the column's width.
34
+ #
35
+ # @see https://hackage.haskell.org/package/pandoc-types-1.21/docs/Text-Pandoc-Definition.html#t:ColSpec
36
+ #
37
+ # @!attribute alignment
38
+ # @return [String]
39
+ #
40
+ # @!attribute width
41
+ # @return [Double|COL_WIDTH_DEFAULT]
42
+ class ColSpec
43
+ attr_accessor :alignment, :width
44
+
45
+ # Create a new ColSpec object
46
+ #
47
+ # @param contents [Array = DEFAULT_COLSPEC] the attributes as a pair of [alignment, width]
48
+ def initialize(contents = DEFAULT_COLSPEC)
49
+ @alignment = Value.new contents[0]
50
+ @width = Value.new contents[1]
51
+ end
52
+
53
+ # Set the width
54
+ #
55
+ # @param [String|Integer|Float] new_width the new width. If it is
56
+ # "ColWidthDefault", it uses the default value.
57
+ def width=(new_width)
58
+ if new_width == "ColWidthDefault" then
59
+ @width = Value.new({"t": new_width})
60
+ else
61
+ @width = Value.new({"t": "ColWidth", "c": new_width})
62
+ end
63
+ end
64
+
65
+ # Set the alignment
66
+ #
67
+ # @param [String] new_alignment the new alignment.
68
+ def alignment=(new_alignment)
69
+ @alignment.value = new_alignment
70
+ end
71
+
72
+ # Convert this attributes object to an AST representation
73
+ #
74
+ # @return [Array] Array containing id, class name list, and
75
+ # key-value pair list
76
+ def to_ast
77
+ [
78
+ @alignment.to_ast,
79
+ @width.to_ast
80
+ ]
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -36,7 +36,7 @@ module Paru
36
36
 
37
37
  # The current pandoc type version
38
38
  # @see https://hackage.haskell.org/package/pandoc-types
39
- CURRENT_PANDOC_VERSION = [1, 17, 2]
39
+ CURRENT_PANDOC_VERSION = [1, 21]
40
40
 
41
41
  # Each file that is being filtered by pandoc is represented by a root
42
42
  # Document. It is the root node of the AST of the document in the file.
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,7 +17,6 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  require_relative "../pandoc.rb"
20
-
21
20
  require_relative './ast_manipulation.rb'
22
21
 
23
22
  module Paru
@@ -26,12 +25,12 @@ module Paru
26
25
  # A Paru::Pandoc converter from JSON to markdown
27
26
  AST2MARKDOWN = Paru::Pandoc.new do
28
27
  from "json"
29
- to "markdown"
28
+ to "markdown-smart"
30
29
  end
31
30
 
32
31
  # A Paru::Pandoc converter from markdown to JSON
33
32
  MARKDOWN2JSON = Paru::Pandoc.new do
34
- from "markdown"
33
+ from "markdown+smart"
35
34
  to "json"
36
35
  end
37
36
 
@@ -64,7 +63,11 @@ module Paru
64
63
  require_relative './plain.rb'
65
64
  require_relative './raw_block.rb'
66
65
  require_relative './table.rb'
67
- require_relative './table_row.rb'
66
+ require_relative './caption.rb'
67
+ require_relative './table_head.rb'
68
+ require_relative './table_foot.rb'
69
+ require_relative './row.rb'
70
+ require_relative './cell.rb'
68
71
 
69
72
  # Inline level nodes
70
73
  require_relative './cite.rb'
@@ -88,6 +91,7 @@ module Paru
88
91
  require_relative './str.rb'
89
92
  require_relative './subscript.rb'
90
93
  require_relative './superscript.rb'
94
+ require_relative './short_caption.rb'
91
95
 
92
96
  # Metadata level nodes
93
97
  require_relative './meta_blocks.rb'
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -17,32 +17,51 @@
17
17
  # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
  require_relative "./block.rb"
20
+ require_relative "./cell.rb"
20
21
 
21
22
  module Paru
22
23
  module PandocFilter
23
- # A TableRow node represents a row in a table's head or body
24
- class TableRow < Block
25
- # Create a new TableRow based on the row_data
24
+
25
+ # A Row node represents a row in a table's head or body
26
+ #
27
+ # @!attribute attr
28
+ # @return Attr
29
+ #
30
+ # @!attribute cells
31
+ # @return [Block]
32
+ class Row < Block
33
+ attr_accessor :attr
34
+
35
+ # Create a new Row based on the row_data
26
36
  #
27
- # @param row_data [Array]
28
- def initialize(row_data)
29
- super []
30
- row_data.each do |cell|
31
- @children.push Block.new cell
32
- end
37
+ # @param contents [Array = []] the contents of
38
+ # this Row node
39
+ def initialize(contents = [])
40
+ @attr = Attr.new contents[0]
41
+ super contents[1]
42
+ end
43
+
44
+ # The cells of this row
45
+ #
46
+ # @return [Array<Cell>]
47
+ def cells()
48
+ @children
33
49
  end
34
50
 
35
- # The AST contents of this TableRow
51
+ # The AST contents of this Row
36
52
  #
37
53
  # @return [Array]
38
54
  def ast_contents
39
- @children.map {|child| child.ast_contents}
55
+ [
56
+ @attr.to_ast,
57
+ @children.map {|child| child.to_ast}
58
+ ]
40
59
  end
41
60
 
42
- # Convert this TableRow to an array of markdown strings, one for
61
+ # Convert this Row to an array of markdown strings, one for
43
62
  # each cell
44
63
  #
45
- # @return [String[]] An Array representation of this TableRow.
64
+ # @return [String[]] An Array representation of this Row.
46
65
  def to_array()
47
66
  @children.map do |cell|
48
67
  cell.children.map{|c| c.markdown.strip}.join("\n")
@@ -0,0 +1,27 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./inline.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+ # A ShortCaption used in a table's caption.
24
+ class ShortCaption < Inline
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -19,44 +19,46 @@
19
19
  require "csv"
20
20
  require_relative "./block.rb"
21
21
  require_relative "./inline.rb"
22
+ require_relative "./caption.rb"
23
+ require_relative "./col_spec.rb"
24
+ require_relative "./row.rb"
25
+ require_relative "./table_head.rb"
26
+ require_relative "./table_foot.rb"
27
+ require_relative "./table_body.rb"
22
28
 
23
29
  module Paru
24
30
  module PandocFilter
25
- # The allignment of a table column
26
- ALIGNMENTS = ["AlignLeft", "AlignRight", "AlignCenter", "AlignDefault"]
27
31
 
28
32
  # A Table node represents a table with an inline caption, column
29
33
  # definition, widths, headers, and rows.
30
34
  #
31
35
  # @!attribute caption
32
- # @return [Inline]
36
+ # @return Caption
37
+ #
38
+ # @!attribute attr
39
+ # @return Attr
33
40
  #
34
- # @!attribute alignment
35
- # @return [ALIGNMENTS]
41
+ # @!attribute colspec
42
+ # @return [ColSpec]
36
43
  #
37
- # @!attribute column_widths
38
- # @return [Float]
39
- #
40
- # @!attribute headers
41
- # @return [TableRow]
42
- #
43
- # @!attribute rows
44
- # @return [Array<TableRow>]
44
+ # @!attribute head
45
+ # @return [TableHead]
46
+ #
47
+ # @!attribute foot
48
+ # @return [TableHead]
45
49
  class Table < Block
46
- attr_accessor :caption, :alignment, :column_widths, :headers, :rows
50
+ attr_accessor :caption, :attr, :colspec, :head, :foot
47
51
 
48
52
  # Create a new Table based on the contents
49
53
  #
50
54
  # @param contents [Array]
51
55
  def initialize(contents)
52
- @caption = Inline.new contents[0]
53
- @alignment = contents[1]
54
- @column_widths = contents[2]
55
- @headers = TableRow.new contents[3]
56
- @children = []
57
- contents[4].each do |row_data|
58
- @children.push TableRow.new row_data
59
- end
56
+ @attr = Attr.new contents[0]
57
+ @caption = Caption.new contents[1]["c"]
58
+ @colspec = contents[2].map {|p| ColSpec.new p}
59
+ @head = TableHead.new contents[3]["c"]
60
+ super contents[4]
61
+ @foot = TableFoot.new contents[5]["c"]
60
62
  end
61
63
 
62
64
  # The AST contents of this Table node
@@ -64,11 +66,12 @@ module Paru
64
66
  # @return [Array]
65
67
  def ast_contents()
66
68
  [
67
- @caption.ast_contents,
68
- @alignment,
69
- @column_widths,
70
- @headers.ast_contents,
71
- @children.map {|row| row.ast_contents}
69
+ @attr.to_ast,
70
+ @caption.to_ast,
71
+ @colspec.map {|c| c.to_ast},
72
+ @head.to_ast,
73
+ @children.map {|c| c.to_ast},
74
+ @foot.to_ast,
72
75
  ]
73
76
  end
74
77
 
@@ -82,14 +85,19 @@ module Paru
82
85
  # represented by their markdown strings.
83
86
  def to_array(**config)
84
87
  headers = if config.has_key? :headers then config[:headers] else false end
88
+ footers = if config.has_key? :footers then config[:footers] else false end
85
89
 
86
90
  data = []
87
91
  if headers then
88
- data.push @headers.to_array
92
+ data.concat @head.to_array
89
93
  end
90
94
 
91
95
  @children.each do |row|
92
- data.push row.to_array
96
+ data.concat row.to_array
97
+ end
98
+
99
+ if footers then
100
+ data.concat @foot.to_array
93
101
  end
94
102
 
95
103
  data
@@ -113,53 +121,53 @@ module Paru
113
121
  # @param config [Hash] configuration of the list.
114
122
  # properties:
115
123
  # :headers [Boolean] True if data includes headers on first
116
- # row
124
+ # row. Defailts to false.
117
125
  # :caption [String] The table's caption
118
- # :alignment [String[]] An array with alignments for each
119
- # column. Should have an alignment for all columns. Defaults
120
- # to "AlignLeft"
121
- # :widhts [Number[]] An array with column widths. Should have
122
- # a width for all columns. Use 0 for no set width. Defaults to
123
- # 0
126
+ # :footers [Boolean] True if data includes footers on last row,
127
+ # default to false.
124
128
  #
125
129
  # @return [Table]
126
130
  def self.from_array(data, **config)
127
- return Table.new [[],[],[],[],[]] if data.empty?
128
-
129
- headers = if config.has_key? :headers then
130
- config[:headers]
131
- else
132
- false
133
- end
134
- caption = if config.has_key? :caption then
135
- Block.from_markdown(config[:caption]).ast_contents
136
- else
137
- []
138
- end
139
-
140
- alignment = if config.has_key? :alignment then
141
- config[:alignment].map {|a| {"t" => "#{a}"}}
142
- else
143
- data.first.map {|_| {"t"=>"AlignLeft"}}
144
- end
145
-
146
- widths = if config.has_key? :widths then
147
- config[:widths]
148
- else
149
- data.first.map {|_| 0}
150
- end
151
-
152
- header = []
153
- rows = data
154
- if headers then
155
- header = data.first
156
- header = header.map {|cell| [Block.from_markdown(cell).to_ast]}
157
- rows = data.slice(1..-1)
131
+ # With the updated Table definition, it has become complicated
132
+ # to construct a table manually. It has gotten easier to just
133
+ # construct a string containing a table in Pandoc's markdown and
134
+ # load that. I did remove setting alignments and column widths,
135
+ # though, because that is a bit of a hassle to get right.
136
+
137
+ markdown_table = ""
138
+ header = ""
139
+ footer = ""
140
+
141
+ if config.has_key? :headers and config[:headers] then
142
+ head_row = data.first
143
+ header += head_row.join(" \t") + "\n"
144
+ header += head_row.map {|s| s.gsub(/./, "-") + "-"}.join("\t") + "\n"
145
+ data = data.slice(1..-1)
158
146
  end
159
-
160
- rows = rows.map {|row| row.map {|cell| [Block.from_markdown(cell).to_ast]}}
161
147
 
162
- Table.new [caption, alignment, widths, header, rows]
148
+ if config.has_key? :footers and config[:footers] then
149
+ foot_row = data.first
150
+ footer += foot_row.join(" \t") + "\n"
151
+ footer += foot_row.map {|s| s.gsub(/./, "-") + "-"}.join("\t") + "\n"
152
+ data = data.slice(0, -2)
153
+ end
154
+
155
+ data.each do |row|
156
+ markdown_table += row.join(" \t") + "\n"
157
+ end
158
+
159
+ markdown_table = header + markdown_table + footer
160
+
161
+ if config.has_key? :caption then
162
+ markdown_table += "\n"
163
+ markdown_table += ": #{config[:caption]}\n"
164
+ end
165
+
166
+ table = Block.new []
167
+ table.markdown = markdown_table
168
+ table = table.children.first
169
+
170
+ table
163
171
  end
164
172
 
165
173
 
@@ -0,0 +1,87 @@
1
+ #--
2
+ # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./block.rb"
20
+ require_relative "./row.rb"
21
+ require_relative "./value.rb"
22
+
23
+ module Paru
24
+ module PandocFilter
25
+ # A TableBody node represents a row in a table's head or body
26
+ #
27
+ # @!attribute attr
28
+ # @return Attr
29
+ #
30
+ # @!attribute rowheadcolumns
31
+ # @return Value containing an Integer indicating the number of head
32
+ # columns.
33
+ #
34
+ # @!attribute rowheadercolums
35
+ # @return [Row]
36
+ #
37
+ # @!attribute rows
38
+ # @return [Row]
39
+ class TableBody < Block
40
+ attr_accessor :attr, :rowheadcolumnspec, :rowheadercolumns
41
+
42
+ # Create a new TableBody
43
+ #
44
+ # @param contents [Array] The contents of this TableBody
45
+ def initialize(contents)
46
+ @attr = Attr.new contents[0]
47
+ @rowheadcolumns = Value.new contents[1]
48
+ @rowheadercolumns = contents[2].map {|r| Row.new r}
49
+
50
+ super []
51
+ contents[3].each do |row|
52
+ @children.push Row.new row["c"]
53
+ end
54
+ end
55
+
56
+ # The rows in this TableBody
57
+ #
58
+ # @return [Array<Row>]
59
+ def rows()
60
+ @children
61
+ end
62
+
63
+ # The AST contents of this TableBody
64
+ #
65
+ # @return [Array]
66
+ def ast_contents
67
+ [
68
+ @attr.to_ast,
69
+ @rowheadcolumns.to_ast,
70
+ @rowheadercolumns.map {|r| r.to_ast},
71
+ @children.map {|child| child.to_ast}
72
+ ]
73
+ end
74
+
75
+ # Convert this table end to a 2D table of markdown strings for each
76
+ # cell
77
+ #
78
+ # @return [String[][]] This Table as a 2D array of cells
79
+ # represented by their markdown strings.
80
+ def to_array()
81
+ @children.map do |row|
82
+ row.to_array
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,71 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require "csv"
20
+ require_relative "./block.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+
25
+ # A TableEnd node is the base class for the TableHead and TableFoot
26
+ # nodes. It has attributes and one or more rows.
27
+ #
28
+ # @!attribute attr
29
+ # @return Attr
30
+ #
31
+ # @!attribute rows
32
+ # @return [Row]
33
+ class TableEnd < Block
34
+ attr_accessor :attr
35
+
36
+ # Create a new TableEnd based on the contents
37
+ #
38
+ # @param contents [Array]
39
+ def initialize(contents)
40
+ @attr = Attr.new contents[0]
41
+ super contents[1]
42
+ end
43
+
44
+ def rows()
45
+ @children
46
+ end
47
+
48
+ # The AST contents of this Table node
49
+ #
50
+ # @return [Array]
51
+ def ast_contents()
52
+ [
53
+ @attr.to_ast,
54
+ @children.map {|row| row.to_ast},
55
+ ]
56
+ end
57
+
58
+ # Convert this table end to a 2D table of markdown strings for each
59
+ # cell
60
+ #
61
+ # @return [String[][]] This Table as a 2D array of cells
62
+ # represented by their markdown strings.
63
+ def to_array()
64
+ @children.map do |row|
65
+ row.to_array
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./table_end.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+
24
+ # A TableFoot node represents the heading of a table.
25
+ class TableFoot < TableEnd
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./table_end.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+
24
+ # A TableHead node represents the heading of a table.
25
+ class TableHead < TableEnd
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./inline.rb"
20
+
21
+ module Paru
22
+ module PandocFilter
23
+ # A Underline inline node
24
+ class Underline < Inline
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,108 @@
1
+ #--
2
+ # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
3
+ #
4
+ # This file is part of Paru
5
+ #
6
+ # Paru is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Paru is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Paru. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+ require_relative "./node.rb"
20
+ require_relative "../filter_error.rb"
21
+
22
+ module Paru
23
+ module PandocFilter
24
+
25
+ # Values without value are encoded in their type name.
26
+ VALUE_ENCODED_IN_TYPE_NAME = :value_encoded_in_type_name
27
+
28
+ # A Value node that represents some sort of metadata about block or
29
+ # inline nodes
30
+ class Value < Node
31
+
32
+ # Create a new Value with contents. Also indicate if this node has
33
+ # inline children or block children.
34
+ #
35
+ # @param contents [Array<pandoc node in JSON> = []] the contents of
36
+ # this node
37
+ def initialize(contents)
38
+ @type = contents["t"]
39
+
40
+ if contents.has_key? "c" then
41
+ @value = contents["c"]
42
+ else
43
+ @value = VALUE_ENCODED_IN_TYPE_NAME
44
+ end
45
+ end
46
+
47
+ # Get the encoded value
48
+ #
49
+ # @return [Any]
50
+ def value()
51
+ if type_encodes_value? then
52
+ @type
53
+ else
54
+ @value
55
+ end
56
+ end
57
+
58
+ # Set the encoded value
59
+ #
60
+ # @param [Any] new_value
61
+ def value=(new_value)
62
+ if type_encodes_value? then
63
+ @type = new_value
64
+ else
65
+ @value = new_value
66
+ end
67
+ end
68
+
69
+ # Is this node a block?
70
+ #
71
+ # @return [Boolean] false
72
+ def is_block?
73
+ false
74
+ end
75
+
76
+ # Is this node an inline node?
77
+ #
78
+ # @return [Boolean] false
79
+ def is_inline?
80
+ false
81
+ end
82
+
83
+ # The AST type of this Node
84
+ #
85
+ # @return [String]
86
+ def ast_type()
87
+ @type
88
+ end
89
+
90
+
91
+
92
+ # Create an AST representation of this Node
93
+ #
94
+ # @return [Hash]
95
+ def to_ast()
96
+ return {
97
+ "t" => ast_type,
98
+ "c" => if type_encodes_value? then nil else @value end
99
+ }
100
+ end
101
+
102
+ @private
103
+ def type_encodes_value?()
104
+ return @value == VALUE_ENCODED_IN_TYPE_NAME
105
+ end
106
+ end
107
+ end
108
+ end
@@ -27,6 +27,7 @@ to: ""
27
27
  write: ""
28
28
  output: ""
29
29
  data_dir: ""
30
+ defaults: ""
30
31
  bash_completion: true
31
32
  verbose: true
32
33
  quiet: true
@@ -34,7 +35,7 @@ fail_if_warnings: true
34
35
  log: ""
35
36
  list_input_formats: true
36
37
  list_output_formats: true
37
- list_extensions: true
38
+ list_extensions: ""
38
39
  list_highlight_languages: true
39
40
  list_highlight_styles: true
40
41
  version: true
@@ -42,14 +43,14 @@ help: true
42
43
  #####
43
44
  # General reader options:
44
45
  #####
45
- base_header_level: 1
46
+ shift_heading_level_by: 1
46
47
  indented_code_classes: ""
47
48
  default_image_extension: ""
48
49
  file_scope: true
49
50
  filter: [""]
50
51
  lua_filter: [""]
51
52
  metadata: [""]
52
- metadata-file: ""
53
+ metadata_file: [""]
53
54
  preserve_tabs: true
54
55
  tab_stop: 4
55
56
  track_changes: "accept"
@@ -67,20 +68,21 @@ eol: "native"
67
68
  dpi: 96
68
69
  wrap: "auto"
69
70
  columns: 78
70
- strip-comments: true
71
+ strip_comments: true
71
72
  toc: true
72
73
  table_of_contents: true
73
74
  toc_depth: 3
74
75
  strip_comments: true
75
76
  no_highlight: true
76
77
  highlight_style: ""
77
- print-highlight-style: ""
78
+ print_highlight_style: ""
78
79
  syntax_definition: ""
79
80
  include_in_header: [""]
80
81
  include_before_body: [""]
81
82
  include_after_body: [""]
82
83
  resource_path: ""
83
84
  request_header: ""
85
+ no_check_certificate: false
84
86
  #####
85
87
  # Options affecting specific writers
86
88
  #####
@@ -108,7 +110,7 @@ epub_metadata: ""
108
110
  epub_embed_font: ""
109
111
  epub_chapter_level: 1
110
112
  epub_subdirectory: ""
111
- ipynb-output: "best"
113
+ ipynb_output: "best"
112
114
  pdf_engine: "pdflatex"
113
115
  pdf_engine_opt: [""]
114
116
  #####
@@ -122,16 +124,11 @@ biblatex: true
122
124
  #####
123
125
  # Math rendering in HTML
124
126
  #####
125
- asciimathml: ""
126
- latexmathml: ""
127
- mathml: true
128
- jsmath: ""
129
127
  mathjax: ""
130
- gladtex: true
131
- mimetex: ""
128
+ mathml: true
132
129
  webtex: ""
133
130
  katex: ""
134
- katex_stylesheet: ""
131
+ gladtex: true
135
132
  #####
136
133
  # Options for wrapper scripts
137
134
  #####
@@ -59,9 +59,10 @@ module Paru
59
59
  private
60
60
 
61
61
  S = /\s*/
62
- TYPE = /(?<type>(?<name>[A-Z][a-zA-Z]*)(?<classes>(\.[a-zA-Z-]+)*))/
63
62
  # Improved CSS class selector taken from https://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors/449000#449000
64
- OTHER_TYPE = /(?<other_type>(?<other_name>[A-Z][a-zA-Z]*)(?<other_classes>(\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*)*))/
63
+ CLASS = /(\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*)/
64
+ TYPE = /(?<type>(?<name>[A-Z][a-zA-Z]*)(?<classes>#{CLASS}*))/
65
+ OTHER_TYPE = /(?<other_type>(?<other_name>[A-Z][a-zA-Z]*)(?<other_classes>#{CLASS}*))/
65
66
  OPERATOR = /(?<operator>\+|-|>)/
66
67
  DISTANCE = /(?<distance>[1-9][0-9]*)/
67
68
  RELATION = /(?<relation>#{S}#{OTHER_TYPE}#{S}#{OPERATOR}#{S}#{DISTANCE}?#{S})/
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2.3
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huub de Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-31 00:00:00.000000000 Z
11
+ date: 2020-07-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Use Pandoc (http://www.pandoc.org) with ruby
13
+ description: Control pandoc with Ruby and write pandoc filters in Ruby
14
14
  email: Huub@heerdebeer.org
15
15
  executables:
16
16
  - pandoc2yaml.rb
@@ -28,10 +28,13 @@ files:
28
28
  - lib/paru/filter/block.rb
29
29
  - lib/paru/filter/block_quote.rb
30
30
  - lib/paru/filter/bullet_list.rb
31
+ - lib/paru/filter/caption.rb
32
+ - lib/paru/filter/cell.rb
31
33
  - lib/paru/filter/citation.rb
32
34
  - lib/paru/filter/cite.rb
33
35
  - lib/paru/filter/code.rb
34
36
  - lib/paru/filter/code_block.rb
37
+ - lib/paru/filter/col_spec.rb
35
38
  - lib/paru/filter/definition_list.rb
36
39
  - lib/paru/filter/definition_list_item.rb
37
40
  - lib/paru/filter/div.rb
@@ -68,6 +71,8 @@ files:
68
71
  - lib/paru/filter/quoted.rb
69
72
  - lib/paru/filter/raw_block.rb
70
73
  - lib/paru/filter/raw_inline.rb
74
+ - lib/paru/filter/row.rb
75
+ - lib/paru/filter/short_caption.rb
71
76
  - lib/paru/filter/small_caps.rb
72
77
  - lib/paru/filter/soft_break.rb
73
78
  - lib/paru/filter/space.rb
@@ -78,8 +83,13 @@ files:
78
83
  - lib/paru/filter/subscript.rb
79
84
  - lib/paru/filter/superscript.rb
80
85
  - lib/paru/filter/table.rb
81
- - lib/paru/filter/table_row.rb
86
+ - lib/paru/filter/table_body.rb
87
+ - lib/paru/filter/table_end.rb
88
+ - lib/paru/filter/table_foot.rb
89
+ - lib/paru/filter/table_head.rb
82
90
  - lib/paru/filter/target.rb
91
+ - lib/paru/filter/underline.rb
92
+ - lib/paru/filter/value.rb
83
93
  - lib/paru/filter/version.rb
84
94
  - lib/paru/filter_error.rb
85
95
  - lib/paru/pandoc.rb
@@ -99,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
109
  requirements:
100
110
  - - ">="
101
111
  - !ruby/object:Gem::Version
102
- version: '2.4'
112
+ version: '2.5'
103
113
  required_rubygems_version: !ruby/object:Gem::Requirement
104
114
  requirements:
105
115
  - - ">="