livetext 0.9.38 → 0.9.39

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: dd459c3fa75665b383b8056baa8af5ee9bae77a3abcaeba153b11c422b2f0418
4
- data.tar.gz: 6f3674f4f5f5408e1b7fbffe45631ebbc0c43abbc624f1ba6ade1232e33d10f3
3
+ metadata.gz: c1acd3333afca72468cfc97d2dcdf7d7018700e08d7c0defe4b68d7da53d0824
4
+ data.tar.gz: 32495892978828e9e75d619b9df32891829fd6d6fca9eea46efc5d372fc172c5
5
5
  SHA512:
6
- metadata.gz: 49baee92ae2d7a5ef1337ef98258e416014c954a07d5574f697def625c41e06f7cdaa297ca6cc9a88f3cb3dc4f7c58b589aab889f9bb30d67ba4bf583a52c4f7
7
- data.tar.gz: 6bff41c9c3128a5de6a58f1e81985e35ec3563acbdc133f24427e21c86aca2b475ac0dc1da7967b6e10f92203beab44750ae2ae47bb36a164dfddc62b506c5b9
6
+ metadata.gz: f8c3e9ad8689636fbe83f63117e75461a2a12ca8b716f96f26ca89752f8404093bfd77d1a25ec62dd200263a79f7584960c66a2a2df699b314d909cba82995a7
7
+ data.tar.gz: bee8d442bd0755f18c64851241907569d9150af1a051f04729d82bd84ca814049e14a71c1e9257caea9f26ad3af547ebaaf0a55012f837c37ea4cb2699b22283
@@ -11,6 +11,14 @@ class Livetext::Functions
11
11
  attr_accessor :param # kill this?
12
12
  end
13
13
 
14
+ def code_lines(param = nil)
15
+ $code_lines.to_i # FIXME pleeease
16
+ end
17
+
18
+ def ns(param = nil)
19
+ "\b"
20
+ end
21
+
14
22
  # FIXME Function parameters need to be fixed...
15
23
 
16
24
  def isqrt(param = nil) # "integer square root" - Just for testing
@@ -255,8 +255,3 @@ module Livetext::Helpers
255
255
 
256
256
  end
257
257
 
