paru 1.1.2 → 1.2.0

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: a5fdb8848444eeca6165736f3f0aa78109097a49153e8fe397d2587098f4d2db
4
- data.tar.gz: a013d3f067c34eefc32438cba227cef3e8aa086326c0a28c64aa90e4ef83778f
3
+ metadata.gz: c5c453f6e4cb23977b77bb04faa0a9d72b1d7f9569529e5ba3995083f51bf514
4
+ data.tar.gz: af94f1496e2a1df4cf0b5cc842f95887c0000a5d2b4c2e85dc19d39054c40b27
5
5
  SHA512:
6
- metadata.gz: 1d24f3c3675ffeb08ecbdce00469cee0f28f5d9f006d28bbb4094aa1ea7b1d66f50de432126c4cb57217e2ad399de3ba8f3973d2eb3578b3edfe06fa0e971bb3
7
- data.tar.gz: 1f8b3b165bb57273d56b916b6070159771a6873deee11e63379bd5fdfb91a90c8bc08d31be5d4f6c2e30fe9863bfd457f7be79b089ae8c1b113187149fb3e5ee
6
+ metadata.gz: 733a600fc35387fcb8e381fa03099247d2719acbe09f5841d2d53f3703e6d7df28be92608f0bf7d2c180ba27e2bb86cf679ed4ef53d1f08c28a8aa96d13beb20
7
+ data.tar.gz: 817c37dfdc57802e94c70035a03c89c4e631f8c4cac34e92816d17dcb4512791cdd23cce40d2ff113024901aab288da1a18b4a6ab92719b3c57f1060953b78c9
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2020 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2020, 2023 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -22,7 +22,7 @@ require_relative "./int_value.rb"
22
22
 
23
23
  module Paru
24
24
  module PandocFilter
25
- # A Cell node represents a cell in a table's head, body, or foot
25
+ # A Cell node represents a cell in a table's head, body, or foot.
26
26
  #
27
27
  # @!attribute attr
28
28
  # @return Attr
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020, 2023 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -26,12 +26,14 @@ module Paru
26
26
  AST2MARKDOWN = Paru::Pandoc.new do
27
27
  from "json"
28
28
  to "markdown-smart"
29
+ preserve_tabs true
29
30
  end
30
31
 
31
32
  # A Paru::Pandoc converter from markdown to JSON
32
33
  MARKDOWN2JSON = Paru::Pandoc.new do
33
34
  from "markdown+smart"
34
35
  to "json"
36
+ preserve_tabs true
35
37
  end
36
38
 
37
39
  # Every node in a Pandoc AST is mapped to Node. Filters are all about
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2015, 2016, 2017, 2020 Huub de Beer <Huub@heerdebeer.org>
2
+ # Copyright 2015, 2016, 2017, 2020, 2023 Huub de Beer <Huub@heerdebeer.org>
3
3
  #
4
4
  # This file is part of Paru
5
5
  #
@@ -131,46 +131,39 @@ module Paru
131
131
  #
132
132
  # @return [Table]
133
133
  def self.from_array(data, config = {})
134
- # With the updated Table definition, it has become complicated
135
- # to construct a table manually. It has gotten easier to just
136
- # construct a string containing a table in Pandoc's markdown and
137
- # load that. I did remove setting alignments and column widths,
138
- # though, because that is a bit of a hassle to get right.
139
-
140
- markdown_table = ""
141
- header = ""
142
- footer = ""
143
-
144
- if config.has_key? :headers and config[:headers] then
145
- head_row = data.first
146
- header += head_row.join(" \t") + "\n"
147
- header += head_row.map {|s| s.gsub(/./, "-") + "-"}.join("\t") + "\n"
148
- data = data.slice(1..-1)
149
- end
134
+ table_attribute = create_attr
150
135
 
