livetext 0.9.33 → 0.9.36

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c6ed527394d333fd5c667d5737093c26595794269dcf444d72bc28cdcbf8c61
4
- data.tar.gz: 7eb6d6907ebfd5bfd2ee7f8253a0c3a051d06cd83ffaac5baca388406168db6c
3
+ metadata.gz: 2dceb322a5f44e776bab9ed9113c7c7a4adf29eff271be81a613c72a081a2d51
4
+ data.tar.gz: 70576d3a39fccbe7f3285ddca930f79400b8d770ef600d043e2b3690f173ba23
5
5
  SHA512:
6
- metadata.gz: 57b37bb2795cacaa81f86f4d251d438b92dd8d0fd7f71839eb68edda95a4bf5d60a56af46d93d9ba93de118b7b878eea53f5daecab6459dd73a0167a5aba33d4
7
- data.tar.gz: 7c7fb6ac4101629dd86b0901a961fc8d4c4901b661ff0eb8553081f7617601c7d807df03212ac57ab14b8c740a3a60efcfd3c2d951bea6b509f57a89170fa2b9
6
+ metadata.gz: 8d91e26a1721ce60ca41ff49a323df2e4ef0a365b0b4eec9b224cbef8381e48b6ab4f3c0bb63e74ada905efb101c69a33e021f521420abe56927b16a46e02091
7
+ data.tar.gz: fa718856dcbb75bb4f60f49f31638041158b815335ba9df3680c2ca0b117a2584d66921e06dae30b266f3104a465f826904a797e3e1a546960d75d6dc79d9d4b
data/bin/livetext CHANGED
@@ -93,8 +93,8 @@ def parse_command_line
93
93
  end
94
94
  end
95
95
  @live.dump if success
96
- # rescue => err
97
- # STDERR.puts "Unexpected error! #{err.inspect}"
96
+ rescue => err
97
+ STDERR.puts "Unexpected error! #{err.inspect}\n#{err.backtrace.join("\n")}"
98
98
  end
99
99
 
100
100
  # Main
data/imports/bookish.rb CHANGED
@@ -98,14 +98,18 @@ module Bookish
98
98
  end
99
99
 
100
100
  def sec(args = nil, body = nil)
101
+ api.tty "## sec: cp 1"
101
102
  @sec += 1
102
103
  @sec2 = 0
103
104
  @section = "#@chapter.#@sec"
105
+ api.tty "## sec: cp 2"
104
106
  title = api.data.dup
105
107
  @toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>"
106
- api.data = _slug(api.data)
108
+ api.data = _slug(title)
109
+ api.tty "## sec: cp 3"
107
110
  next_output
108
111
  api.out "<h3>#@section #{title}</h3>\n"
112
+ api.tty "## sec: cp 4"
109
113
  rescue => err
110
114
  ::STDERR.puts "#{err}\n#{err.backtrace}"
111
115
  exit
@@ -2,6 +2,7 @@
2
2
  require_relative 'global_helpers'
3
3
  require_relative 'expansion'
4
4
 
5
+
5
6
  module Livetext::Helpers
6
7
 
7
8
  Space = " "
@@ -98,13 +99,16 @@ module Livetext::Helpers
98
99
  when Comment
99
100
  success = handle_scomment(line)
100
101
  when DotCmd
101
- success = handle_dotcmd(line)
102
+ success = handle_dotcmd(line) # was 102
102
103
  when DollarDot
103
104
  success = handle_dollar_dot(line)
104
105
  else
105
106
  api.passthru(line) # must succeed?
106
107
  end
107
108
  success
109
+ rescue => err
110
+ STDERR.puts "ERROR: #{err}\n#{err.backtrace.join("\n")}"
111
+ exit
108
112
  end
109
113
 
110
114
  def handle_dollar_dot(line)
@@ -120,7 +124,7 @@ module Livetext::Helpers
120
124
  api.data = data0.dup # should permit _ in function names at least
121
125
  args0 = data0.split
122
126
  api.args = args0.dup
