class ReVIEW::MARKDOWNBuilder
Public Instance Methods
blank()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 30 def blank @output.puts unless @blank_seen @blank_seen = true end
cmd(lines)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 194 def cmd(lines) puts '```shell-session' lines.each { |line| puts detab(line) } puts '```' end
comment(lines, comment = nil)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 297 def comment(lines, comment = nil) return unless @book.config['draft'] lines ||= [] lines.unshift comment unless comment.blank? str = lines.join('<br />') puts %Q(<div class="red">#{escape_html(str)}</div>) end
compile_href(url, label)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 134 def compile_href(url, label) label = url if label.blank? "[#{label}](#{url})" end
compile_ruby(base, ruby)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 289 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
# File ../../../../../lib/review/markdownbuilder.rb, line 107 def dd(lines) puts "<dd>#{lines.join}</dd>" end
dl_begin()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 99 def dl_begin puts '<dl>' end
dl_end()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 111 def dl_end puts '</dl>' end
dt(line)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 103 def dt(line) puts "<dt>#{line}</dt>" end
emlist(lines, caption = nil, lang = nil)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 115 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
# File ../../../../../lib/review/markdownbuilder.rb, line 14 def extname '.md' end
footnote(id, str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 272 def footnote(id, str) puts "[^#{id}]: #{compile_inline(str)}" blank end
headline(level, _label, caption)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 35 def headline(level, _label, caption) blank prefix = '#' * level puts "#{prefix} #{caption}" blank end
hr()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 130 def hr puts '----' end
image_dummy(_id, _caption, lines)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 169 def image_dummy(_id, _caption, lines) puts lines.join end
image_ext()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 190 def image_ext 'jpg' end
image_image(id, caption, _metric)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 163 def image_image(id, caption, _metric) blank puts ".path.sub(%r{\A\./}, '')})" blank end
indepimage(_lines, id, caption = '', _metric = nil)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 180 def indepimage(_lines, id, caption = '', _metric = nil) blank puts ".path.sub(%r{\A\./}, '')})" blank end
inline_b(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 147 def inline_b(str) "**#{str.gsub(/\*/, '\*')}**" end
inline_br(_str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 281 def inline_br(_str) "\n" end
inline_code(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 155 def inline_code(str) "`#{str}`" end
inline_comment(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 305 def inline_comment(str) if @book.config['draft'] %Q(<span class="red">#{escape_html(str)}</span>) else '' end end
inline_em(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 143 def inline_em(str) "*#{str.gsub(/\*/, '\*')}*" end
inline_fn(id)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 277 def inline_fn(id) "[^#{id}]" end
inline_i(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 139 def inline_i(str) "*#{str.gsub(/\*/, '\*')}*" end
inline_img(id)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 173 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
# File ../../../../../lib/review/markdownbuilder.rb, line 151 def inline_strong(str) "**#{str.gsub(/\*/, '\*')}**" end
inline_tt(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 159 def inline_tt(str) "`#{str}`" end
list_body(_id, lines, _lang)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 63 def list_body(_id, lines, _lang) lines.each do |line| puts detab(line) end puts '```' end
list_header(id, caption, lang)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 53 def list_header(id, caption, lang) if get_chap.nil? print %Q(リスト#{@chapter.list(id).number} #{compile_inline(caption)}\n\n) else print %Q(リスト#{get_chap}.#{@chapter.list(id).number} #{compile_inline(caption)}\n\n) end lang ||= '' puts "```#{lang}" end
nofunc_text(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 285 def nofunc_text(str) str end
ol_begin()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 87 def ol_begin blank end
ol_end()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 95 def ol_end blank end
ol_item(lines, num)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 91 def ol_item(lines, num) puts "#{num}. #{lines.join}" end
pagebreak()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 186 def pagebreak puts '{pagebreak}' end
paragraph(lines)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 48 def paragraph(lines) puts lines.join puts "\n" end
puts(str)
click to toggle source
Calls superclass method
# File ../../../../../lib/review/markdownbuilder.rb, line 25 def puts(str) @blank_seen = false super end
quote(lines)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 42 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
# File ../../../../../lib/review/markdownbuilder.rb, line 200 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) 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
# File ../../../../../lib/review/markdownbuilder.rb, line 249 def table_begin(ncols) end
table_border(ncols)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 256 def table_border(ncols) puts((0..ncols).map { '|' }.join(':--')) end
table_end()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 268 def table_end blank end
table_header(id, caption)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 238 def table_header(id, caption) if id.nil? puts compile_inline(caption) elsif get_chap puts %Q(#{I18n.t('table')}#{I18n.t('format_number_header', [get_chap, @chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}) else puts %Q(#{I18n.t('table')}#{I18n.t('format_number_header_without_chapter', [@chapter.table(id).number])}#{I18n.t('caption_prefix')}#{compile_inline(caption)}) end blank end
td(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 264 def td(str) str end
th(str)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 260 def th(str) str end
tr(rows)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 252 def tr(rows) puts "|#{rows.join('|')}|" end
ul_begin()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 70 def ul_begin blank if @ul_indent == 0 @ul_indent += 1 end
ul_end()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 82 def ul_end @ul_indent -= 1 blank if @ul_indent == 0 end
ul_item_begin(lines)
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 75 def ul_item_begin(lines) puts ' ' * (@ul_indent - 1) + '* ' + lines.join end
ul_item_end()
click to toggle source
# File ../../../../../lib/review/markdownbuilder.rb, line 79 def ul_item_end end