def hardbreaks(args = nil, body = nil) @hard = false @hard = true unless @_args.first == "off" end def hardbreaks? @hard end def credit(args = nil, body = nil) # really just a place marker in source end # These are duplicated. Remove safely def h1; _out "

#{@_data}

"; end def h2; _out "

#{@_data}

"; end def h3; _out "

#{@_data}

"; end def alpha_columns(args = nil, body = nil) 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 "" end _out "
" + items.join("") + "
" 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 # FIXME duplicated? def image(args = nil, body = nil) name = @_args[0] _out "" end def figure(args = nil, body = nil) name = @_args[0] num = @_args[1] title = @_args[2..-1].join(" ") title = _format(title) _out "" _out "
Figure #{num} #{title}
" end def chapter(args = nil, body = nil) # _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(args = nil, body = nil) @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(args = nil, body = nil) @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(args = nil, body = nil) @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(args = nil, body = nil) 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 " " end _out "" end _out "
#{cell}


" _optional_blank_line end def table2(args = nil, body = nil) 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 " " end _out "" end _out "
#{cell}


" _optional_blank_line end def simple_table(args = nil, body = nil) 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 " " end _out "" end _out "
" + "#{cell}
" end def table(args = nil, body = nil) @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 " " end _out "" end _out "
" + "#{cell}
" @toc << "#{_nbsp(8)}Table #@chapter.#@table_num #{title}
" # _next_output(_slug("table_#{title}")) _out "Table #@chapter.#@table_num    #{title}

" end def toc!(args = nil, body = nil) _debug "Closing TOC" @toc.close rescue => err puts @parent.body @parent.body = "" _errout "Exception: #{err.inspect}" end def toc2(args = nil, body = nil) file = @_args[0] @toc.close ::File.write(file, <<-EOS)

Fake (non-hyperlinked) Table of Contents

EOS system("cat toc.tmp >>#{file}") end def missing(args = nil, body = nil) @toc << "#{_nbsp(8)}TBD: #@_data
" stuff = @_data.empty? ? "" : ": #@_data" _out "
[Material missing#{stuff}]
\n " end def TBC(args = nil, body = nil) @toc << "#{_nbsp(8)}To be continued...
" _out "
To be continued...
" end def note(args = nil, body = nil) _out "
Note: " _out @_data _out "
\n " end def quote(args = nil, body = nil) _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