123
- retval = @main.send(name) # , *args)
127
+ retval = @main.send(name) # , *args) # was 125
124
128
  retval
125
129
  rescue => err
126
130
  graceful_error(err)
@@ -135,7 +139,7 @@ module Livetext::Helpers
135
139
  when name == :end # special case
136
140
  graceful_error EndWithoutOpening()
137
141
  when @main.respond_to?(name)
138
- success = invoke_dotcmd(name, data)
142
+ success = invoke_dotcmd(name, data) # was 141
139
143
  else
140
144
  graceful_error UnknownMethod(name)
141
145
  end
@@ -250,3 +254,9 @@ module Livetext::Helpers
250
254
  end
251
255
 
252
256
  end
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
data/lib/livetext/html.rb CHANGED
@@ -1,43 +1,48 @@
1
1
 
2
- module HTMLHelper
3
-
4
- def wrapped(str, *tags) # helper
5
- open, close = open_close_tags(*tags)
6
- open + str + close
7
- end
8
-
9
- def wrapped!(str, tag, **extras) # helper
10
- open, close = open_close_tags(tag)
11
- extras.each_pair do |name, value|
12
- open.sub!(">", " #{name}='#{value}'>")
13
- end
14
- open + str + close
15
- end
16
-
17
- def wrap(*tags) # helper
18
- open, close = open_close_tags(*tags)
19
- api.out open
20
- yield
21
- api.out close
22
- end
23
-
24
- def open_close_tags(*tags)
25
- open, close = "", ""
26
- tags.each do |tag|
27
- open << "<#{tag}>"
28
- close.prepend("</#{tag}>")
29
- end
30
- [open, close]
31
- end
32
- end
2
+ # module HTMLHelper
3
+ #
4
+ # def wrapped(str, *tags) # helper
5
+ # open, close = open_close_tags(*tags)
6
+ # open + str + close
7
+ # end
8
+ #
9
+ # def wrapped!(str, tag, **extras) # helper
10
+ # open, close = open_close_tags(tag)
11
+ # extras.each_pair do |name, value|
12
+ # open.sub!(">", " #{name}='#{value}'>")
13
+ # end
14
+ # open + str + close
15
+ # end
16
+ #
17
+ # def wrap(*tags) # helper
18
+ # open, close = open_close_tags(*tags)
19
+ # api.out open
20
+ # yield
21
+ # api.out close
22
+ # end
23
+ #
24
+ # def open_close_tags(*tags)
25
+ # open, close = "", ""
26
+ # tags.each do |tag|
27
+ # open << "<#{tag}>"
28
+ # close.prepend("</#{tag}>")
29
+ # end
30
+ # [open, close]
31
+ # end
32
+ # end
33
33
 
34
34
  class HTML
35
35
 
36
36
  def initialize(api)
37
+ raise "API is nil!" unless api
37
38
  @api = api
38
39
  @indent = 0
39
40
  end
40
41
 
42
+ def api
43
+ @api
44
+ end
45
+
41
46
  def indented
42
47
  " "*@indent
43
48
  end
@@ -69,10 +74,6 @@ class HTML
69
74
  wrap(:li, **details, &block)
70
75
  end
71
76
 
72
- def api
73
- @api
74
- end
75
-
76
77
  def open_close_tags(*tags)
77
78
  open, close = "", ""
78
79
  tags.each do |tag|
@@ -87,6 +88,7 @@ class HTML
87
88
  extras.each_pair do |name, value|
88
89
  open.sub!(">", " #{name}='#{value}'>")
89
90
  end
91
+ # STDERR.puts "#wrap - @api = #{@api.inspect}\n-----------"
90
92
  api.out indented + open
91
93
  indent(:in)
92
94
  yield
data/lib/livetext/more.rb CHANGED
@@ -138,6 +138,10 @@ class Livetext
138
138
  @api
139
139
  end
140
140
 
141
+ def api=(obj)
142
+ @api = obj
143
+ end
144
+
141
145
  def initial_vars
142
146
  # Other predefined variables (see also setfile)
143
147
  @api.setvar(:User, `whoami`.chomp)
