plugin/bookish.rb in livetext-0.8.76 vs plugin/bookish.rb in livetext-0.8.77
- old
+ new
@@ -9,47 +9,47 @@
def credit
# really just a place marker in source
end
-def h1; _puts "<h1>#{@_data}</h1>"; end
-def h3; _puts "<h3>#{@_data}</h3>"; end
+def h1; _out "<h1>#{@_data}</h1>"; end
+def h3; _out "<h3>#{@_data}</h3>"; end
def list
- _puts "<ul>"
- _body {|line| _puts "<li>#{line}</li>" }
- _puts "</ul>"
+ _out "<ul>"
+ _body {|line| _out "<li>#{line}</li>" }
+ _out "</ul>"
end
def list!
- _puts "<ul>"
- lines = _body.each # {|line| _puts "<li>#{line}</li>" }
+ _out "<ul>"
+ lines = _body.each # {|line| _out "<li>#{line}</li>" }
loop do
line = lines.next
line = _formatting(line)
if line[0] == " "
- _puts line
+ _out line
else
- _puts "<li>#{line}</li>"
+ _out "<li>#{line}</li>"
end
end
- _puts "</ul>"
+ _out "</ul>"
end
def alpha_columns
n = @_args.first.to_i # FIXME: what if missing?
words = []
_body do |line|
words << line.chomp
end
words.sort!
- _puts "<table cellpadding=10>"
+ _out "<table cellpadding=10>"
words.each_slice(n) do |w|
items = w.map {|x| "<tt>#{x}</tt>" }
- _puts "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
+ _out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
end
- _puts "</table>"
+ _out "</table>"
end
def comment
_body { } # ignore body
end
@@ -68,31 +68,31 @@
s2
end
def image
name = @_args[0]
- _puts "<img src='#{name}'></img>"
+ _out "<img src='#{name}'></img>"
end
def figure
name = @_args[0]
num = @_args[1]
title = @_args[2..-1].join(" ")
title = _formatting(title)
- _puts "<img src='#{name}'></img>"
- _puts "<center><b>Figure #{num}</b> #{title}</center>"
+ _out "<img src='#{name}'></img>"
+ _out "<center><b>Figure #{num}</b> #{title}</center>"
end
def chapter
# _errout("chapter")
@chapter = @_args.first.to_i
@sec = @sec2 = 0
title = @_data.split(" ",2)[1]
@toc << "<br><b>#@chapter</b> #{title}<br>"
_next_output(_slug(title))
- _puts "<title>#{@chapter}. #{title}</title>"
- _puts <<-HTML
+ _out "<title>#{@chapter}. #{title}</title>"
+ _out <<-HTML
<h2>Chapter #{@chapter}</h1>
<h1>#{title}</h1>
HTML
end
@@ -102,12 +102,12 @@
@sec = @sec2 = 0
title = @_data # .split(" ",2)[1]
_errout("Chapter #@chapter: #{title}")
@toc << "<br><b>#@chapter</b> #{title}<br>"
_next_output(_slug(title))
- _puts "<title>#{@chapter}. #{title}</title>"
- _puts <<-HTML
+ _out "<title>#{@chapter}. #{title}</title>"
+ _out <<-HTML
<h2>Chapter #{@chapter}</h1>
<h1>#{title}</h1>
HTML
end
@@ -117,50 +117,50 @@
@sec2 = 0
@section = "#@chapter.#@sec"
# _errout("section #@section")
@toc << "#{_nbsp(3)}<b>#@section</b> #@_data<br>"
# _next_output(_slug(@_data))
- _puts "<h3>#@section #{@_data}</h3>\n"
+ _out "<h3>#@section #{@_data}</h3>\n"
end
def subsec
@sec2 += 1
@subsec = "#@chapter.#@sec.#@sec2"
@toc << "#{_nbsp(6)}<b>#@subsec</b> #@_data<br>"
# _errout("section #@subsec")
# _next_output(_slug(@_data))
- _puts "<h3>#@subsec #{@_data}</h3>\n"
+ _out "<h3>#@subsec #{@_data}</h3>\n"
end
def table2
title = @_data
wide = "90"
extra = _args[2]
delim = " :: "
- _puts "<br><center><table border=1 width=#{wide}% cellpadding=5>"
+ _out "<br><center><table border=1 width=#{wide}% cellpadding=5>"
lines = _body(true)
lines.map! {|line| _formatting(line) }
lines.each do |line|
cells = line.split(delim)
percent = (100/cells.size.to_f).round
- _puts "<tr>"
+ _out "<tr>"
cells.each do |cell|
- _puts " <td width=#{percent}% valign=top " +
+ _out " <td width=#{percent}% valign=top " +
"#{extra}>#{cell}</td>"
end
- _puts "</tr>"
+ _out "</tr>"
end
- _puts "</table></center><br><br>"
+ _out "</table></center><br><br>"
_optional_blank_line
end
def simple_table
title = @_data
delim = " :: "
- _puts "<table cellpadding=2>"
+ _out "<table cellpadding=2>"
lines = _body(true)
maxw = nil
lines.each do |line|
_formatting(line)
cells = line.split(delim)
@@ -172,26 +172,26 @@
sum = maxw.inject(0, :+)
maxw.map! {|x| (x/sum*100).floor }
lines.each do |line|
cells = line.split(delim)
- _puts "<tr>"
+ _out "<tr>"
cells.each.with_index do |cell, i|
- _puts " <td width=#{maxw}% valign=top>" +
+ _out " <td width=#{maxw}% valign=top>" +
"#{cell}</td>"
end
- _puts "</tr>"
+ _out "</tr>"
end
- _puts "</table>"
+ _out "</table>"
end
def table
@table_num ||= 0
@table_num += 1
title = @_data
delim = " :: "
- _puts "<br><center><table border=1 width=90% cellpadding=5>"
+ _out "<br><center><table border=1 width=90% cellpadding=5>"
lines = _body(true)
maxw = nil
lines.each do |line|
_formatting(line)
cells = line.split(delim)
@@ -203,27 +203,28 @@
sum = maxw.inject(0, :+)
maxw.map! {|x| (x/sum*100).floor }
lines.each do |line|
cells = line.split(delim)
- _puts "<tr>"
+ _out "<tr>"
cells.each.with_index do |cell, i|
- _puts " <td width=#{maxw}% valign=top>" +
+ _out " <td width=#{maxw}% valign=top>" +
"#{cell}</td>"
end
- _puts "</tr>"
+ _out "</tr>"
end
- _puts "</table>"
+ _out "</table>"
@toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
# _next_output(_slug("table_#{title}"))
- _puts "<b>Table #@chapter.#@table_num #{title}</b></center><br>"
+ _out "<b>Table #@chapter.#@table_num #{title}</b></center><br>"
end
def toc!
_debug "Closing TOC"
@toc.close
rescue => err
+ puts @body
_errout "Exception: #{err.inspect}"
end
def toc2
file = @_args[0]
@@ -240,27 +241,27 @@
def missing
@toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
_print "<br><font color=red><i>[Material missing"
_print ": #@_data" unless @_data.empty?
- _puts "]</i></font><br>\n "
+ _out "]</i></font><br>\n "
end
def TBC
@toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
_print "<br><font color=red><i>To be continued...</i></font><br>"
end
def note
- _puts "<br><font color=red><i>Note: "
- _puts @_data
- _puts "</i></font><br>\n "
+ _out "<br><font color=red><i>Note: "
+ _out @_data
+ _out "</i></font><br>\n "
end
def quote
- _puts "<blockquote>"
- _puts _body
- _puts "</blockquote>"
+ _out "<blockquote>"
+ _out _body
+ _out "</blockquote>"
end
def init_bookish
@toc_file = "toc.tmp"
@toc = ::File.new(@toc_file, "w")