blank()
click to toggle source
def blank
@output.puts unless @blank_seen
@blank_seen = true
end
cmd(lines)
click to toggle source
def cmd(lines)
puts '```shell-session'
lines.each { |line| puts detab(line) }
puts '```'
end
compile_href(url, label)
click to toggle source
def compile_href(url, label)
label = url if label.blank?
"[#{label}](#{url})"
end
compile_ruby(base, ruby)
click to toggle source
def compile_ruby(base, ruby)
if @book.htmlversion == 5
%Q(<ruby>#{escape_html(base)}<rp>#{I18n.t('ruby_prefix')}</rp><rt>#{escape_html(ruby)}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
else
%Q(<ruby><rb>#{escape_html(base)}</rb><rp>#{I18n.t('ruby_prefix')}</rp><rt>#{ruby}</rt><rp>#{I18n.t('ruby_postfix')}</rp></ruby>)
end
end
dd(lines)
click to toggle source
def dd(lines)
puts "<dd>#{lines.join}</dd>"
end
dl_begin()
click to toggle source
def dl_begin
puts '<dl>'
end
dl_end()
click to toggle source
def dl_end
puts '</dl>'
end
dt(line)
click to toggle source
def dt(line)
puts "<dt>#{line}</dt>"
end
emlist(lines, caption = nil, lang = nil)
click to toggle source
def emlist(lines, caption = nil, lang = nil)
blank
if caption
puts caption
print "\n"
end
lang ||= ''
puts "```#{lang}"
lines.each do |line|
puts detab(line)
end
puts '```'
blank
end
extname()
click to toggle source
headline(level, _label, caption)
click to toggle source
def headline(level, _label, caption)
blank
prefix = '#' * level
puts "#{prefix} #{caption}"
blank
end
hr()
click to toggle source
image_dummy(_id, _caption, lines)
click to toggle source
def image_dummy(_id, _caption, lines)
puts lines.join
end
image_ext()
click to toggle source
image_image(id, caption, _metric)
click to toggle source
def image_image(id, caption, _metric)
blank
puts ".path.sub(%r{\A\./}, '')})"
blank
end
indepimage(_lines, id, caption = '', _metric = nil)
click to toggle source
def indepimage(_lines, id, caption = '', _metric = nil)
blank
puts ".path.sub(%r{\A\./}, '')})"
blank
end
inline_b(str)
click to toggle source
def inline_b(str)
"**#{str.gsub(/\*/, '\*')}**"
end
inline_br(_str)
click to toggle source
def inline_br(_str)
"\n"
end
inline_code(str)
click to toggle source
def inline_code(str)
"`#{str}`"
end
inline_em(str)
click to toggle source
def inline_em(str)
"*#{str.gsub(/\*/, '\*')}*"
end
inline_fn(id)
click to toggle source
def inline_fn(id)
"[^#{id}]"
end
inline_i(str)
click to toggle source
def inline_i(str)
"*#{str.gsub(/\*/, '\*')}*"
end
inline_img(id)
click to toggle source
def inline_img(id)
"#{I18n.t('image')}#{@chapter.image(id).number}"
rescue KeyError
error "unknown image: #{id}"
nofunc_text("[UnknownImage:#{id}]")
end
inline_strong(str)
click to toggle source
def inline_strong(str)
"**#{str.gsub(/\*/, '\*')}**"
end
inline_tt(str)
click to toggle source
def inline_tt(str)
"`#{str}`"
end
list_body(_id, lines, _lang)
click to toggle source
def list_body(_id, lines, _lang)
lines.each do |line|
puts detab(line)
end
puts '```'
end
nofunc_text(str)
click to toggle source
def nofunc_text(str)
str
end
ol_begin()
click to toggle source
ol_end()
click to toggle source
ol_item(lines, num)
click to toggle source
def ol_item(lines, num)
puts "#{num}. #{lines.join}"
end
pagebreak()
click to toggle source
def pagebreak
puts '{pagebreak}'
end
paragraph(lines)
click to toggle source
def paragraph(lines)
puts lines.join
puts "\n"
end
puts(str)
click to toggle source
Calls superclass method
def puts(str)
@blank_seen = false
super
end
quote(lines)
click to toggle source
def quote(lines)
blank
puts split_paragraph(lines).map { |line| "> #{line}" }.join("\n> \n")
blank
end
table(lines, id = nil, caption = nil)
click to toggle source
def table(lines, id = nil, caption = nil)
rows = []
sepidx = nil
lines.each_with_index do |line, idx|
if /\A[\=\-]{12}/ =~ line
sepidx ||= idx
next
end
rows.push(line.strip.split(/\t+/).map { |s| s.sub(/\A\./, '') })
end
rows = adjust_n_cols(rows)
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
table_border rows.first.size
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
end
table_begin(ncols)
click to toggle source
def table_begin(ncols)
end
table_border(ncols)
click to toggle source
def table_border(ncols)
puts((0..ncols).map { '|' }.join(':--'))
end
table_end()
click to toggle source
td(str)
click to toggle source
th(str)
click to toggle source
tr(rows)
click to toggle source
def tr(rows)
puts "|#{rows.join('|')}|"
end
ul_begin()
click to toggle source
def ul_begin
blank if @ul_indent == 0
@ul_indent += 1
end
ul_end()
click to toggle source
def ul_end
@ul_indent -= 1
blank if @ul_indent == 0
end
ul_item_begin(lines)
click to toggle source
def ul_item_begin(lines)
puts ' ' * (@ul_indent - 1) + '* ' + lines.join
end
ul_item_end()
click to toggle source