]
headline(level, label, caption)
end
def xcolumn_end(level)
puts '
'
end
def ref_begin(level, label, caption)
print %Q[]
headline(level, label, caption)
end
def ref_end(level)
puts '
'
end
def sup_begin(level, label, caption)
print %Q[]
headline(level, label, caption)
end
def sup_end(level)
puts '
'
end
def tsize(str)
# null
end
def captionblock(type, lines, caption)
puts %Q[" ## it's OK in HTML5, but not OK in XHTML1.1
@ol_num = nil
else
puts ''
end
end
def ol_item(lines, num)
puts "- #{lines.join}
"
end
def ol_end
puts '
'
end
def dl_begin
puts ''
end
def dt(line)
puts "- #{line}
"
end
def dd(lines)
puts "- #{lines.join}
"
end
def dl_end
puts '
'
end
def paragraph(lines)
if @noindent.nil?
puts "#{lines.join}
"
else
puts %Q[#{lines.join}
]
@noindent = nil
end
end
def parasep()
puts '
'
end
def read(lines)
if ReVIEW.book.param["deprecated-blocklines"].nil?
blocked_lines = split_paragraph(lines)
puts %Q[\n#{blocked_lines.join("\n")}\n
]
else
puts %Q[\n#{lines.join("\n")}\n
]
end
end
alias :lead read
def list(lines, id, caption)
puts %Q[]
begin
list_header id, caption
rescue KeyError
error "no such list: #{id}"
end
list_body id, lines
puts '
'
end
def list_header(id, caption)
if get_chap.nil?
puts %Q[#{I18n.t("list")}#{I18n.t("format_number_header_without_chapter", [@chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}
]
else
puts %Q[#{I18n.t("list")}#{I18n.t("format_number_header", [get_chap, @chapter.list(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}
]
end
end
def list_body(id, lines)
id ||= ''
print %Q[]
body = lines.inject(''){|i, j| i + detab(j) + "\n"}
lexer = File.extname(id).gsub(/\./, '')
puts highlight(:body => body, :lexer => lexer, :format => 'html')
puts '
'
end
def source(lines, caption = nil)
puts %Q[]
source_header caption
source_body caption, lines
puts '
'
end
def source_header(caption)
if caption.present?
puts %Q[#{compile_inline(caption)}
]
end
end
def source_body(id, lines)
id ||= ''
print %Q[]
body = lines.inject(''){|i, j| i + detab(j) + "\n"}
lexer = File.extname(id).gsub(/\./, '')
puts highlight(:body => body, :lexer => lexer, :format => 'html')
puts '
'
end
def listnum(lines, id, caption)
puts %Q[]
begin
list_header id, caption
rescue KeyError
error "no such list: #{id}"
end
listnum_body lines
puts '
'
end
def listnum_body(lines)
print %Q[]
lines.each_with_index do |line, i|
puts detab((i+1).to_s.rjust(2) + ": " + line)
end
puts '
'
end
def emlist(lines, caption = nil)
puts %Q[]
puts %Q(
#{caption}
) unless caption.nil?
print %Q[
]
lines.each do |line|
puts detab(line)
end
puts '
'
puts '
'
end
def emlistnum(lines, caption = nil)
puts %Q[]
puts %Q(
#{caption}
) unless caption.nil?
print %Q[
]
lines.each_with_index do |line, i|
puts detab((i+1).to_s.rjust(2) + ": " + line)
end
puts '
'
puts '
'
end
def cmd(lines, caption = nil)
puts %Q[]
puts %Q(
#{caption}
) unless caption.nil?
print %Q[
]
lines.each do |line|
puts detab(line)
end
puts '
'
puts '
'
end
def quotedlist(lines, css_class)
print %Q[]
lines.each do |line|
puts detab(line)
end
puts '
'
end
private :quotedlist
def quote(lines)
if ReVIEW.book.param["deprecated-blocklines"].nil?
blocked_lines = split_paragraph(lines)
puts "#{blocked_lines.join("\n")}
"
else
puts "#{lines.join("\n")}
"
end
end
def doorquote(lines, ref)
if ReVIEW.book.param["deprecated-blocklines"].nil?
blocked_lines = split_paragraph(lines)
puts %Q[]
puts "#{blocked_lines.join("\n")}"
puts %Q[#{ref}より
]
puts %Q[
]
else
puts <<-QUOTE
#{lines.join("\n")}
#{ref}より
QUOTE
end
end
def talk(lines)
puts %Q[]
if ReVIEW.book.param["deprecated-blocklines"].nil?
blocked_lines = split_paragraph(lines)
puts "#{blocked_lines.join("\n")}"
else
print '
'
puts "#{lines.join("\n")}"
puts '
'
end
puts '
'
end
def texequation(lines)
puts %Q[]
if ReVIEW.book.param["mathml"]
p = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference)
puts p.parse(unescape_html(lines.join("\n")), true)
else
print '
'
puts "#{lines.join("\n")}"
puts '
'
end
puts '
'
end
def handle_metric(str)
if str =~ /\Ascale=([\d.]+)\Z/
return "width=\"#{($1.to_f * 100).round}%\""
else
k, v = str.split('=', 2)
return %Q|#{k}=\"#{v.sub(/\A["']/, '').sub(/["']\Z/, '')}\"|
end
end
def result_metric(array)
" #{array.join(' ')}"
end
def image_image(id, caption, metric)
metrics = parse_metric("html", metric)
puts %Q[]
puts %Q[
]
image_header id, caption
puts %Q[
]
end
def image_dummy(id, caption, lines)
puts %Q[]
puts %Q[
]
lines.each do |line|
puts detab(line)
end
puts %Q[
]
image_header id, caption
puts %Q[
]
end
def image_header(id, caption)
puts %Q[]
if get_chap.nil?
puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header_without_chapter", [@chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
else
puts %Q[#{I18n.t("image")}#{I18n.t("format_number_header", [get_chap, @chapter.image(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
end
puts %Q[
]
end
def table(lines, id = nil, caption = nil)
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\-]{12}/ =~ line
# just ignore
#error "too many table separator" if sepidx
sepidx ||= idx
next
end
rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
end
rows = adjust_n_cols(rows)
puts %Q[]
begin
table_header id, caption unless caption.nil?
rescue KeyError
error "no such table: #{id}"
end
table_begin rows.first.size
return if rows.empty?
if sepidx
sepidx.times do
tr rows.shift.map {|s| th(s) }
end
rows.each do |cols|
tr cols.map {|s| td(s) }
end
else
rows.each do |cols|
h, *cs = *cols
tr [th(h)] + cs.map {|s| td(s) }
end
end
table_end
puts %Q[
]
end
def table_header(id, caption)
if get_chap.nil?
puts %Q[#{I18n.t("table")}#{I18n.t("format_number_header_without_chapter", [@chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}
]
else
puts %Q[#{I18n.t("table")}#{I18n.t("format_number_header", [get_chap, @chapter.table(id).number])}#{I18n.t("caption_prefix")}#{compile_inline(caption)}
]
end
end
def table_begin(ncols)
puts ''
end
def tr(rows)
puts "#{rows.join}
"
end
def th(str)
"#{str} | "
end
def td(str)
"#{str} | "
end
def table_end
puts '
'
end
def comment(lines, comment = nil)
lines ||= []
lines.unshift comment unless comment.blank?
if ReVIEW.book.param["draft"]
str = lines.map{|line| escape_html(line) }.join("
")
puts %Q()
else
str = lines.join("\n")
puts %Q()
end
end
def footnote(id, str)
if ReVIEW.book.param["epubversion"].to_i == 3
puts %Q()
else
puts %Q()
end
end
def indepimage(id, caption="", metric=nil)
metrics = parse_metric("html", metric)
caption = "" if caption.nil?
puts %Q[]
begin
puts %Q[
]
rescue
puts %Q[
missing image: #{id}
]
end
unless caption.empty?
puts %Q[
]
puts %Q[#{I18n.t("numberless_image")}#{I18n.t("caption_prefix")}#{compile_inline(caption)}]
puts %Q[
]
end
puts %Q[
]
end
alias :numberlessimage indepimage
def hr
puts "
"
end
def label(id)
puts %Q()
end
def linebreak
puts "
"
end
def pagebreak
puts %Q(
)
end
def bpo(lines)
puts ""
lines.each do |line|
puts detab(line)
end
puts ""
end
def noindent
@noindent = true
end
def inline_labelref(idref)
%Q[「●● #{escape_html(idref)}」]
end
alias inline_ref inline_labelref
def inline_chapref(id)
title = super
if ReVIEW.book.param["chapterlink"]
%Q(#{title})
else
title
end
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_chap(id)
if ReVIEW.book.param["chapterlink"]
%Q(#{@chapter.env.chapter_index.number(id)})
else
@chapter.env.chapter_index.number(id)
end
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_title(id)
if ReVIEW.book.param["chapterlink"]
%Q(#{compile_inline(@chapter.env.chapter_index.title(id))})
else
@chapter.env.chapter_index.title(id)
end
rescue KeyError
error "unknown chapter: #{id}"
nofunc_text("[UnknownChapter:#{id}]")
end
def inline_fn(id)
if ReVIEW.book.param["epubversion"].to_i == 3
%Q(*#{@chapter.footnote(id).number})
else
%Q(*#{@chapter.footnote(id).number})
end
end
def compile_ruby(base, ruby)
if ReVIEW.book.param["htmlversion"].to_i == 5
%Q[#{escape_html(base)}]
else
%Q[#{escape_html(base)}]
end
end
def compile_kw(word, alt)
%Q[] +
if alt
then escape_html(word + " (#{alt.strip})")
else escape_html(word)
end +
""
end
def inline_i(str)
%Q(#{escape_html(str)})
end
def inline_b(str)
%Q(#{escape_html(str)})
end
def inline_ami(str)
%Q(#{escape_html(str)})
end
def inline_bou(str)
%Q(#{escape_html(str)})
end
def inline_tti(str)
if ReVIEW.book.param["htmlversion"].to_i == 5
%Q(#{escape_html(str)}
)
else
%Q(#{escape_html(str)})
end
end
def inline_ttb(str)
if ReVIEW.book.param["htmlversion"].to_i == 5
%Q(#{escape_html(str)}
)
else
%Q(#{escape_html(str)})
end
end
def inline_dtp(str)
""
end
def inline_code(str)
if ReVIEW.book.param["htmlversion"].to_i == 5
%Q(#{escape_html(str)}
)
else
%Q(#{escape_html(str)})
end
end
def inline_idx(str)
%Q(#{escape_html(str)})
end
def inline_hidx(str)
%Q()
end
def inline_br(str)
%Q(
)
end
def inline_m(str)
if ReVIEW.book.param["mathml"]
p = MathML::LaTeX::Parser.new(:symbol=>MathML::Symbol::CharacterReference)
%Q[#{p.parse(str, nil)}]
else
%Q[#{escape_html(str)}]
end
end
def text(str)
str
end
def bibpaper(lines, id, caption)
puts %Q[]
bibpaper_header id, caption
unless lines.empty?
bibpaper_bibpaper id, caption, lines
end
puts "
"
end
def bibpaper_header(id, caption)
print %Q()
print "[#{@chapter.bibpaper(id).number}]"
print %Q()
puts " #{compile_inline(caption)}"
end
def bibpaper_bibpaper(id, caption, lines)
print split_paragraph(lines).join("")
end
def inline_bib(id)
%Q([#{@chapter.bibpaper(id).number}])
end
def inline_hd_chap(chap, id)
n = chap.headline_index.number(id)
if chap.number and ReVIEW.book.param["secnolevel"] >= n.split('.').size
str = "「#{n} #{compile_inline(chap.headline(id).caption)}」"
else
str = "「#{compile_inline(chap.headline(id).caption)}」"
end
if ReVIEW.book.param["chapterlink"]
anchor = "h"+n.gsub(/\./, "-")
%Q(#{str})
else
str
end
end
def inline_list(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
"#{I18n.t("list")}#{I18n.t("format_number_without_header", [chapter.list(id).number])}"
else
"#{I18n.t("list")}#{I18n.t("format_number", [get_chap(chapter), chapter.list(id).number])}"
end
rescue KeyError
error "unknown list: #{id}"
nofunc_text("[UnknownList:#{id}]")
end
def inline_table(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
"#{I18n.t("table")}#{I18n.t("format_number_without_chapter", [chapter.table(id).number])}"
else
"#{I18n.t("table")}#{I18n.t("format_number", [get_chap(chapter), chapter.table(id).number])}"
end
rescue KeyError
error "unknown table: #{id}"
nofunc_text("[UnknownTable:#{id}]")
end
def inline_img(id)
chapter, id = extract_chapter_id(id)
if get_chap(chapter).nil?
"#{I18n.t("image")}#{I18n.t("format_number_without_chapter", [chapter.image(id).number])}"
else
"#{I18n.t("image")}#{I18n.t("format_number", [get_chap(chapter), chapter.image(id).number])}"
end
rescue KeyError
error "unknown image: #{id}"
nofunc_text("[UnknownImage:#{id}]")
end
def inline_asis(str, tag)
%Q(<#{tag}>#{escape_html(str)}#{tag}>)
end
def inline_abbr(str)
inline_asis(str, "abbr")
end
def inline_acronym(str)
inline_asis(str, "acronym")
end
def inline_cite(str)
inline_asis(str, "cite")
end
def inline_dfn(str)
inline_asis(str, "dfn")
end
def inline_em(str)
inline_asis(str, "em")
end
def inline_kbd(str)
inline_asis(str, "kbd")
end
def inline_samp(str)
inline_asis(str, "samp")
end
def inline_strong(str)
inline_asis(str, "strong")
end
def inline_var(str)
inline_asis(str, "var")
end
def inline_big(str)
inline_asis(str, "big")
end
def inline_small(str)
inline_asis(str, "small")
end
def inline_sub(str)
inline_asis(str, "sub")
end
def inline_sup(str)
inline_asis(str, "sup")
end
def inline_tt(str)
if ReVIEW.book.param["htmlversion"].to_i == 5
%Q(#{escape_html(str)}
)
else
%Q(#{escape_html(str)})
end
end
def inline_del(str)
inline_asis(str, "del")
end
def inline_ins(str)
inline_asis(str, "ins")
end
def inline_u(str)
%Q(#{escape_html(str)})
end
def inline_recipe(str)
%Q(「#{escape_html(str)}」)
end
def inline_icon(id)
begin
%Q[]
rescue
%Q[missing image: #{id}
]
end
end
def inline_uchar(str)
%Q(#{str};)
end
def inline_comment(str)
if ReVIEW.book.param["draft"]
%Q()
else
%Q()
end
end
def inline_raw(str)
super(str)
end
def nofunc_text(str)
escape_html(str)
end
def compile_href(url, label)
%Q(#{label.nil? ? escape_html(url) : escape_html(label)})
end
def flushright(lines)
if ReVIEW.book.param["deprecated-blocklines"].nil?
puts split_paragraph(lines).join("\n").gsub("", "
")
else
puts %Q[
]
print %Q[
]
lines.each {|line| puts detab(line) }
puts '
'
puts '
'
end
end
def centering(lines)
puts split_paragraph(lines).join("\n").gsub("", "
")
end
def image_ext
"png"
end
def olnum(num)
@ol_num = num.to_i
end
end
end # module ReVIEW