def hardbreaks
@hard = false
@hard = true unless @_args.first == "off"
end
def hardbreaks?
@hard
end
def credit
# really just a place marker in source
end
def h1; _out "
#{@_data}
"; end
def h2; _out "#{@_data}
"; end
def h3; _out "#{@_data}
"; end
def list
_out ""
_body {|line| _out "- #{line}
" }
_out "
"
end
def list!
_out ""
lines = _body.each # {|line| _out "- #{line}
" }
loop do
line = lines.next
line = _format(line)
if line[0] == " "
_out line
else
_out "- #{line}
"
end
end
_out "
"
end
def alpha_columns
n = @_args.first.to_i # FIXME: what if missing?
words = []
_body do |line|
words << line.chomp
end
words.sort!
_out ""
words.each_slice(n) do |w|
items = w.map {|x| "#{x}" }
_out " | " + items.join(" | ") + " |
"
end
_out "
"
end
def comment
_body { } # ignore body
end
def _errout(*args)
::STDERR.puts *args
end
def _nbsp(n)
" "*n
end
def _slug(str)
s2 = str.chomp.strip.gsub(/[?:,()'"\/]/,"").gsub(/ /, "-").downcase
# _errout "SLUG: #{str} => #{s2}"
s2
end
def image
name = @_args[0]
_out ""
end
def figure
name = @_args[0]
num = @_args[1]
title = @_args[2..-1].join(" ")
title = _format(title)
_out ""
_out "Figure #{num} #{title}"
end
def chapter
# _errout("chapter")
@chapter = @_args.first.to_i
@sec = @sec2 = 0
title = @_data.split(" ",2)[1]
@toc << "
#@chapter #{title}
"
@_data = _slug(title)
next_output
_out "#{@chapter}. #{title}"
_out <<-HTML
Chapter #{@chapter}
#{title}
HTML
end
def chapterN
@chapter += 1
@sec = @sec2 = 0
title = @_data # .split(" ",2)[1]
_errout("Chapter #@chapter: #{title}")
@toc << "
#@chapter #{title}
"
@_data = _slug(title)
next_output
_out "#{@chapter}. #{title}"
_out <<-HTML
Chapter #{@chapter}
#{title}
HTML
end
def sec
@sec += 1
@sec2 = 0
@section = "#@chapter.#@sec"
title = @_data.dup
@toc << "#{_nbsp(3)}#@section #{title}
"
@_data = _slug(@_data)
next_output
_out "#@section #{title}
\n"
rescue => err
STDERR.puts "#{err}\n#{err.backtrace}"
exit
end
def subsec
@sec2 += 1
@subsec = "#@chapter.#@sec.#@sec2"
title = @_data.dup
@toc << "#{_nbsp(6)}#@subsec #{title}
"
@_data = _slug(@_data)
next_output
_out "#@subsec #{title}
\n"
end
def definition_table
title = @_data
wide = "95"
delim = " :: "
_out "
"
lines = _body(true)
lines.map! {|line| _format(line) }
lines.each do |line|
cells = line.split(delim)
_out ""
cells.each.with_index do |cell, i|
width = (i == 0) ? "width=15%" : ""
_out " #{cell} | "
end
_out "
"
end
_out "
"
_optional_blank_line
end
def table2
title = @_data
wide = "90"
extra = _args[2]
delim = " :: "
_out "
"
lines = _body(true)
lines.map! {|line| _format(line) }
lines.each do |line|
cells = line.split(delim)
percent = (100/cells.size.to_f).round
_out ""
cells.each do |cell|
_out " #{cell} | "
end
_out "
"
end
_out "
"
_optional_blank_line
end
def simple_table
title = @_data
delim = " :: "
_out "
"
lines = _body(true)
maxw = nil
lines.each do |line|
_format(line)
cells = line.split(delim)
wide = cells.map {|x| x.length }
maxw = [0] * cells.size
maxw = maxw.map.with_index {|x, i| [x, wide[i]].max }
end
sum = maxw.inject(0, :+)
maxw.map! {|x| (x/sum*100).floor }
lines.each do |line|
cells = line.split(delim)
_out ""
cells.each.with_index do |cell, i|
_out " " +
"#{cell} | "
end
_out "
"
end
_out "
"
end
def table
@table_num ||= 0
@table_num += 1
title = @_data
delim = " :: "
_out "
"
lines = _body(true)
maxw = nil
lines.each do |line|
_format(line)
cells = line.split(delim)
wide = cells.map {|x| x.length }
maxw = [0] * cells.size
maxw = maxw.map.with_index {|x, i| [x, wide[i]+2].max }
end
sum = maxw.inject(0, :+)
maxw.map! {|x| (x/sum*100).floor }
lines.each do |line|
cells = line.split(delim)
_out ""
cells.each.with_index do |cell, i|
_out " " +
"#{cell} | "
end
_out "
"
end
_out "
"
@toc << "#{_nbsp(8)}Table #@chapter.#@table_num #{title}
"
# _next_output(_slug("table_#{title}"))
_out "Table #@chapter.#@table_num #{title}
"
end
def toc!
_debug "Closing TOC"
@toc.close
rescue => err
puts @parent.body
@parent.body = ""
_errout "Exception: #{err.inspect}"
end
def toc2
file = @_args[0]
@toc.close
::File.write(file, <<-EOS)
Fake (non-hyperlinked) Table of Contents
EOS
system("cat toc.tmp >>#{file}")
end
def missing
@toc << "#{_nbsp(8)}TBD: #@_data
"
stuff = @_data.empty? ? "" : ": #@_data"
_out "
[Material missing#{stuff}]
\n "
end
def TBC
@toc << "#{_nbsp(8)}To be continued...
"
_out "
To be continued...
"
end
def note
_out "
Note: "
_out @_data
_out "
\n "
end
def quote
_out ""
_body {|line| _out line }
_out "
"
rescue => err
STDERR.puts "#{err}\n#{err.backtrace}"
exit
end
def init_bookish
@toc_file = "toc.tmp"
@toc = ::File.new(@toc_file, "w")
@chapter = -1
end