@@ -27,6 +27,8 @@ class Processor
27
27
 
28
28
  def initialize(parent, output = nil)
29
29
  @parent = parent
30
+ # STDERR.puts "PARENT.api = #{parent.api.inspect}"
31
+ @parent.api ||= Livetext::UserAPI.new(@parent)
30
32
  @nopass = false
31
33
  @nopara = false
32
34
  # Meh?
@@ -14,7 +14,7 @@ make_exception(:FileNotFound, "Error: file '%1' not found")
14
14
 
15
15
  module Livetext::Standard
16
16
 
17
- include HTMLHelper
17
+ # include HTMLHelper
18
18
  include Livetext::Helpers
19
19
 
20
20
  TTY = ::File.open("/dev/tty", "w")
@@ -82,14 +82,14 @@ module Livetext::Standard
82
82
  def h6; api.out wrapped(api.data, :h6); return true; end
83
83
 
84
84
  def list
85
- wrap :ul do
85
+ html.wrap :ul do
86
86
  api.body {|line| api.out wrapped(line, :li) }
87
87
  end
88
88
  api.optional_blank_line
89
89
  end
90
90
 
91
91
  def list!
92
- wrap(:ul) do
92
+ html.wrap(:ul) do
93
93
  lines = api.body.each # enumerator
94
94
  loop do
95
95
  line = lines.next
@@ -117,9 +117,10 @@ module Livetext::Standard
117
117
  api.optional_blank_line
118
118
  end
119
119
 
120
- def say
121
- str = api.format(api.data)
122
- TTY.puts str
120
+ def say(arg=nil)
121
+ data = arg || api.args.join(" ")
122
+ str = api.format(data)
123
+ TTY.puts "(say) #{str}"
123
124
  api.optional_blank_line
124
125
  end
125
126
 
@@ -281,7 +282,7 @@ module Livetext::Standard
281
282
  end
282
283
 
283
284
  def debug
284
- self._debug = onoff(api.args.first)
285
+ @debug = onoff(api.args.first)
285
286
  api.optional_blank_line
286
287
  end
287
288
 
@@ -321,7 +322,7 @@ module Livetext::Standard
321
322
  end
322
323
 
323
324
  def mono
324
- wrap ":pre" do
325
+ html.wrap ":pre" do
325
326
  api.body(true) {|line| api.out line }
326
327
  end
327
328
  api.optional_blank_line
@@ -329,7 +330,7 @@ module Livetext::Standard
329
330
 
330
331
  def dlist
331
332
  delim = api.args.first
332
- wrap(:dl) do
333
+ html.wrap(:dl) do
333
334
  api.body do |line|
334
335
  line = api.format(line)
335
336
  term, defn = line.split(delim)
@@ -369,7 +370,7 @@ module Livetext::Standard
369
370
 
370
371
  processed.each do |line|
371
372
  cells = line.split(delim)
372
- wrap :tr do
373
+ html.wrap :tr do
373
374
  cells.each {|cell| api.out " <td valign=top>#{cell}</td>" }
374
375
  end
375
376
  end
@@ -378,8 +379,10 @@ module Livetext::Standard
378
379
  end
379
380
 
380
381
  def image
381
- name = api.args[0]
382
- api.out "<img src='#{name}'></img>"
382
+ name, wide, high = api.args
383
+ geom = ""
384
+ geom = "width=#{wide} height=#{high}" if wide || high
385
+ api.out "<img src='#{name} #{geom}'></img>"
383
386
  api.optional_blank_line
384
387
  end
385
388
 
@@ -5,6 +5,8 @@ require_relative 'html'
5
5
 
6
6
  class Livetext::UserAPI
7
7
 
8
+ include ::Livetext::Standard
9
+
8
10
  KBD = File.new("/dev/tty", "r")
9
11
  TTY = File.new("/dev/tty", "w")
10
12
 
@@ -33,6 +35,8 @@ class Livetext::UserAPI
33
35
 
34
36
  def include_file(file)
35
37
  api.data = file