151
- if config.has_key? :footers and config[:footers] then
152
- foot_row = data.first
153
- footer += foot_row.join(" \t") + "\n"
154
- footer += foot_row.map {|s| s.gsub(/./, "-") + "-"}.join("\t") + "\n"
155
- data = data.slice(0, -2)
136
+ caption = []
137
+ if config.has_key? :caption
138
+ caption = create_caption config[:caption]
156
139
  end
157
140
 
158
- data.each do |row|
159
- markdown_table += row.join(" \t") + "\n"
160
- end
141
+ col_spec = data[0].map {|c| ColSpec.new.to_ast }
161
142
 
162
- markdown_table = header + markdown_table + footer
143
+ head = create_endrow []
144
+ if config.has_key? :headers and config[:headers]
145
+ head = create_endrow data.first
146
+ data = data[1..-1]
147
+ end
163
148
 
164
- if config.has_key? :caption then
165
- markdown_table += "\n"
166
- markdown_table += ": #{config[:caption]}\n"
149
+ foot = create_endrow []
150
+ if config.has_key? :footers and config[:footers]
151
+ foot = create_endrow data.last
152
+ data = data[0...-1]
167
153
  end
168
154
 
169
- table = Block.new []
170
- table.markdown = markdown_table
171
- table = table.children.first
155
+ body = create_body data
156
+
157
+ table = [
158
+ table_attribute,
159
+ caption,
160
+ col_spec,
161
+ head,
162
+ body,
163
+ foot
164
+ ]
172
165
 
173
- table
166
+ Table.new table
174
167
  end
175
168
 
176
169
 
@@ -188,6 +181,53 @@ module Paru
188
181
 
189
182
  return self.from_array(data, config)
190
183
  end
184
+
185
+ private
186
+
187
+ def self.create_caption(contents)
188
+ [
189
+ nil,
190
+ [Node.from_markdown(contents).to_ast]
191
+ ]
192
+ end
193
+
194
+ def self.create_body(data)
195
+ [[
196
+ create_attr,
197
+ 0,
198
+ [],
199
+ data.map {|r| create_row(r)}
200
+ ]]
201
+ end
202
+
203
+ def self.create_endrow(data)
204
+ [
205
+ create_attr,
206
+ if data.empty? then [] else [create_row(data)] end
207
+ ]
208
+ end
209
+
210
+ def self.create_row(data)
211
+ [
212
+ create_attr,
213
+ data.map {|c| create_cell(c)}
214
+ ]
215
+ end
216
+
217
+ def self.create_cell(contents)
218
+ [
219
+ create_attr,
220
+ {"t" => "AlignDefault", "c" => nil},
221
+ 1,
222
+ 1,
223
+ [Node.from_markdown(contents).to_ast]
224
+ ]
225
+ end
226
+
227
+ def self.create_attr()
228
+ ["", [], []]
229
+ end
230
+
191
231
  end
192
232
  end
193
233
  end
@@ -87,8 +87,6 @@ module Paru
87
87
  @type
88
88
  end
89
89
 
90
-
91
-
92
90
  # Create an AST representation of this Node
93
91
  #
94
92
  # @return [Hash]
data/lib/paru.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  #++
19
19
  module Paru
20
20
  # Paru's current version
21
- VERSION = [1, 1, 2].freeze
21
+ VERSION = [1, 2, 0].freeze
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paru
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huub de Beer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-30 00:00:00.000000000 Z
11
+ date: 2023-11-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Control pandoc with Ruby and write pandoc filters in Ruby
14
14
  email: Huub@heerdebeer.org
@@ -103,7 +103,7 @@ homepage: https://heerdebeer.org/Software/markdown/paru/
103
103
  licenses:
104
104
  - GPL-3.0
105
105
  metadata: {}
106
- post_install_message:
106
+ post_install_message:
107
107
  rdoc_options: []
108
108
  require_paths:
109
109
  - lib
@@ -118,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
- rubygems_version: 3.4.1
122
- signing_key:
121
+ rubygems_version: 3.4.10
122
+ signing_key:
123
123
  specification_version: 4
124
124
  summary: Paru is a ruby wrapper around pandoc
125
125
  test_files: []