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 list _puts "" end def list! _puts "" end def alpha_columns n = @_args.first.to_i # FIXME: what if missing? words = [] _body do |line| words << line.chomp end words.sort! _puts "" words.each_slice(n) do |w| items = w.map {|x| "#{x}" } _puts "" end _puts "
" + 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 def image name = @_args[0] _puts "" end def figure name = @_args[0] num = @_args[1] title = @_args[2..-1].join(" ") title = _formatting(title) _puts "" _puts "
Figure #{num} #{title}
" end def chapter # _errout("chapter") @chapter = @_args.first.to_i @sec = @sec2 = 0 title = @_data.split(" ",2)[1] @toc << "
#@chapter #{title}
" _next_output(_slug(title)) _puts "#{@chapter}. #{title}" _puts <<-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}
" _next_output(_slug(title)) _puts "#{@chapter}. #{title}" _puts <<-HTML

Chapter #{@chapter}

#{title}

HTML end def sec @sec += 1 @sec2 = 0 @section = "#@chapter.#@sec" # _errout("section #@section") @toc << "#{_nbsp(3)}#@section #@_data
" _next_output(_slug(@_data)) _puts "

#@section #{@_data}

\n" end def subsec @sec2 += 1 @subsec = "#@chapter.#@sec.#@sec2" @toc << "#{_nbsp(6)}#@subsec #@_data
" # _errout("section #@subsec") _next_output(_slug(@_data)) _puts "

#@subsec #{@_data}

\n" end def table2 title = @_data wide = "90" extra = _args[2] delim = " :: " _puts "
" lines = _body lines.map! {|line| _formatting(line) } lines.each do |line| cells = line.split(delim) percent = (100/cells.size.to_f).round _puts "" cells.each {|cell| _puts " " } _puts "" end _puts "
#{cell}


" _optional_blank_line end def table @table_num ||= 0 @table_num += 1 title = @_data delim = " :: " _puts "
" lines = _body maxw = nil lines.each do |line| _formatting(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) _puts "" cells.each.with_index {|cell, i| ; _puts " " } _puts "" end _puts "
#{cell}
" @toc << "#{_nbsp(8)}Table #@chapter.#@table_num #{title}
" _next_output(_slug("table_#{title}")) _puts "Table #@chapter.#@table_num    #{title}

" end def toc! _debug "Closing TOC" @toc.close rescue => err _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
" _print "
[Material missing" _print ": #@_data" unless @_data.empty? _puts "]
\n " end def TBC @toc << "#{_nbsp(8)}To be continued...
" _print "
To be continued...
" end def note _puts "
Note: " _puts @_data _puts "
\n " end def quote _puts "
" _puts _body _puts "
" end def init_bookish @toc_file = "toc.tmp" @toc = ::File.new(@toc_file, "w") @chapter = -1 end