38
+ api.args = [file]
39
+ STDERR.puts "incfile: #{api.methods.sort.inspect}\n "
36
40
  api.dot_include
37
41
  end
38
42
 
@@ -2,5 +2,5 @@
2
2
  # Defining VERSION
3
3
 
4
4
  class Livetext
5
- VERSION = "0.9.33"
5
+ VERSION = "0.9.36"
6
6
  end
data/plugin/bookish.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  def hardbreaks(args = nil, body = nil)
2
2
  @hard = false
3
3
  @hard = true unless api.args.first == "off"
4
+ api.optional_blank_line
4
5
  end
5
6
 
6
7
  def hardbreaks?
@@ -9,13 +10,14 @@ end
9
10
 
10
11
  def credit(args = nil, body = nil)
11
12
  # really just a place marker in source
13
+ api.optional_blank_line
12
14
  end
13
15
 
14
16
  # These are duplicated. Remove safely
15
17
 
16
- def h1; api.out "<h1>#{api.data}</h1>"; end
17
- def h2; api.out "<h2>#{api.data}</h2>"; end
18
- def h3; api.out "<h3>#{api.data}</h3>"; end
18
+ def h1; api.out "<h1>#{api.data}</h1>"; api.optional_blank_line; end
19
+ def h2; api.out "<h2>#{api.data}</h2>"; api.optional_blank_line; end
20
+ def h3; api.out "<h3>#{api.data}</h3>"; api.optional_blank_line; end
19
21
 
20
22
  def alpha_columns(args = nil, body = nil)
21
23
  n = api.args.first.to_i # FIXME: what if it's missing?
@@ -30,6 +32,7 @@ def alpha_columns(args = nil, body = nil)
30
32
  api.out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
31
33
  end
32
34
  api.out "</table>"
35
+ api.optional_blank_line
33
36
  end
34
37
 
35
38
  # def comment
@@ -55,6 +58,7 @@ end
55
58
  def image(args = nil, body = nil)
56
59
  name = api.args[0]
57
60
  api.out "<img src='#{name}'></img>"
61
+ api.optional_blank_line
58
62
  end
59
63
 
60
64
  def figure(args = nil, body = nil)
@@ -64,6 +68,7 @@ def figure(args = nil, body = nil)
64
68
  title = api.format(title)
65
69
  api.out "<img src='#{name}'></img>"
66
70
  api.out "<center><b>Figure #{num}</b> #{title}</center>"
71
+ api.optional_blank_line
67
72
  end
68
73
 
69
74
  def chapter(args = nil, body = nil)
@@ -79,6 +84,7 @@ def chapter(args = nil, body = nil)
79
84
  <h1>#{title}</h1>
80
85
 
81
86
  HTML
87
+ api.optional_blank_line
82
88
  end
83
89
 
84
90
  def chapterN(args = nil, body = nil)
@@ -95,6 +101,7 @@ def chapterN(args = nil, body = nil)
95
101
  <h1>#{title}</h1>
96
102
 
97
103
  HTML
104
+ api.optional_blank_line
98
105
  end
99
106
 
100
107
  def sec(args = nil, body = nil)
@@ -106,7 +113,9 @@ def sec(args = nil, body = nil)
106
113
  api.data = _slug(api.data)
107
114
  next_output
108
115
  api.out "<h3>#@section #{title}</h3>\n"
116
+ api.optional_blank_line
109
117
  rescue => err
118
+ api.tty "#{err}\n#{err.backtrace}"
110
119
  ::STDERR.puts "#{err}\n#{err.backtrace}"
111
120
  exit
112
121
  end
@@ -119,6 +128,7 @@ def subsec(args = nil, body = nil)
119
128
  api.data = _slug(api.data)
120
129
  next_output
121
130
  api.out "<h3>#@subsec #{title}</h3>\n"
131
+ api.optional_blank_line
122
132
  end
123
133
 
124
134
  def definition_table(args = nil, body = nil)
@@ -234,6 +244,7 @@ end
234
244
  def toc!(args = nil, body = nil)
235
245
  _debug "Closing TOC"
236
246
  @toc.close