258
- =begin
259
- /Users/Hal/.rvm/gems/ruby-2.7.0/gems/livetext-0.9.35/lib/livetext/helpers.rb:125:in `invoke_dotcmd'
260
- /Users/Hal/.rvm/gems/ruby-2.7.0/gems/livetext-0.9.35/lib/livetext/helpers.rb:141:in `handle_dotcmd'
261
- /Users/Hal/.rvm/gems/ruby-2.7.0/gems/livetext-0.9.35/lib/livetext/helpers.rb:102:in `process_line'
262
- =end
@@ -74,16 +74,16 @@ module Livetext::Standard
74
74
  return true
75
75
  end
76
76
 
77
- def h1(args = nil, body = nil); api.out html.tag(:h1, api.data); return true; end
78
- def h2(args = nil, body = nil); api.out html.tag(:h2, api.data); return true; end
79
- def h3(args = nil, body = nil); api.out html.tag(:h3, api.data); return true; end
80
- def h4(args = nil, body = nil); api.out html.tag(:h4, api.data); return true; end
81
- def h5(args = nil, body = nil); api.out html.tag(:h5, api.data); return true; end
82
- def h6(args = nil, body = nil); api.out html.tag(:h6, api.data); return true; end
77
+ def h1(args = nil, body = nil); api.out html.tag(:h1, cdata: api.data); return true; end
78
+ def h2(args = nil, body = nil); api.out html.tag(:h2, cdata: api.data); return true; end
79
+ def h3(args = nil, body = nil); api.out html.tag(:h3, cdata: api.data); return true; end
80
+ def h4(args = nil, body = nil); api.out html.tag(:h4, cdata: api.data); return true; end
81
+ def h5(args = nil, body = nil); api.out html.tag(:h5, cdata: api.data); return true; end
82
+ def h6(args = nil, body = nil); api.out html.tag(:h6, cdata: api.data); return true; end
83
83
 
84
84
  def list(args = nil, body = nil)
85
85
  html.wrap :ul do
86
- api.body {|line| api.out html.tag(:li, line) }
86
+ api.body {|line| api.out html.tag(:li, cdata: line) }
87
87
  end
88
88
  api.optional_blank_line
89
89
  end
@@ -94,7 +94,7 @@ module Livetext::Standard
94
94
  loop do
95
95
  line = lines.next
96
96
  line = api.format(line)
97
- str = line[0] == " " ? line : html.tag(:li, line)
97
+ str = line[0] == " " ? line : html.tag(:li, cdata: line)
98
98
  api.out str
99
99
  end
100
100
  end
@@ -200,7 +200,21 @@ module Livetext::Standard
200
200
  rhs = ""
201
201
  text.each_line do |line|
202
202
  str = api.format(line.chomp)
203
- rhs << str + "<br>"
203
+ rhs << str + "<br>\n"
204
+ end
205
+ indent = @parent.indentation.last
206
+ indented = " " * indent
207
+ api.setvar(var, rhs.chomp)
208
+ api.optional_blank_line
209
+ end
210
+
211
+ def heredoc!(args = nil, body = nil) # no <br>
212
+ var = api.args[0]
213
+ text = api.body.join("\n")
214
+ rhs = ""
215
+ text.each_line do |line|
216
+ str = api.format(line.chomp)
217
+ rhs << str + "\n"
204
218
  end
205
219
  indent = @parent.indentation.last
206
220
  indented = " " * indent
@@ -216,6 +230,20 @@ module Livetext::Standard
216
230
  api.optional_blank_line
217
231
  end
218
232
 
233
+ def cinclude(args = nil, body = nil) # dot command
234
+ file = api.expand_variables(api.args.first) # allows for variables
235
+ if api.args.size > 1 # there is an HTML file
236
+ processed = api.expand_variables(api.args[1])
237
+ if File.exist?(processed) && File.mtime(processed) > File.mtime(file)
238
+ api.args = [processed]
239
+ copy
240
+ end
241
+ end
242
+ check_file_exists(file)
243
+ @parent.process_file(file)
244
+ api.optional_blank_line
245
+ end
246
+
219
247
  def dot_include(args = nil, body = nil) # dot command
220
248
  file = api.expand_variables(api.args.first) # allows for variables
221
249
  check_file_exists(file)
@@ -335,10 +363,11 @@ module Livetext::Standard
335
363
  api.body do |line|
336
364
  line = api.format(line)
337
365
  term, defn = line.split(delim)
338
- api.out html.tag(:dt, term)
339
- api.out html.tag(:dd, defn)
366
+ api.out html.tag(:dt, cdata: term)
367
+ api.out " " + html.tag(:dd, cdata: defn)
340
368
  end
341
369
  end
370
+ api.out ""
342
371
  api.optional_blank_line
343
372
  end
344
373
 
@@ -352,13 +381,13 @@ module Livetext::Standard
352
381
  def xtable(args = nil, body = nil) # Borrowed from bookish - FIXME
353
382
  title = api.data
354
383
  delim = " :: "
355
- api.out "<br><center><table width=90% cellpadding=5>"
384
+ api.out "<br>\n\n<center><table width=90% cellpadding=5>"
356
385
  lines = api.body(true)
357
386
  maxw = nil
358
387
  processed = []
359
388
  lines.each do |line|
360
389
  line = api.format(line)
361
- line.gsub!(/\n+/, "<br>")
390
+ line.gsub!(/\n+/, "<br>\n")
362
391
  processed << line
363
392
  cells = line.split(delim)
364
393
  wide = cells.map {|cell| cell.length }
@@ -173,6 +173,7 @@ STDERR.puts "incfile: #{api.methods.sort.inspect}\n "
173
173
  def out(str = "", file = nil)
174
174
  return if str.nil?
175
175
  return file.puts str unless file.nil?
176
+ str.gsub!("\b ", "") # ignore spaces
176
177
  @live.body << str
177
178
  @live.body << "\n" unless str.end_with?("\n")
178
179
  end
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.38"
5
+ VERSION = "0.9.39"
6
6
  end
data/plugin/booktool.rb CHANGED
@@ -1,10 +1,31 @@
1
1
  require 'fileutils'
2
2
 
3
+ def mobi(args = nil, body = nil)
4
+ out = api.format(api.args[0])
5
+ src = api.args[1]
6
+ @cover = api.args[2]
7
+ if ::File.directory?(src)
8
+ files = ::Dir["#{src}/*"].grep /\.html$/
9
+ files = files.sort # why is this necessary now?
10
+ cmd = "cat #{files.join(' ')} >TEMP.html"
11
+ system(cmd)
12
+ else
13
+ raise "Not supported yet"
14
+ end
15
+
16
+ cmd = "ebook-convert "
17
+ cmd << "TEMP.html #{out}.mobi "
18
+ cmd << "--cover #@cover " if @cover
19
+ system(cmd)
20
+
21
+ system("links -dump TEMP.html >/tmp/links.out")
22
+ str = `wc -w /tmp/links.out`
23
+ nw = str.split[0]
24
+ end
25
+
3
26
  def epub(args = nil, body = nil)
4
- api.tty "======== Entering epub"
5
27
  out = api.format(api.args[0])
6
28
  src = api.args[1]
7
- api.tty "======== epub: src = #{src}"
8
29
  @cover = api.args[2]
9
30
  if ::File.directory?(src)
10
31
  files = ::Dir["#{src}/*"].grep /\.html$/
@@ -107,7 +128,7 @@ def xchapterN(args = nil, body = nil)
107
128
  @chapter = api.args.first.to_i
108
129
  @sec = @sec2 = 0
109
130
  title = api.data.split(" ",2)[1]
110
- @toc << "<br><b>#@chapter</b> #{title}<br>"
131
+ @toc << "<br>\n\n<b>#@chapter</b> #{title}<br>\n\n"
111
132
  api.data = _slug(title)
112
133
  next_output
113
134
  api.out "<title>#{@chapter}. #{title}</title>"
@@ -123,7 +144,7 @@ def chapter(args = nil, body = nil)
123
144
  @sec = @sec2 = 0
124
145
  title = api.data # .split(" ",2)[1]
125
146
  _errout("Chapter #@chapter: #{title}")
126
- @toc << "<br><b>#@chapter</b> #{title}<br>"
147
+ @toc << "<br>\n\n<b>#@chapter</b> #{title}<br>\n\n"
127
148
  api.data = _slug(title)
128
149
  next_output
129
150
  api.out "<title>#{@chapter}. #{title}</title>"
@@ -139,10 +160,10 @@ def sec(args = nil, body = nil)
139
160
  @sec2 = 0
140
161
  @section = "#@chapter.#@sec"
141
162
  title = api.data.dup
142
- @toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>"
163
+ @toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>\n"
143
164
  api.data = _slug(api.data)
144
165
  next_output
145
- api.out "<h3>#@section #{title}</h3>\n"
166
+ api.out "<h3>#@section #{title}</h3>\n\n"
146
167
  api.optional_blank_line
147
168
  rescue => err
148
169
  api.tty "#{err}\n#{err.backtrace.join("\n")}"
@@ -154,10 +175,10 @@ def subsec(args = nil, body = nil)
154
175
  @sec2 += 1
155
176
  @subsec = "#@chapter.#@sec.#@sec2"
156
177
  title = api.data.dup
157
- @toc << "#{_nbsp(6)}<b>#@subsec</b> #{title}<br>"
178
+ @toc << "#{_nbsp(6)}<b>#@subsec</b> #{title}<br>\n"
158
179
  api.data = _slug(api.data)
159
180
  next_output
160
- api.out "<h3>#@subsec #{title}</h3>\n"
181
+ api.out "<h3>#@subsec #{title}</h3>\n\n"
161
182
  api.optional_blank_line
162
183
  end
163
184
 
@@ -165,7 +186,7 @@ def definition_table(args = nil, body = nil)
165
186
  title = api.data
166
187
  wide = "95"
167
188
  delim = " :: "
168
- api.out "<br><center><table width=#{wide}% cellpadding=5>"
189
+ api.out "<br>\n\n<center><table width=#{wide}% cellpadding=5>"
169
190
  lines = api.body(true)
170
191
  lines.map! {|line| api.format(line) }
171
192
 
@@ -178,7 +199,7 @@ def definition_table(args = nil, body = nil)
178
199
  end
179
200
  api.out "</tr>"
180
201
  end
181
- api.out "</table></center><br><br>"
202
+ api.out "</table></center>\n\n<br><br>\n\n"
182
203
 
183
204
  api.optional_blank_line
184
205
  end
@@ -188,7 +209,7 @@ def table2(args = nil, body = nil)
188
209
  wide = "90"
189
210
  extra = api.args[2]
190
211
  delim = " :: "
191
- api.out "<br><center><table width=#{wide}% cellpadding=5>"
212
+ api.out "<br>\n\n<center><table width=#{wide}% cellpadding=5>"
192
213
  lines = api.body(true)
193
214
  lines.map! {|line| api.format(line) }
194
215
 
@@ -202,7 +223,7 @@ def table2(args = nil, body = nil)
202
223
  end
203
224
  api.out "</tr>"
204
225
  end
205
- api.out "</table></center><br><br>"
226
+ api.out "</table></center>\n\n<br><br>\n\n"
206
227
  api.optional_blank_line
207
228
  end
208
229
 
@@ -241,11 +262,12 @@ def table(args = nil, body = nil)
241
262
  @table_num += 1
242
263
  title = api.data
243
264
  delim = " :: "
244
- api.out "<br><center><table width=90% cellpadding=5>"
265
+ api.out "<br>\n\n<center><table width=90% cellpadding=5>"
266
+
245
267
  lines = api.body(true)
268
+ # Find max width for each column
246
269
  maxw = nil
247
270
  lines.each do |line|
248
- api.format(line)
249
271
  cells = line.split(delim)
250
272
  wide = cells.map {|x| x.length }
251
273
  maxw = [0] * cells.size
@@ -253,21 +275,22 @@ def table(args = nil, body = nil)
253
275
  end
254
276
 
255
277
  sum = maxw.inject(0, :+)
256
- maxw.map! {|x| (x/sum*100).floor }
278
+ maxw.map! {|x| (x/sum*100.0).floor }
257
279
 
258
280
  lines.each do |line|
281
+ line = api.format(line)
259
282
  cells = line.split(delim)
260
283
  api.out "<tr>"
261
284
  cells.each.with_index do |cell, i|
262
- api.out " <td width=#{maxw}% valign=top>" +
263
- "#{cell}</td>"
285
+ api.out " <td width=#{maxw[i]}% valign=top>#{cell}</td>"
286
+ # api.out " <td valign=top>#{cell}</td>"
264
287
  end
265
288
  api.out "</tr>"
266
289
  end
267
290
  api.out "</table>"
268
- @toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
291
+ @toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>\n"
269
292
  # _next_output(_slug("table_#{title}"))
270
- api.out "<b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>"
293
+ api.out "\n<br><b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>\n\n"
271
294
  api.optional_blank_line
272
295
  end
273
296
 
@@ -296,20 +319,20 @@ EOS
296
319
  end
297
320
 
298
321
  def missing(args = nil, body = nil)
299
- @toc << "#{_nbsp(8)}<font color=red>TBD: #{api.data}</font><br>"
322
+ @toc << "#{_nbsp(8)}<font color=red>TBD: #{api.data}</font><br>\n"
300
323
  stuff = api.data.empty? ? "" : ": #{api.data}"
301
324
  api.out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
302
325
  api.optional_blank_line
303
326
  end
304
327
 
305
328
  def TBC(args = nil, body = nil)
306
- @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
329
+ @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>\n"
307
330
  api.out "<br><font color=red><i>To be continued...</i></font><br>"
308
331
  api.optional_blank_line
309
332
  end
310
333
 
311
334
  def note(args = nil, body = nil)
312
- api.out "<br><font color=red><i>Note: "
335
+ api.out "\n<br>\n<font color=red><i>Note: "
313
336
  api.out api.data
314
337
  api.out "</i></font><br>\n "
315
338
  api.optional_blank_line
data/plugin/codetool.rb CHANGED
@@ -83,12 +83,14 @@ def self.pyg_finalize(code, lexer=:elixir)
83
83
  end
84
84
 
85
85
  def fragment(args = nil, body = nil)
86
+ $code_lines ||= 0 # FIXME later
86
87
  lang = api.args.empty? ? :elixir : api.args.first.to_sym # ruby or elixir
87
88
  api.args = []
88
89
  lines = api.body(true) # .to_a # raw
90
+ $code_lines += lines.size
89
91
  result = send("format_#{lang}", lines)
90
92
  api.out result
91
- api.out "\n"
93
+ api.out "<br>\n"
92
94
  api.optional_blank_line
93
95
  rescue => err
94
96
  STDERR.puts "fragment Error: #{__method__} err = #{err}\n#{err.backtrace.join("\n")}"
@@ -1,4 +1,4 @@
1
- .mixin bookish
1
+ .mixin booktool
2
2
 
3
3
  .simple_table
4
4
  this :: that
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.38
4
+ version: 0.9.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-11 00:00:00.000000000 Z
11
+ date: 2024-01-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -141,10 +141,10 @@ files:
141
141
  - test/snapshots/import_bookish/expected-output.txt
142
142
  - test/snapshots/import_bookish/source.lt3
143
143
  - test/snapshots/import_bookish/toc.tmp
144
- - test/snapshots/mixin_bookish/expected-error.txt
145
- - test/snapshots/mixin_bookish/expected-output.txt
146
- - test/snapshots/mixin_bookish/source.lt3
147
- - test/snapshots/mixin_bookish/toc.tmp
144
+ - test/snapshots/mixin_booktool/expected-error.txt
145
+ - test/snapshots/mixin_booktool/expected-output.txt
146
+ - test/snapshots/mixin_booktool/source.lt3
147
+ - test/snapshots/mixin_booktool/toc.tmp
148
148
  - test/snapshots/more_complex_vars/expected-error.txt
149
149
  - test/snapshots/more_complex_vars/expected-output.txt
150
150
  - test/snapshots/more_complex_vars/source.lt3
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.1.2
222
+ rubygems_version: 3.5.4
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: A smart processor for text