247
+ api.optional_blank_line
237
248
  rescue => err
238
249
  puts @parent.body
239
250
  @parent.body = ""
@@ -251,29 +262,34 @@ def toc2(args = nil, body = nil)
251
262
 
252
263
  EOS
253
264
  system("cat toc.tmp >>#{file}")
265
+ api.optional_blank_line
254
266
  end
255
267
 
256
268
  def missing(args = nil, body = nil)
257
269
  @toc << "#{_nbsp(8)}<font color=red>TBD: #{api.data}</font><br>"
258
270
  stuff = api.data.empty? ? "" : ": #{api.data}"
259
271
  api.out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
272
+ api.optional_blank_line
260
273
  end
261
274
 
262
275
  def TBC(args = nil, body = nil)
263
276
  @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
264
277
  api.out "<br><font color=red><i>To be continued...</i></font><br>"
278
+ api.optional_blank_line
265
279
  end
266
280
 
267
281
  def note(args = nil, body = nil)
268
282
  api.out "<br><font color=red><i>Note: "
269
283
  api.out api.data
270
284
  api.out "</i></font><br>\n "
285
+ api.optional_blank_line
271
286
  end
272
287
 
273
288
  def quote(args = nil, body = nil)
274
289
  api.out "<blockquote>"
275
290
  api.body {|line| api.out line }
276
291
  api.out "</blockquote>"
292
+ api.optional_blank_line
277
293
  rescue => err
278
294
  ::STDERR.puts "#{err}\n#{err.backtrace}"
279
295
  exit
@@ -285,3 +301,102 @@ def init_bookish
285
301
  @chapter = -1
286
302
  end
287
303
 
304
+ ################### custom.rb
305
+
306
+
307
+ def outdir
308
+ @_outdir = api.args.first
309
+ # @output = STDOUT
310
+ @output = nil
311
+ api.optional_blank_line
312
+ end
313
+
314
+ def outdir! # FIXME ?
315
+ @_outdir = api.args.first
316
+ raise "No output directory specified" if @_outdir.nil?
317
+ raise "No output directory specified" if @_outdir.empty?
318
+ system("rm -f #@_outdir/*.html")
319
+ api.optional_blank_line
320
+ end
321
+
322
+ def _append(name)
323
+ @_outdir ||= "."
324
+ @output.close unless @output == STDOUT
325
+ @output = File.open(@_outdir + "/" + name, "a")
326
+ @output.puts "<meta charset='UTF-8'>\n\n"
327
+ end
328
+
329
+
330
+ def append
331
+ file = api.args[0]
332
+ _append(file)
333
+ end
334
+
335
+ def close_output
336
+ return if @output == STDOUT
337
+ @_outdir ||= "."
338
+ @output.puts "<meta charset='UTF-8'>\n\n"
339
+ @output.puts @parent.body
340
+ @output.close
341
+ @parent.body = "" # See bin/livetext
342
+ @output = STDOUT
343
+ end
344
+
345
+ def _prep_next_output(args)
346
+ tag, num = args # _next_output(tag, num)
347
+ @_file_num = num ? num : @_file_num + 1
348
+ @_file_num = @_file_num.to_i
349
+ name = "#{'%03d' % @_file_num}-#{tag}.html"
350
+ api.tty "tag, num, name= #{[tag, num, name].inspect}"
351
+ name
352
+ end
353
+
354
+ def next_output
355
+ name = _prep_next_output(api.args)
356
+ @_outdir ||= "."
357
+ unless @output.nil?
358
+ @output.puts "<meta charset='UTF-8'>\n\n"
359
+ @output.puts @parent.body
360
+ @parent.body = ""
361
+ @output.close unless @output == STDOUT
362
+ end
363
+ fname = @_outdir + "/" + name
364
+ @output = File.open(fname, "w")
365
+ api.optional_blank_line
366
+ end
367
+
368
+ def output
369
+ name = api.args.first
370
+ _debug "Redirecting output to: #{name}"
371
+ # _output(name)
372
+ @_outdir ||= "." # FIXME
373
+ @output.puts "<meta charset='UTF-8'>\n\n"
374
+ @output.puts @parent.body
375
+ @parent.body = ""
376
+ @output.close unless @output == STDOUT
377
+ fname = @_outdir + "/" + name #; STDERR.puts "--- _output: fname = #{fname.inspect}"
378
+ @output = File.open(fname, "w") #; STDERR.puts "---- @out = #{@output.inspect}"
379
+ end
380
+
381
+ def columns
382
+ api.out "<table border=1><tr><td valign=top><br>\n"
383
+ api.body.to_a.each do |line|
384
+ if line.start_with?("##col")
385
+ api.out "</td><td valign=top>"
386
+ elsif line.start_with?("##row")
387
+ api.out "</td></tr><tr><td valign=top>"
388
+ else
389
+ api.out line
390
+ end
391
+ end
392
+ api.out "<br>\n</td></tr></table>"
393
+ end
394
+
395
+ def quote
396
+ api.out "<blockquote>"
397
+ lines = api.body.to_a
398
+ # STDERR.puts "-----------------------------------------------------"
399
+ # STDERR.puts lines.inspect
400
+ lines.each {|line| api.out line }
401
+ api.out "</blockquote>"
402
+ end
data/plugin/pyggish.rb CHANGED
@@ -82,14 +82,26 @@ def self.pyg_finalize(code, lexer=:elixir)
82
82
  result
83
83
  end
84
84
 
85
- def fragment
85
+ def fragment(args = nil, body = nil)
86
86
  lang = api.args.empty? ? :elixir : api.args.first.to_sym # ruby or elixir
87
87
  api.args = []
88
- # TTY.puts "\n#{self.inspect}"
89
- send(lang)
88
+ lines = api.body(true) # .to_a # raw
89
+ result = send(lang, lines)
90
+ api.out result
90
91
  api.out "\n"
92
+ api.optional_blank_line
93
+ rescue => err
94
+ STDERR.puts "fragment Error: #{__method__} err = #{err}\n#{err.backtrace.join("\n")}"
91
95
  end
92
96
 
97
+ def dammit(args = nil, body = nil)
98
+ lines = api.body(true)
99
+ api.out "BODY:"
100
+ lines.each {|x| api.out x }
101
+ api.out "END BODY"
102
+ api.optional_blank_line
103
+ end
104
+
93
105
  def code # FIXME ?
94
106
  text = ""
95
107
  api.body {|line| api.out " " + line }
@@ -145,8 +157,9 @@ def self.pyg_finalize(code, lexer=:elixir)
145
157
  text
146
158
  end
147
159
 
148
- def ruby
160
+ def xruby
149
161
  file = api.args.first
162
+ code = nil
150
163
  if file.nil?
151
164
  code = " # Ruby code\n\n"
152
165
  api.body {|line| code << " " + line + "\n" }
@@ -158,15 +171,76 @@ def self.pyg_finalize(code, lexer=:elixir)
158
171
  api.out html
159
172
  end
160
173
 
161
- def elixir
174
+ def xelixir
162
175
  file = api.args.first
176
+ code = nil
163
177
  if file.nil?
164
178
  code = ""
165
179
  api.body {|line| code << " " + line + "\n" }
166
180
  else
167
181
  code = ::File.read(file)
168
182
  end
169
-
170
183
  html = format_elixir(code)
171
184
  api.out html
185
+ end
186
+
187
+ def ruby(lines)
188
+ theme = :Github # default
189
+ source = lines.join("\n")
190
+ formatter = Rouge::Formatters::HTML.new
191
+ lexer = Rouge::Lexers::Ruby.new
192
+ body = formatter.format(lexer.lex(source))
193
+
194
+ # css = Rouge::Themes.const_get(theme.to_s).render(scope: '.highlight')
195
+ # added = ".highlight { font-family: courier; white-space: pre }"
196
+
197
+ result = <<~HTML
198
+ <div class="highlight">
199
+ #{body}
200
+ </div>
201
+ <br>
202
+ HTML
203
+ return result
204
+
205
+ iheight = lines.size * 25
206
+ api.out <<~HTML
207
+ <center>
208
+ <iframe width=90% height=#{iheight} src='#{File.basename(html_file)}'></iframe>
209
+ </center>
210
+ <br>
211
+ HTML
212
+ rescue => err
213
+ STDERR.puts "Error: #{__method__} err = #{err}\n#{err.backtrace.join("\n")}"
172
214
  end
215
+
216
+
217
+ def elixir(lines)
218
+ theme = :Github # default
219
+ source = lines.join("\n")
220
+ formatter = Rouge::Formatters::HTML.new
221
+ lexer = Rouge::Lexers::Elixir.new
222
+ body = formatter.format(lexer.lex(source))
223
+
224
+ # css = Rouge::Themes.const_get(theme.to_s).render(scope: '.highlight')
225
+ # added = ".highlight { font-family: courier; white-space: pre }"
226
+
227
+ result = <<~HTML
228
+ <div class="highlight">
229
+ #{body}
230
+ </div>
231
+ <br>
232
+ HTML
233
+ return result
234
+
235
+ iheight = lines.size * 25
236
+ api.out <<~HTML
237
+ <center>
238
+ <iframe width=90% height=#{iheight} src='#{File.basename(html_file)}'></iframe>
239
+ </center>
240
+ <br>
241
+ HTML
242
+ rescue => err
243
+ STDERR.puts "Error: #{__method__} err = #{err}\n#{err.backtrace}"
244
+ end
245
+
246
+
data/test/unit/html.rb CHANGED
@@ -9,29 +9,27 @@ class TestingLivetext < MiniTest::Test
9
9
  # Same is probably true of the methods that are testing them.
10
10
 
11
11
  def test_wrapped
12
- cdata = "nothing much"
13
- assert_equal wrapped(cdata, :b), "<b>#{cdata}</b>"
14
- assert_equal wrapped(cdata, :b, :i), "<b><i>#{cdata}</i></b>"
15
-
16
- assert_equal wrapped(cdata, :table, :tr, :td),
17
- "<table><tr><td>#{cdata}</td></tr></table>"
12
+ live = Livetext.new
13
+ html = HTML.new(live.api)
14
+ str = "nothing much"
15
+ assert_equal html.tag(:b, cdata: str), "<b>#{str}</b>"
16
+ assert_equal html.tag(:b, :i, cdata: str), "<b><i>#{str}</i></b>"
17
+
18
+ assert_equal html.tag(:table, :tr, :td, cdata: str),
19
+ "<table><tr><td>#{str}</td></tr></table>"
18
20
  end
19
21
 
20
- def test_wrapped_bang
21
- cdata = "nothing much"
22
- assert_equal wrapped!(cdata, :td, valign: :top),
23
- "<td valign='top'>#{cdata}</td>"
24
- assert_equal wrapped!(cdata, :img, src: "foo.jpg"),
25
- "<img src='foo.jpg'>#{cdata}</img>"
26
- assert_equal wrapped!(cdata, :a, style: 'text-decoration: none',
22
+ def test_wrapped_extra
23
+ live = Livetext.new
24
+ html = HTML.new(live.api)
25
+ str = "nothing much"
26
+ assert_equal html.tag(:td, cdata: str, valign: :top),
27
+ "<td valign='top'>#{str}</td>"
28
+ assert_equal html.tag(:img, cdata: str, src: "foo.jpg"),
29
+ "<img src='foo.jpg'>#{str}</img>"
30
+ assert_equal html.tag(:a, cdata: str, style: 'text-decoration: none',
27
31
  href: 'foo.com'),
28
- "<a style='text-decoration: none' href='foo.com'>#{cdata}</a>"
29
- end
30
-
31
- def xtest_wrap
32
- # bogus!
33
- wrap(:ul) { 2.times {|i| _out i } }
34
- dump # puts @body
32
+ "<a style='text-decoration: none' href='foo.com'>#{str}</a>"
35
33
  end
36
34
 
37
35
  end
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.33
4
+ version: 0.9.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-22 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com